SWS-162
This commit is contained in:
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.xml.schema.xsd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
protected final void setUp() throws Exception {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
}
|
||||
|
||||
protected abstract XsdSchema createSchemaInternal(Resource[] schemaResources) throws Exception;
|
||||
|
||||
protected XsdSchema createSchema(Resource[] schemaResources) throws Exception {
|
||||
XsdSchema schema = createSchemaInternal(schemaResources);
|
||||
if (schema instanceof InitializingBean) {
|
||||
((InitializingBean) schema).afterPropertiesSet();
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
public void testSingleDocument() throws Exception {
|
||||
XsdSchema schema =
|
||||
createSchema(new Resource[]{new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class)});
|
||||
XmlValidator validator = schema.getValidator();
|
||||
assertNotNull("No validator returned", validator);
|
||||
XsdSchemaDocument[] documents = schema.getSchemaDocuments();
|
||||
assertEquals("Invalid amount of schema documents", 1, documents.length);
|
||||
XsdSchemaDocument document = documents[0];
|
||||
assertNotNull("Document is null", document);
|
||||
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/single",
|
||||
document.getTargetNamespace());
|
||||
verifyDocument("single.xsd", document);
|
||||
XsdElement[] declarations = document.getElements();
|
||||
assertEquals("Invalid amount of element declarations", 1, declarations.length);
|
||||
XsdElement declaration = declarations[0];
|
||||
assertEquals("Invalid element declaration name",
|
||||
new QName("http://www.springframework.org/spring-ws/single", "root"), declaration.getName());
|
||||
}
|
||||
|
||||
public void testInclude() throws Exception {
|
||||
XsdSchema schema =
|
||||
createSchema(new Resource[]{new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class)});
|
||||
XmlValidator validator = schema.getValidator();
|
||||
assertNotNull("No validator returned", validator);
|
||||
XsdSchemaDocument[] documents = schema.getSchemaDocuments();
|
||||
assertEquals("Invalid amount of schema documents", 2, documents.length);
|
||||
for (int i = 0; i < documents.length; i++) {
|
||||
XsdSchemaDocument document = documents[i];
|
||||
assertNotNull("Document is null", document);
|
||||
XsdElement[] elements = document.getElements();
|
||||
if ("including.xsd".equals(document.getFilename())) {
|
||||
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include",
|
||||
document.getTargetNamespace());
|
||||
verifyDocument("including.xsd", document);
|
||||
assertEquals("Invalid amount of element declarations", 1, elements.length);
|
||||
assertEquals("Invalid element declaration name",
|
||||
new QName("http://www.springframework.org/spring-ws/include", "customElement"),
|
||||
elements[0].getName());
|
||||
}
|
||||
else if ("included.xsd".equals(document.getFilename())) {
|
||||
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include",
|
||||
document.getTargetNamespace());
|
||||
verifyDocument("included.xsd", document);
|
||||
assertEquals("Invalid amount of element declarations", 1, elements.length);
|
||||
assertEquals("Invalid element declaration name",
|
||||
new QName("http://www.springframework.org/spring-ws/include", "stringElement"),
|
||||
elements[0].getName());
|
||||
}
|
||||
else {
|
||||
fail("Invalid filename: " + document.getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testImport() throws Exception {
|
||||
XsdSchema schema =
|
||||
createSchema(new Resource[]{new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class)});
|
||||
XmlValidator validator = schema.getValidator();
|
||||
assertNotNull("No validator returned", validator);
|
||||
XsdSchemaDocument[] documents = schema.getSchemaDocuments();
|
||||
assertEquals("Invalid amount of schema documents", 2, documents.length);
|
||||
for (int i = 0; i < documents.length; i++) {
|
||||
XsdSchemaDocument document = documents[i];
|
||||
assertNotNull("Document is null", document);
|
||||
XsdElement[] elements = document.getElements();
|
||||
if ("importing.xsd".equals(document.getFilename())) {
|
||||
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing",
|
||||
document.getTargetNamespace());
|
||||
verifyDocument("importing.xsd", document);
|
||||
assertEquals("Invalid amount of element declarations", 1, elements.length);
|
||||
assertEquals("Invalid element declaration name",
|
||||
new QName("http://www.springframework.org/spring-ws/importing", "customElement"),
|
||||
elements[0].getName());
|
||||
}
|
||||
else if ("imported.xsd".equals(document.getFilename())) {
|
||||
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/imported",
|
||||
document.getTargetNamespace());
|
||||
verifyDocument("imported.xsd", document);
|
||||
assertEquals("Invalid amount of element declarations", 1, elements.length);
|
||||
assertEquals("Invalid element declaration name",
|
||||
new QName("http://www.springframework.org/spring-ws/imported", "stringElement"),
|
||||
elements[0].getName());
|
||||
}
|
||||
else {
|
||||
fail("Invalid filename: " + document.getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyDocument(String filename, XsdSchemaDocument document)
|
||||
throws IOException, SAXException, TransformerException {
|
||||
assertEquals("Invalid document filename", filename, document.getFilename());
|
||||
InputStream inputStream = AbstractXsdSchemaTestCase.class.getResourceAsStream(filename);
|
||||
try {
|
||||
Document expected = documentBuilder.parse(inputStream);
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(document.getSource(), result);
|
||||
assertXMLEqual("Invalid source returned", expected, (Document) result.getNode());
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright ${YEAR} the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.xml.schema.xsd;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
public class SimpleXsdSchemaTest extends AbstractXsdSchemaTestCase {
|
||||
|
||||
protected XsdSchema createSchemaInternal(Resource[] schemaResources) throws Exception {
|
||||
return new SimpleXsdSchema(schemaResources[0]);
|
||||
}
|
||||
|
||||
public void testInclude() throws Exception {
|
||||
}
|
||||
|
||||
public void testImport() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright ${YEAR} the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.xml.schema.xsd;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
public class WsCommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
|
||||
|
||||
protected XsdSchema createSchemaInternal(Resource[] schemaResources) throws IOException {
|
||||
return new WsCommonsXsdSchema(schemaResources);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/imported"
|
||||
xmlns="http://www.springframework.org/spring-ws/imported" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:simpleType name="customType">
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:element name="stringElement" type="xsd:string"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/importing"
|
||||
xmlns="http://www.springframework.org/spring-ws/importing" elementFormDefault="qualified"
|
||||
xmlns:imported="http://www.springframework.org/spring-ws/imported" attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/spring-ws/imported" schemaLocation="imported.xsd"/>
|
||||
|
||||
<xsd:element name="customElement" type="imported:customType"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include"
|
||||
xmlns="http://www.springframework.org/spring-ws/include" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:simpleType name="customType">
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:element name="stringElement" type="xsd:string"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include"
|
||||
xmlns="http://www.springframework.org/spring-ws/include" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:include schemaLocation="included.xsd"/>
|
||||
|
||||
<xsd:element name="customElement" type="customType"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/single"
|
||||
xmlns="http://www.springframework.org/spring-ws/single" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:element name="root">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
Reference in New Issue
Block a user