diff options
author | pfullbright | 2010-10-20 17:50:19 +0000 |
---|---|---|
committer | pfullbright | 2010-10-20 17:50:19 +0000 |
commit | 2e2becee5a06592a4530667a71bb7d971322dbc7 (patch) | |
tree | c5bc2d36884c756a1a0fc8f55729ad11c382ae8f | |
parent | b27d333956fc327a2aaf49c927ba2982b9a766ee (diff) | |
download | webtools.dali-2e2becee5a06592a4530667a71bb7d971322dbc7.tar.gz webtools.dali-2e2becee5a06592a4530667a71bb7d971322dbc7.tar.xz webtools.dali-2e2becee5a06592a4530667a71bb7d971322dbc7.zip |
XmlSchema/XmlNs annotation tests
2 files changed, 247 insertions, 0 deletions
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java index 13d3ef5f33..91ff88a3b8 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java @@ -33,6 +33,7 @@ public class JaxbJavaResourceModelTests { suite.addTestSuite(XmlMixedAnnotationTests.class); suite.addTestSuite(XmlRegistryAnnotationTests.class); suite.addTestSuite(XmlRootElementAnnotationTests.class); + suite.addTestSuite(XmlSchemaAnnotationTests.class); suite.addTestSuite(XmlSeeAlsoAnnotationTests.class); suite.addTestSuite(XmlTransientAnnotationTests.class); suite.addTestSuite(XmlTypeAnnotationTests.class); diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java new file mode 100644 index 0000000000..efd2c3d645 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java @@ -0,0 +1,246 @@ +package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jpt.core.resource.java.JavaResourcePackage; +import org.eclipse.jpt.jaxb.core.resource.java.JAXB; +import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation; +import org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm; +import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation; +import org.eclipse.jpt.utility.internal.CollectionTools; + +@SuppressWarnings("nls") +public class XmlSchemaAnnotationTests + extends JaxbJavaResourceModelTestCase { + + private static final String TEST_LOCATION = "http://www.eclipse.org/test/schema.xsd"; + + private static final String TEST_NAMESPACE = "http://www.eclipse.org/test/schema"; + + private static final String TEST_PREFIX = "ts"; + + private static final String TEST_NAMESPACE_2 = "http://www.eclipse.org/test/schema2"; + + private static final String TEST_PREFIX_2 = "ts2"; + + + public XmlSchemaAnnotationTests(String name) { + super(name); + } + + + private ICompilationUnit createPackageInfoWithSchemaAndAttributeFormDefault() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(attributeFormDefault = XmlNsForm.QUALIFIED)", + JAXB.XML_SCHEMA, JAXB.XML_NS_FORM); + } + + private ICompilationUnit createPackageInfoWithSchemaAndElementFormDefault() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED)", + JAXB.XML_SCHEMA, JAXB.XML_NS_FORM); + } + + private ICompilationUnit createPackageInfoWithSchemaAndLocation() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(location = \"" + TEST_LOCATION + "\")", + JAXB.XML_SCHEMA); + } + + private ICompilationUnit createPackageInfoWithSchemaAndNamespace() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(namespace = \"" + TEST_NAMESPACE + "\")", + JAXB.XML_SCHEMA); + } + + private ICompilationUnit createPackageInfoWithSchemaAndXmlns() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(xmlns = @XmlNs)", + JAXB.XML_SCHEMA, JAXB.XML_NS); + } + + private ICompilationUnit createPackageInfoWithSchemaAndXmlnsWithNamespace() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE + "\"))", + JAXB.XML_SCHEMA, JAXB.XML_NS); + } + + private ICompilationUnit createPackageInfoWithSchemaAndXmlnsWithPrefix() throws CoreException { + return createTestPackageInfo( + "@XmlSchema(xmlns = @XmlNs(prefix = \"" + TEST_PREFIX + "\"))", + JAXB.XML_SCHEMA, JAXB.XML_NS); + } + + public void testAttributeFormDefault() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndAttributeFormDefault(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + assertTrue(schemaAnnotation != null); + assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getAttributeFormDefault()); + assertSourceContains("@XmlSchema(attributeFormDefault = XmlNsForm.QUALIFIED)", cu); + + schemaAnnotation.setAttributeFormDefault(XmlNsForm.UNQUALIFIED); + assertEquals(XmlNsForm.UNQUALIFIED, schemaAnnotation.getAttributeFormDefault()); + assertSourceContains("@XmlSchema(attributeFormDefault = UNQUALIFIED)", cu); + + schemaAnnotation.setAttributeFormDefault(XmlNsForm.UNSET); + assertEquals(XmlNsForm.UNSET, schemaAnnotation.getAttributeFormDefault()); + assertSourceContains("@XmlSchema(attributeFormDefault = UNSET)", cu); + + schemaAnnotation.setAttributeFormDefault(null); + assertEquals(null, schemaAnnotation.getAttributeFormDefault()); + assertSourceContains("@XmlSchema", cu); + + schemaAnnotation.setAttributeFormDefault(XmlNsForm.QUALIFIED); + assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getAttributeFormDefault()); + assertSourceContains("@XmlSchema(attributeFormDefault = QUALIFIED)", cu); + } + + public void testElementFormDefault() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndElementFormDefault(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + assertTrue(schemaAnnotation != null); + assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getElementFormDefault()); + assertSourceContains("@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED)", cu); + + schemaAnnotation.setElementFormDefault(XmlNsForm.UNQUALIFIED); + assertEquals(XmlNsForm.UNQUALIFIED, schemaAnnotation.getElementFormDefault()); + assertSourceContains("@XmlSchema(elementFormDefault = UNQUALIFIED)", cu); + + schemaAnnotation.setElementFormDefault(XmlNsForm.UNSET); + assertEquals(XmlNsForm.UNSET, schemaAnnotation.getElementFormDefault()); + assertSourceContains("@XmlSchema(elementFormDefault = UNSET)", cu); + + schemaAnnotation.setElementFormDefault(null); + assertEquals(null, schemaAnnotation.getElementFormDefault()); + assertSourceContains("@XmlSchema", cu); + + schemaAnnotation.setElementFormDefault(XmlNsForm.QUALIFIED); + assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getElementFormDefault()); + assertSourceContains("@XmlSchema(elementFormDefault = QUALIFIED)", cu); + } + + public void testLocation() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndLocation(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + assertNotNull(schemaAnnotation.getLocation()); + + schemaAnnotation.setLocation(null); + assertNull(schemaAnnotation.getNamespace()); + assertSourceContains("@XmlSchema", cu); + + schemaAnnotation.setLocation(TEST_LOCATION); + assertEquals(TEST_LOCATION, schemaAnnotation.getLocation()); + assertSourceContains("@XmlSchema(location = \"" + TEST_LOCATION + "\")", cu); + } + + public void testNamespace() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndNamespace(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + assertNotNull(schemaAnnotation.getNamespace()); + + schemaAnnotation.setNamespace(null); + assertNull(schemaAnnotation.getNamespace()); + assertSourceContains("@XmlSchema", cu); + + schemaAnnotation.setNamespace(TEST_NAMESPACE); + assertEquals(TEST_NAMESPACE, schemaAnnotation.getNamespace()); + assertSourceContains("@XmlSchema(namespace = \"" + TEST_NAMESPACE + "\")", cu); + } + + public void testXmlnsNamespace() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndXmlnsWithNamespace(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + XmlNsAnnotation xmlnsAnnotation = schemaAnnotation.xmlnsAt(0); + assertNotNull(xmlnsAnnotation.getNamespace()); + + xmlnsAnnotation.setNamespace(null); + assertNull(xmlnsAnnotation.getNamespace()); + assertSourceContains("@XmlSchema(xmlns = @XmlNs)", cu); + + xmlnsAnnotation.setNamespace(TEST_NAMESPACE_2); + assertEquals(TEST_NAMESPACE_2, xmlnsAnnotation.getNamespace()); + assertSourceContains("@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 + "\"))", cu); + } + + public void testXmlnsPrefix() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndXmlnsWithPrefix(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + XmlNsAnnotation xmlnsAnnotation = schemaAnnotation.xmlnsAt(0); + assertNotNull(xmlnsAnnotation.getPrefix()); + + xmlnsAnnotation.setPrefix(null); + assertNull(xmlnsAnnotation.getPrefix()); + assertSourceContains("@XmlSchema(xmlns = @XmlNs)", cu); + + xmlnsAnnotation.setPrefix(TEST_PREFIX_2); + assertEquals(TEST_PREFIX_2, xmlnsAnnotation.getPrefix()); + assertSourceContains("@XmlSchema(xmlns = @XmlNs(prefix = \"" + TEST_PREFIX_2 + "\"))", cu); + } + + public void testXmlns() + throws Exception { + + ICompilationUnit cu = createPackageInfoWithSchemaAndXmlns(); + JavaResourcePackage packageResource = buildJavaResourcePackage(cu); + + XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); + assertFalse(CollectionTools.isEmpty(schemaAnnotation.getXmlns())); + assertEquals(1, schemaAnnotation.getXmlnsSize()); + + schemaAnnotation.addXmlns(1); + assertEquals(2, schemaAnnotation.getXmlnsSize()); + assertSourceContains("@XmlSchema(xmlns = {@XmlNs,@XmlNs})", cu); + + XmlNsAnnotation xmlnsAnnotation1 = schemaAnnotation.xmlnsAt(0); + xmlnsAnnotation1.setNamespace(TEST_NAMESPACE); + xmlnsAnnotation1.setPrefix(TEST_PREFIX); + XmlNsAnnotation xmlnsAnnotation2 = schemaAnnotation.xmlnsAt(1); + xmlnsAnnotation2.setNamespace(TEST_NAMESPACE_2); + xmlnsAnnotation2.setPrefix(TEST_PREFIX_2); + assertSourceContains( + "@XmlSchema(xmlns = {@XmlNs(namespaceURI = \"" + TEST_NAMESPACE + + "\", prefix = \"" + TEST_PREFIX + + "\"),@XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 + + "\", prefix = \"" + TEST_PREFIX_2 + + "\")})", cu); + + schemaAnnotation.moveXmlns(0, 1); + assertSourceContains( + "@XmlSchema(xmlns = {@XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 + + "\", prefix = \"" + TEST_PREFIX_2 + + "\"),@XmlNs(namespaceURI = \"" + TEST_NAMESPACE + + "\", prefix = \"" + TEST_PREFIX + + "\")})", cu); + + schemaAnnotation.removeXmlns(1); + assertEquals(1, schemaAnnotation.getXmlnsSize()); + assertSourceContains( + "@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 + + "\", prefix = \"" + TEST_PREFIX_2 + + "\"))", cu); + } +} |