Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-05-11 15:02:04 +0000
committerpfullbright2011-05-11 15:02:04 +0000
commit7ad44dd68ee96a7d83031c1cc7677cfd35571ae2 (patch)
tree0609bb65a16aeec38461c8dfe72e6749f5033498 /jaxb/tests/org.eclipse.jpt.jaxb.core.tests
parent1d1ee9cf7c65d5206e7439aa03225d34eae579a8 (diff)
downloadwebtools.dali-7ad44dd68ee96a7d83031c1cc7677cfd35571ae2.tar.gz
webtools.dali-7ad44dd68ee96a7d83031c1cc7677cfd35571ae2.tar.xz
webtools.dali-7ad44dd68ee96a7d83031c1cc7677cfd35571ae2.zip
bug 343851 - minimal support for XmlElements, XmlElementRef, XmlElementRefs, (EclipseLink) XmlInverseReference, and (EclipseLink) XmlTransformation attribute mappings
Diffstat (limited to 'jaxb/tests/org.eclipse.jpt.jaxb.core.tests')
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java2
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java146
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java119
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java290
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementsAnnotationTests.java380
5 files changed, 816 insertions, 121 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 d76311ba11..e3864f284e 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
@@ -27,6 +27,8 @@ public class JaxbJavaResourceModelTests {
suite.addTestSuite(XmlElementAnnotationTests.class);
suite.addTestSuite(XmlElementDeclAnnotationTests.class);
suite.addTestSuite(XmlElementRefAnnotationTests.class);
+ suite.addTestSuite(XmlElementRefsAnnotationTests.class);
+ suite.addTestSuite(XmlElementsAnnotationTests.class);
suite.addTestSuite(XmlElementWrapperAnnotationTests.class);
suite.addTestSuite(XmlEnumAnnotationTests.class);
suite.addTestSuite(XmlEnumValueAnnotationTests.class);
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java
index 2706f40ea6..06e9c05d63 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java
@@ -18,97 +18,103 @@ import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation;
@SuppressWarnings("nls")
-public class XmlElementAnnotationTests extends JaxbJavaResourceModelTestCase {
-
+public class XmlElementAnnotationTests
+ extends JaxbJavaResourceModelTestCase {
+
private static final String XML_ELEMENT_NAME = "elementName";
private static final String XML_ELEMENT_NAMESPACE = "XmlElementNamespace";
private static final String XML_ELEMENT_DEFAULT_VALUE = "myDefaultValue";
private static final String XML_ELEMENT_TYPE = "String";
-
+
+
public XmlElementAnnotationTests(String name) {
super(name);
}
-
+
+
private ICompilationUnit createTestXmlElement() throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElement");
}
});
}
-
+
private ICompilationUnit createTestXmlElementWithName() throws Exception {
return this.createTestXmlElementWithStringElement("name", XML_ELEMENT_NAME);
}
-
+
private ICompilationUnit createTestXmlElementWithNamespace() throws Exception {
return this.createTestXmlElementWithStringElement("namespace", XML_ELEMENT_NAMESPACE);
}
-
+
private ICompilationUnit createTestXmlElementWithDefaultValue() throws Exception {
return this.createTestXmlElementWithStringElement("defaultValue", XML_ELEMENT_DEFAULT_VALUE);
}
-
+
private ICompilationUnit createTestXmlElementWithStringElement(final String element, final String value) throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElement(" + element + " = \"" + value + "\")");
}
});
}
-
+
private ICompilationUnit createTestXmlElementWithBooleanElement(final String booleanElement) throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElement(" + booleanElement + " = true)");
}
});
}
-
+
private ICompilationUnit createTestXmlElementWithType() throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class)");
}
});
}
-
- public void testGetName() throws Exception {
- ICompilationUnit cu = this.createTestXmlElementWithName();
- JavaResourceType resourceType = buildJavaResourceType(cu);
- JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
- assertTrue(xmlElementAnnotation != null);
- assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName());
- }
-
+
+
public void testGetNull() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertTrue(xmlElementAnnotation != null);
assertNull(xmlElementAnnotation.getName());
assertNull(xmlElementAnnotation.getNamespace());
@@ -117,166 +123,182 @@ public class XmlElementAnnotationTests extends JaxbJavaResourceModelTestCase {
assertNull(xmlElementAnnotation.getRequired());
assertNull(xmlElementAnnotation.getType());
}
-
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
+ assertTrue(xmlElementAnnotation != null);
+ assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName());
+ }
+
public void testSetName() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertNull(xmlElementAnnotation.getName());
+
xmlElementAnnotation.setName(XML_ELEMENT_NAME);
+
assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName());
-
assertSourceContains("@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", cu);
-
+
xmlElementAnnotation.setName(null);
+
assertNull(xmlElementAnnotation.getName());
-
assertSourceContains("@XmlElement", cu);
assertSourceDoesNotContain("@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", cu);
}
-
+
public void testGetNamespace() throws Exception {
ICompilationUnit cu = this.createTestXmlElementWithNamespace();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertTrue(xmlElementAnnotation != null);
assertEquals(XML_ELEMENT_NAMESPACE, xmlElementAnnotation.getNamespace());
}
-
+
public void testSetNamespace() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertNull(xmlElementAnnotation.getNamespace());
+
xmlElementAnnotation.setNamespace(XML_ELEMENT_NAMESPACE);
+
assertEquals(XML_ELEMENT_NAMESPACE, xmlElementAnnotation.getNamespace());
-
assertSourceContains("@XmlElement(namespace = \"" + XML_ELEMENT_NAMESPACE + "\")", cu);
-
+
xmlElementAnnotation.setNamespace(null);
+
assertNull(xmlElementAnnotation.getNamespace());
-
assertSourceContains("@XmlElement", cu);
assertSourceDoesNotContain("@XmlElement(namespace = \"" + XML_ELEMENT_NAMESPACE + "\")", cu);
}
-
+
public void testGetDefaultValue() throws Exception {
ICompilationUnit cu = this.createTestXmlElementWithDefaultValue();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertTrue(xmlElementAnnotation != null);
assertEquals(XML_ELEMENT_DEFAULT_VALUE, xmlElementAnnotation.getDefaultValue());
}
-
+
public void testSetDefaultValue() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertNull(xmlElementAnnotation.getDefaultValue());
+
xmlElementAnnotation.setDefaultValue(XML_ELEMENT_DEFAULT_VALUE);
+
assertEquals(XML_ELEMENT_DEFAULT_VALUE, xmlElementAnnotation.getDefaultValue());
-
assertSourceContains("@XmlElement(defaultValue = \"" + XML_ELEMENT_DEFAULT_VALUE + "\")", cu);
-
+
xmlElementAnnotation.setDefaultValue(null);
+
assertNull(xmlElementAnnotation.getDefaultValue());
-
assertSourceContains("@XmlElement", cu);
assertSourceDoesNotContain("@XmlElement(defaultValue = \"" + XML_ELEMENT_DEFAULT_VALUE + "\")", cu);
}
-
+
public void testGetNillable() throws Exception {
ICompilationUnit cu = this.createTestXmlElementWithBooleanElement("nillable");
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
-
+
assertEquals(Boolean.TRUE, xmlElementAnnotation.getNillable());
}
-
+
public void testSetNillable() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
-
+
assertNotNull(xmlElementAnnotation);
assertNull(xmlElementAnnotation.getNillable());
-
+
xmlElementAnnotation.setNillable(Boolean.FALSE);
+
assertEquals(Boolean.FALSE, xmlElementAnnotation.getNillable());
-
assertSourceContains("@XmlElement(nillable = false)", cu);
-
+
xmlElementAnnotation.setNillable(null);
+
assertSourceContains("@XmlElement", cu);
assertSourceDoesNotContain("nillable", cu);
}
-
+
public void testGetRequired() throws Exception {
ICompilationUnit cu = this.createTestXmlElementWithBooleanElement("required");
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
-
+
assertEquals(Boolean.TRUE, xmlElementAnnotation.getRequired());
}
-
+
public void testSetRequired() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
-
+
assertNotNull(xmlElementAnnotation);
assertNull(xmlElementAnnotation.getRequired());
-
+
xmlElementAnnotation.setRequired(Boolean.FALSE);
+
assertEquals(Boolean.FALSE, xmlElementAnnotation.getRequired());
-
assertSourceContains("@XmlElement(required = false)", cu);
-
+
xmlElementAnnotation.setRequired(null);
+
assertSourceContains("@XmlElement", cu);
assertSourceDoesNotContain("required", cu);
}
-
+
public void testGetType() throws Exception {
ICompilationUnit cu = this.createTestXmlElementWithType();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertTrue(xmlElementAnnotation != null);
assertEquals(XML_ELEMENT_TYPE, xmlElementAnnotation.getType());
assertEquals("java.lang." + XML_ELEMENT_TYPE, xmlElementAnnotation.getFullyQualifiedTypeName());
}
-
+
public void testSetType() throws Exception {
ICompilationUnit cu = this.createTestXmlElement();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT);
+
assertNull(xmlElementAnnotation.getType());
+
xmlElementAnnotation.setType(XML_ELEMENT_TYPE);
+
assertEquals(XML_ELEMENT_TYPE, xmlElementAnnotation.getType());
-
assertSourceContains("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class", cu);
-
+
xmlElementAnnotation.setType(null);
+
assertNull(xmlElementAnnotation.getType());
-
assertSourceContains("@XmlElement", cu);
assertSourceDoesNotContain("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class", cu);
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java
index c2908ebcd7..5700eacefe 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java
@@ -18,174 +18,175 @@ import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation;
@SuppressWarnings("nls")
-public class XmlElementRefAnnotationTests extends JaxbJavaResourceModelTestCase {
-
+public class XmlElementRefAnnotationTests
+ extends JaxbJavaResourceModelTestCase {
+
private static final String XML_ELEMENT_REF_NAME = "elementName";
private static final String XML_ELEMENT_REF_NAMESPACE = "XmlElementRefNamespace";
private static final String XML_ELEMENT_REF_TYPE = "String";
-
+
+
public XmlElementRefAnnotationTests(String name) {
super(name);
}
-
+
+
private ICompilationUnit createTestXmlElementRef() throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElementRef");
}
});
}
-
+
private ICompilationUnit createTestXmlElementRefWithName() throws Exception {
return this.createTestXmlElementRefWithStringElement("name", XML_ELEMENT_REF_NAME);
}
-
+
private ICompilationUnit createTestXmlElementRefWithNamespace() throws Exception {
return this.createTestXmlElementRefWithStringElement("namespace", XML_ELEMENT_REF_NAMESPACE);
}
-
+
private ICompilationUnit createTestXmlElementRefWithStringElement(final String element, final String value) throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElementRef(" + element + " = \"" + value + "\")");
}
});
}
-
+
private ICompilationUnit createTestXmlElementRefWithType() throws Exception {
+
return this.createTestType(new DefaultAnnotationWriter() {
+
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF);
}
+
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class)");
}
});
}
-
- public void testGetName() throws Exception {
- ICompilationUnit cu = this.createTestXmlElementRefWithName();
- JavaResourceType resourceType = buildJavaResourceType(cu);
- JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
- assertTrue(xmlElementRefAnnotation != null);
- assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName());
- }
-
+
public void testGetNull() throws Exception {
ICompilationUnit cu = this.createTestXmlElementRef();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
assertTrue(xmlElementRefAnnotation != null);
assertNull(xmlElementRefAnnotation.getName());
assertNull(xmlElementRefAnnotation.getNamespace());
assertNull(xmlElementRefAnnotation.getType());
}
-
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
+ assertTrue(xmlElementRefAnnotation != null);
+ assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName());
+ }
+
public void testSetName() throws Exception {
ICompilationUnit cu = this.createTestXmlElementRef();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
assertNull(xmlElementRefAnnotation.getName());
+
xmlElementRefAnnotation.setName(XML_ELEMENT_REF_NAME);
+
assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName());
-
assertSourceContains("@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\")", cu);
-
+
xmlElementRefAnnotation.setName(null);
+
assertNull(xmlElementRefAnnotation.getName());
-
assertSourceContains("@XmlElementRef", cu);
assertSourceDoesNotContain("@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\")", cu);
}
-
+
public void testGetNamespace() throws Exception {
ICompilationUnit cu = this.createTestXmlElementRefWithNamespace();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
assertTrue(xmlElementRefAnnotation != null);
assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace());
}
-
+
public void testSetNamespace() throws Exception {
ICompilationUnit cu = this.createTestXmlElementRef();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
assertNull(xmlElementRefAnnotation.getNamespace());
+
xmlElementRefAnnotation.setNamespace(XML_ELEMENT_REF_NAMESPACE);
+
assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace());
-
assertSourceContains("@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\")", cu);
-
+
xmlElementRefAnnotation.setNamespace(null);
+
assertNull(xmlElementRefAnnotation.getNamespace());
-
assertSourceContains("@XmlElementRef", cu);
assertSourceDoesNotContain("@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\")", cu);
}
-
+
public void testGetType() throws Exception {
ICompilationUnit cu = this.createTestXmlElementRefWithType();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
assertTrue(xmlElementRefAnnotation != null);
assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType());
assertEquals("java.lang." + XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getFullyQualifiedTypeName());
}
-
+
public void testSetType() throws Exception {
ICompilationUnit cu = this.createTestXmlElementRef();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
+ XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF);
+
assertNull(xmlElementRefAnnotation.getType());
+
xmlElementRefAnnotation.setType(XML_ELEMENT_REF_TYPE);
+
assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType());
-
assertSourceContains("@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class", cu);
-
+
xmlElementRefAnnotation.setType(null);
+
assertNull(xmlElementRefAnnotation.getType());
-
assertSourceContains("@XmlElementRef", cu);
assertSourceDoesNotContain("@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class", cu);
}
-
- public void testAddXmlElementRefAnnotation() throws Exception {
- ICompilationUnit cu = this.createTestXmlElementRefWithName();
- JavaResourceType resourceType = buildJavaResourceType(cu);
- JavaResourceField resourceAttribute = getField(resourceType, 0);
-
- XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF);
- assertTrue(xmlElementRefAnnotation != null);
- assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName());
-
- XmlElementRefAnnotation xmlElementRefAnnotation2 = (XmlElementRefAnnotation) resourceAttribute.addAnnotation(1, JAXB.XML_ELEMENT_REF);
- xmlElementRefAnnotation2.setName("Foo");
- assertSourceContains("@XmlElementRefs({ @XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\"), @XmlElementRef(name = \"Foo\") })", cu);
- }
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java
new file mode 100644
index 0000000000..cf82aae130
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefsAnnotation;
+
+
+public class XmlElementRefsAnnotationTests
+ extends JaxbJavaResourceModelTestCase {
+
+ private static final String XML_ELEMENT_REF_NAME = "elementName";
+ private static final String XML_ELEMENT_REF_NAMESPACE = "XmlElementRefNamespace";
+ private static final String XML_ELEMENT_REF_TYPE = "String";
+
+
+ public XmlElementRefsAnnotationTests(String name) {
+ super(name);
+ }
+
+
+ private ICompilationUnit createTestXmlElementRef() throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF, JAXB.XML_ELEMENT_REFS);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElementRefs(@XmlElementRef)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlElementRefWithName() throws Exception {
+ return this.createTestXmlElementRefWithStringElement("name", XML_ELEMENT_REF_NAME);
+ }
+
+ private ICompilationUnit createTestXmlElementRefWithNamespace() throws Exception {
+ return this.createTestXmlElementRefWithStringElement("namespace", XML_ELEMENT_REF_NAMESPACE);
+ }
+
+ private ICompilationUnit createTestXmlElementRefWithStringElement(final String element, final String value) throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF, JAXB.XML_ELEMENT_REFS);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElementRefs(@XmlElementRef(" + element + " = \"" + value + "\"))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlElementRefWithType() throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF, JAXB.XML_ELEMENT_REFS);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElementRefs(@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlElementRefWithAll() throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF, JAXB.XML_ELEMENT_REFS);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElementRefs(@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\", type = " + XML_ELEMENT_REF_TYPE + ".class))");
+ }
+ });
+ }
+
+
+ private XmlElementRefAnnotation getXmlElementRefAnnotation(JavaResourceAttribute resourceAttribute) {
+ XmlElementRefsAnnotation refsAnnotation
+ = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS);
+ return refsAnnotation.xmlElementRefAt(0);
+ }
+
+ private XmlElementRefAnnotation addXmlElementRefAnnotation(int index, JavaResourceAttribute resourceAttribute) {
+ XmlElementRefsAnnotation refsAnnotation
+ = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS);
+ return refsAnnotation.addXmlElementRef(index);
+ }
+
+ private void removeXmlElementRefAnnotation(int index, JavaResourceAttribute resourceAttribute) {
+ XmlElementRefsAnnotation refsAnnotation
+ = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS);
+ refsAnnotation.removeXmlElementRef(index);
+ }
+
+ public void testGetNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRef();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementRefAnnotation != null);
+ assertNull(xmlElementRefAnnotation.getName());
+ assertNull(xmlElementRefAnnotation.getNamespace());
+ assertNull(xmlElementRefAnnotation.getType());
+ }
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementRefAnnotation != null);
+ assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRef();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertNull(xmlElementRefAnnotation.getName());
+
+ xmlElementRefAnnotation.setName(XML_ELEMENT_REF_NAME);
+ assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName());
+
+ assertSourceContains("@XmlElementRefs(@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\"))", cu);
+
+ xmlElementRefAnnotation.setName(null);
+ assertNull(xmlElementRefAnnotation.getName());
+
+ assertSourceContains("@XmlElementRefs(@XmlElementRef)", cu);
+ }
+
+ public void testGetNamespace() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithNamespace();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementRefAnnotation != null);
+ assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace());
+ }
+
+ public void testSetNamespace() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRef();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertNull(xmlElementRefAnnotation.getNamespace());
+
+ xmlElementRefAnnotation.setNamespace(XML_ELEMENT_REF_NAMESPACE);
+
+ assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace());
+ assertSourceContains("@XmlElementRefs(@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\"))", cu);
+
+ xmlElementRefAnnotation.setNamespace(null);
+
+ assertNull(xmlElementRefAnnotation.getNamespace());
+ assertSourceContains("@XmlElementRefs(@XmlElementRef)", cu);
+ }
+
+ public void testGetType() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithType();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementRefAnnotation != null);
+ assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType());
+ assertEquals("java.lang." + XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getFullyQualifiedTypeName());
+ }
+
+ public void testSetType() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRef();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute);
+
+ assertNull(xmlElementRefAnnotation.getType());
+
+ xmlElementRefAnnotation.setType(XML_ELEMENT_REF_TYPE);
+
+ assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType());
+ assertSourceContains("@XmlElementRefs(@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class))", cu);
+
+ xmlElementRefAnnotation.setType(null);
+
+ assertNull(xmlElementRefAnnotation.getType());
+ assertSourceContains("@XmlElementRefs(@XmlElementRef)", cu);
+ }
+
+ public void testAddXmlElementRef() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithAll();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ addXmlElementRefAnnotation(1, resourceAttribute);
+ XmlElementRefsAnnotation refsAnnotation = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS);
+
+ assertSourceContains(
+ "@XmlElementRefs({@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME
+ + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE
+ + "\", type = " + XML_ELEMENT_REF_TYPE
+ + ".class),@XmlElementRef})", cu);
+ assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF));
+ assertNotNull(refsAnnotation);
+ assertEquals(2, refsAnnotation.getXmlElementRefsSize());
+ }
+
+ public void testAddXmlElementRefToBeginningOfList() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithAll();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ addXmlElementRefAnnotation(1, resourceAttribute);
+ XmlElementRefsAnnotation refsAnnotation = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS);
+
+ assertSourceContains(
+ "@XmlElementRefs({@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME
+ + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE
+ + "\", type = " + XML_ELEMENT_REF_TYPE
+ + ".class),@XmlElementRef})", cu);
+
+ addXmlElementRefAnnotation(0, resourceAttribute);
+
+ assertSourceContains(
+ "@XmlElementRefs({@XmlElementRef,@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME
+ + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE
+ + "\", type = " + XML_ELEMENT_REF_TYPE
+ + ".class), @XmlElementRef})", cu);
+
+ assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF));
+ assertNotNull(refsAnnotation);
+ assertEquals(3, refsAnnotation.getXmlElementRefsSize());
+ }
+
+ public void testRemoveXmlElementRef() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementRefWithAll();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ addXmlElementRefAnnotation(1, resourceAttribute);
+
+ assertSourceContains(
+ "@XmlElementRefs({@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME
+ + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE
+ + "\", type = " + XML_ELEMENT_REF_TYPE
+ + ".class),@XmlElementRef})", cu);
+
+ removeXmlElementRefAnnotation(1, resourceAttribute);
+
+ assertSourceContains(
+ "@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME
+ + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE
+ + "\", type = " + XML_ELEMENT_REF_TYPE
+ + ".class)", cu);
+ }
+} \ No newline at end of file
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementsAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementsAnnotationTests.java
new file mode 100644
index 0000000000..b085a2b3be
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementsAnnotationTests.java
@@ -0,0 +1,380 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlElementsAnnotation;
+
+
+public class XmlElementsAnnotationTests
+ extends JaxbJavaResourceModelTestCase {
+
+ private static final String XML_ELEMENT_NAME = "elementName";
+ private static final String XML_ELEMENT_NAMESPACE = "XmlElementNamespace";
+ private static final String XML_ELEMENT_DEFAULT_VALUE = "myDefaultValue";
+ private static final String XML_ELEMENT_TYPE = "String";
+
+
+ public XmlElementsAnnotationTests(String name) {
+ super(name);
+ }
+
+
+ private ICompilationUnit createTestXmlElement() throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENTS, JAXB.XML_ELEMENT);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElements(@XmlElement)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlElementWithName() throws Exception {
+ return this.createTestXmlElementWithStringElement("name", XML_ELEMENT_NAME);
+ }
+
+ private ICompilationUnit createTestXmlElementWithNamespace() throws Exception {
+ return this.createTestXmlElementWithStringElement("namespace", XML_ELEMENT_NAMESPACE);
+ }
+
+ private ICompilationUnit createTestXmlElementWithDefaultValue() throws Exception {
+ return this.createTestXmlElementWithStringElement("defaultValue", XML_ELEMENT_DEFAULT_VALUE);
+ }
+
+ private ICompilationUnit createTestXmlElementWithStringElement(final String element, final String value) throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENTS, JAXB.XML_ELEMENT);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElements(@XmlElement(" + element + " = \"" + value + "\"))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlElementWithBooleanElement(final String booleanElement) throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENTS, JAXB.XML_ELEMENT);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElements(@XmlElement(" + booleanElement + " = true))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlElementWithType() throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ELEMENTS, JAXB.XML_ELEMENT);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElements(@XmlElement(type = " + XML_ELEMENT_TYPE + ".class))");
+ }
+ });
+ }
+
+
+ private XmlElementAnnotation getXmlElementAnnotation(JavaResourceAttribute resourceAttribute) {
+ XmlElementsAnnotation annotation
+ = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS);
+ return annotation.xmlElementAt(0);
+ }
+
+ private XmlElementAnnotation addXmlElementAnnotation(int index, JavaResourceAttribute resourceAttribute) {
+ XmlElementsAnnotation annotation
+ = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS);
+ return annotation.addXmlElement(index);
+ }
+
+ private void removeXmlElementAnnotation(int index, JavaResourceAttribute resourceAttribute) {
+ XmlElementsAnnotation annotation
+ = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS);
+ annotation.removeXmlElement(index);
+ }
+
+
+ public void testGetNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementAnnotation != null);
+ assertNull(xmlElementAnnotation.getName());
+ assertNull(xmlElementAnnotation.getNamespace());
+ assertNull(xmlElementAnnotation.getDefaultValue());
+ assertNull(xmlElementAnnotation.getNillable());
+ assertNull(xmlElementAnnotation.getRequired());
+ assertNull(xmlElementAnnotation.getType());
+ }
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementAnnotation != null);
+ assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertNull(xmlElementAnnotation.getName());
+
+ xmlElementAnnotation.setName(XML_ELEMENT_NAME);
+
+ assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName());
+ assertSourceContains("@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", cu);
+
+ xmlElementAnnotation.setName(null);
+
+ assertNull(xmlElementAnnotation.getName());
+ assertSourceContains("@XmlElement", cu);
+ assertSourceDoesNotContain("@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", cu);
+ }
+
+ public void testGetNamespace() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithNamespace();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementAnnotation != null);
+ assertEquals(XML_ELEMENT_NAMESPACE, xmlElementAnnotation.getNamespace());
+ }
+
+ public void testSetNamespace() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertNull(xmlElementAnnotation.getNamespace());
+
+ xmlElementAnnotation.setNamespace(XML_ELEMENT_NAMESPACE);
+
+ assertEquals(XML_ELEMENT_NAMESPACE, xmlElementAnnotation.getNamespace());
+ assertSourceContains("@XmlElement(namespace = \"" + XML_ELEMENT_NAMESPACE + "\")", cu);
+
+ xmlElementAnnotation.setNamespace(null);
+
+ assertNull(xmlElementAnnotation.getNamespace());
+ assertSourceContains("@XmlElement", cu);
+ assertSourceDoesNotContain("@XmlElement(namespace = \"" + XML_ELEMENT_NAMESPACE + "\")", cu);
+ }
+
+ public void testGetDefaultValue() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithDefaultValue();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementAnnotation != null);
+ assertEquals(XML_ELEMENT_DEFAULT_VALUE, xmlElementAnnotation.getDefaultValue());
+ }
+
+ public void testSetDefaultValue() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertNull(xmlElementAnnotation.getDefaultValue());
+
+ xmlElementAnnotation.setDefaultValue(XML_ELEMENT_DEFAULT_VALUE);
+
+ assertEquals(XML_ELEMENT_DEFAULT_VALUE, xmlElementAnnotation.getDefaultValue());
+ assertSourceContains("@XmlElement(defaultValue = \"" + XML_ELEMENT_DEFAULT_VALUE + "\")", cu);
+
+ xmlElementAnnotation.setDefaultValue(null);
+
+ assertNull(xmlElementAnnotation.getDefaultValue());
+ assertSourceContains("@XmlElement", cu);
+ assertSourceDoesNotContain("@XmlElement(defaultValue = \"" + XML_ELEMENT_DEFAULT_VALUE + "\")", cu);
+ }
+
+ public void testGetNillable() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithBooleanElement("nillable");
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertEquals(Boolean.TRUE, xmlElementAnnotation.getNillable());
+ }
+
+ public void testSetNillable() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertNotNull(xmlElementAnnotation);
+ assertNull(xmlElementAnnotation.getNillable());
+
+ xmlElementAnnotation.setNillable(Boolean.FALSE);
+
+ assertEquals(Boolean.FALSE, xmlElementAnnotation.getNillable());
+ assertSourceContains("@XmlElement(nillable = false)", cu);
+
+ xmlElementAnnotation.setNillable(null);
+
+ assertSourceContains("@XmlElement", cu);
+ assertSourceDoesNotContain("nillable", cu);
+ }
+
+ public void testGetRequired() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithBooleanElement("required");
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertEquals(Boolean.TRUE, xmlElementAnnotation.getRequired());
+ }
+
+ public void testSetRequired() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertNotNull(xmlElementAnnotation);
+ assertNull(xmlElementAnnotation.getRequired());
+
+ xmlElementAnnotation.setRequired(Boolean.FALSE);
+
+ assertEquals(Boolean.FALSE, xmlElementAnnotation.getRequired());
+ assertSourceContains("@XmlElement(required = false)", cu);
+
+ xmlElementAnnotation.setRequired(null);
+
+ assertSourceContains("@XmlElement", cu);
+ assertSourceDoesNotContain("required", cu);
+ }
+
+ public void testGetType() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElementWithType();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertTrue(xmlElementAnnotation != null);
+ assertEquals(XML_ELEMENT_TYPE, xmlElementAnnotation.getType());
+ assertEquals("java.lang." + XML_ELEMENT_TYPE, xmlElementAnnotation.getFullyQualifiedTypeName());
+ }
+
+ public void testSetType() throws Exception {
+ ICompilationUnit cu = this.createTestXmlElement();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute);
+
+ assertNull(xmlElementAnnotation.getType());
+
+ xmlElementAnnotation.setType(XML_ELEMENT_TYPE);
+
+ assertEquals(XML_ELEMENT_TYPE, xmlElementAnnotation.getType());
+ assertSourceContains("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class", cu);
+
+ xmlElementAnnotation.setType(null);
+
+ assertNull(xmlElementAnnotation.getType());
+ assertSourceContains("@XmlElement", cu);
+ assertSourceDoesNotContain("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class", cu);
+ }
+
+ public void testAddXmlElement() throws Exception {
+ ICompilationUnit cu = createTestXmlElementWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ addXmlElementAnnotation(1, resourceAttribute);
+ XmlElementsAnnotation annotation = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS);
+
+ assertSourceContains(
+ "@XmlElements({@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"),@XmlElement})",
+ cu);
+ assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT));
+ assertNotNull(annotation);
+ assertEquals(2, annotation.getXmlElementsSize());
+ }
+
+ public void testAddXmlElementToBeginningOfList() throws Exception {
+ ICompilationUnit cu = createTestXmlElementWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ addXmlElementAnnotation(1, resourceAttribute);
+ XmlElementsAnnotation annotation = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS);
+
+ assertSourceContains(
+ "@XmlElements({@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"),@XmlElement})",
+ cu);
+
+ addXmlElementAnnotation(0, resourceAttribute);
+
+ assertSourceContains(
+ "@XmlElements({@XmlElement,@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"), @XmlElement})",
+ cu);
+
+ assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT));
+ assertNotNull(annotation);
+ assertEquals(3, annotation.getXmlElementsSize());
+ }
+
+ public void testRemoveXmlElement() throws Exception {
+ ICompilationUnit cu = createTestXmlElementWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceAttribute = getField(resourceType, 0);
+ addXmlElementAnnotation(1, resourceAttribute);
+
+ assertSourceContains(
+ "@XmlElements({@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"),@XmlElement})",
+ cu);
+
+ removeXmlElementAnnotation(1, resourceAttribute);
+
+ assertSourceContains(
+ "@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")",
+ cu);
+ }
+} \ No newline at end of file

Back to the top