blob: b8f687588e7c7d2d07ebdbee6c90c60b69c701fa [file] [log] [blame]
/*******************************************************************************
* 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.context.java;
import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.Member;
import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jaxb.core.MappingKeys;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping;
import org.eclipse.jpt.jaxb.core.context.XmlElement;
import org.eclipse.jpt.jaxb.core.context.XmlElementMapping;
import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
@SuppressWarnings("nls")
public class GenericJavaXmlElementMappingTests extends JaxbContextModelTestCase
{
public GenericJavaXmlElementMappingTests(String name) {
super(name);
}
private ICompilationUnit createTypeWithXmlElement() throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ELEMENT);
}
@Override
public void appendTypeAnnotationTo(StringBuilder sb) {
sb.append("@XmlType");
}
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlElement");
}
});
}
private void createXmlTypeWithVariousAttributes() throws CoreException {
SourceWriter sourceWriter = new SourceWriter() {
public void appendSourceTo(StringBuilder sb) {
sb.append(CR);
sb.append("import ").append(JAXB.XML_TYPE).append(";").append(CR);
sb.append("import java.util.List;").append(CR);
sb.append(CR);
sb.append("@XmlType").append(CR);
sb.append("public class ").append(TYPE_NAME).append("{").append(CR);
sb.append(" public String string;").append(CR);
sb.append(" public List<String> stringList;").append(CR);
sb.append(" public String[] stringArray;").append(CR);
sb.append("}").append(CR);
}
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, TYPE_NAME + ".java", sourceWriter);
}
public void testModifyName() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSchemaElementRef().getSpecifiedName());
assertEquals("id", xmlElement.getSchemaElementRef().getDefaultName());
assertEquals("id", xmlElement.getSchemaElementRef().getName());
xmlElement.getSchemaElementRef().setSpecifiedName("foo");
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertEquals("foo", xmlElementAnnotation.getName());
assertEquals("foo", xmlElement.getSchemaElementRef().getSpecifiedName());
assertEquals("id", xmlElement.getSchemaElementRef().getDefaultName());
assertEquals("foo", xmlElement.getSchemaElementRef().getName());
xmlElement.getSchemaElementRef().setSpecifiedName(null);
xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertNull(xmlElementAnnotation.getName());
assertNull(xmlElement.getSchemaElementRef().getSpecifiedName());
}
public void testUpdateName() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSchemaElementRef().getSpecifiedName());
//add a Name member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__NAME, "foo");
}
});
assertEquals("foo", xmlElement.getSchemaElementRef().getName());
//remove the Name member value pair
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration);
GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0);
}
});
assertNull(xmlElement.getSchemaElementRef().getSpecifiedName());
}
public void testModifyNamespace() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace());
xmlElement.getSchemaElementRef().setSpecifiedNamespace("foo");
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertEquals("foo", xmlElementAnnotation.getNamespace());
assertEquals("foo", xmlElement.getSchemaElementRef().getNamespace());
xmlElement.getSchemaElementRef().setSpecifiedNamespace(null);
xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertNull(xmlElementAnnotation.getNamespace());
assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace());
}
public void testUpdateNamespace() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace());
//add a namespace member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__NAMESPACE, "foo");
}
});
assertEquals("foo", xmlElement.getSchemaElementRef().getNamespace());
//remove the namespace member value pair
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration);
GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0);
}
});
assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace());
}
public void testModifyRequired() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSpecifiedRequired());
assertEquals(false, xmlElement.isDefaultRequired());
assertEquals(false, xmlElement.isRequired());
xmlElement.setSpecifiedRequired(Boolean.TRUE);
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertEquals(Boolean.TRUE, xmlElementAnnotation.getRequired());
assertEquals(Boolean.TRUE, xmlElement.getSpecifiedRequired());
assertEquals(false, xmlElement.isDefaultRequired());
assertEquals(true, xmlElement.isRequired());
xmlElement.setSpecifiedRequired(null);
xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertNull(xmlElementAnnotation.getName());
assertNull(xmlElement.getSpecifiedRequired());
assertEquals(false, xmlElement.isDefaultRequired());
assertEquals(false, xmlElement.isRequired());
}
public void testUpdateRequired() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSpecifiedRequired());
assertEquals(false, xmlElement.isDefaultRequired());
assertEquals(false, xmlElement.isRequired());
//add a required member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__REQUIRED, true);
}
});
assertEquals(Boolean.TRUE, xmlElement.getSpecifiedRequired());
assertEquals(false, xmlElement.isDefaultRequired());
assertEquals(true, xmlElement.isRequired());
//remove the required member value pair
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration);
GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0);
}
});
assertNull(xmlElement.getSpecifiedRequired());
assertEquals(false, xmlElement.isDefaultRequired());
assertEquals(false, xmlElement.isRequired());
}
public void testModifyNillable() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSpecifiedNillable());
assertEquals(false, xmlElement.isDefaultNillable());
assertEquals(false, xmlElement.isNillable());
xmlElement.setSpecifiedNillable(Boolean.TRUE);
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertEquals(Boolean.TRUE, xmlElementAnnotation.getNillable());
assertEquals(Boolean.TRUE, xmlElement.getSpecifiedNillable());
assertEquals(false, xmlElement.isDefaultNillable());
assertEquals(true, xmlElement.isNillable());
xmlElement.setSpecifiedNillable(null);
xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertNull(xmlElementAnnotation.getName());
assertNull(xmlElement.getSpecifiedNillable());
assertEquals(false, xmlElement.isDefaultNillable());
assertEquals(false, xmlElement.isNillable());
}
public void testUpdateNillable() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSpecifiedNillable());
assertEquals(false, xmlElement.isDefaultNillable());
assertEquals(false, xmlElement.isNillable());
//add a nillable member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__NILLABLE, true);
}
});
assertEquals(Boolean.TRUE, xmlElement.getSpecifiedNillable());
assertEquals(false, xmlElement.isDefaultNillable());
assertEquals(true, xmlElement.isNillable());
//remove the nillable member value pair
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration);
GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0);
}
});
assertNull(xmlElement.getSpecifiedNillable());
assertEquals(false, xmlElement.isDefaultNillable());
assertEquals(false, xmlElement.isNillable());
}
public void testDefaultNillable() throws Exception {
createXmlTypeWithVariousAttributes();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
// string
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = persistentAttribute.getJavaResourceAttribute();
assertEquals(false, xmlElement.isDefaultNillable());
annotatedElement(resourceAttribute).edit(
new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT);
}
});
assertEquals(false, xmlElement.isDefaultNillable());
// string list
persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 1);
xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
xmlElement = xmlElementMapping.getXmlElement();
resourceAttribute = persistentAttribute.getJavaResourceAttribute();
assertEquals(true, xmlElement.isDefaultNillable());
annotatedElement(resourceAttribute).edit(
new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT);
}
});
assertEquals(false, xmlElement.isDefaultNillable());
// string array
persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 2);
xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
xmlElement = xmlElementMapping.getXmlElement();
resourceAttribute = persistentAttribute.getJavaResourceAttribute();
assertEquals(true, xmlElement.isDefaultNillable());
annotatedElement(resourceAttribute).edit(
new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT);
}
});
assertEquals(false, xmlElement.isDefaultNillable());
}
public void testModifyDefaultValue() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getDefaultValue());
xmlElement.setDefaultValue("foo");
XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertEquals("foo", xmlElementAnnotation.getDefaultValue());
assertEquals("foo", xmlElement.getDefaultValue());
xmlElement.setDefaultValue(null);
xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME);
assertNull(xmlElementAnnotation.getDefaultValue());
assertNull(xmlElement.getDefaultValue());
}
public void testUpdateDefaultValue() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getDefaultValue());
//add a DefaultValue member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__DEFAULT_VALUE, "foo");
}
});
assertEquals("foo", xmlElement.getDefaultValue());
//remove the DefaultValue member value pair
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration);
GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0);
}
});
assertNull(xmlElement.getDefaultValue());
}
public void testModifyType() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
assertNull(xmlElement.getSpecifiedType());
assertEquals("int", xmlElement.getType());
assertEquals("int", xmlElement.getDefaultType());
xmlElement.setSpecifiedType("Foo");
assertEquals("Foo", xmlElement.getSpecifiedType());
assertEquals("Foo", xmlElement.getType());
xmlElement.setSpecifiedType(null);
assertNull(xmlElement.getSpecifiedType());
assertEquals("int", xmlElement.getType());
}
public void testUpdateType() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping();
XmlElement xmlElement = xmlElementMapping.getXmlElement();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNull(xmlElement.getSpecifiedType());
assertEquals("int", xmlElement.getDefaultType());
assertEquals("int", xmlElement.getType());
//add a Type member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addXmlElementTypeMemberValuePair(declaration, JAXB.XML_ELEMENT__TYPE, "Foo");
}
});
assertEquals("Foo", xmlElement.getSpecifiedType());
assertEquals("Foo", xmlElement.getType());
//remove the Type member value pair
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration);
GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0);
}
});
assertNull(xmlElement.getSpecifiedType());
assertEquals("int", xmlElement.getType());
}
public void testChangeMappingType() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
assertNotNull(xmlElementMapping);
assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME));
persistentAttribute.setMappingKey(MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY);
XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping();
assertNotNull(xmlAttributeMapping);
assertNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME));
assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME));
persistentAttribute.setMappingKey(MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY);
xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
assertNotNull(xmlElementMapping);
assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME));
assertNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME));
}
public void testModifyXmlJavaTypeAdapter() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlJavaTypeAdapter());
assertNull(xmlJavaTypeAdapterAnnotation);
xmlElementMapping.addXmlJavaTypeAdapter();
xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlJavaTypeAdapter());
assertNotNull(xmlJavaTypeAdapterAnnotation);
xmlElementMapping.removeXmlJavaTypeAdapter();
xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlJavaTypeAdapter());
assertNull(xmlJavaTypeAdapterAnnotation);
}
public void testUpdateXmlJavaTypeAdapter() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlJavaTypeAdapter());
assertNull(xmlJavaTypeAdapterAnnotation);
//add an XmlJavaTypeAdapter annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
}
});
xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlJavaTypeAdapter());
assertNotNull(xmlJavaTypeAdapterAnnotation);
//remove the XmlJavaTypeAdapter annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
}
});
xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlJavaTypeAdapter());
assertNull(xmlJavaTypeAdapterAnnotation);
}
public void testModifyXmlSchemaType() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlSchemaType());
assertNull(xmlSchemaTypeAnnotation);
xmlElementMapping.addXmlSchemaType();
xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlSchemaType());
assertNotNull(xmlSchemaTypeAnnotation);
xmlElementMapping.removeXmlSchemaType();
xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
}
public void testUpdateXmlSchemaType() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlSchemaType());
assertNull(xmlSchemaTypeAnnotation);
//add an XmlSchemaType annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlSchemaTypeAnnotation.ANNOTATION_NAME);
}
});
xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlSchemaType());
assertNotNull(xmlSchemaTypeAnnotation);
//remove the XmlSchemaType annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
}
});
xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlSchemaType());
assertNull(xmlSchemaTypeAnnotation);
}
protected void addXmlElementMemberValuePair(ModifiedDeclaration declaration, String name, String value) {
this.addMemberValuePair((MarkerAnnotation) this.getXmlElementAnnotation(declaration), name, value);
}
protected void addXmlElementMemberValuePair(ModifiedDeclaration declaration, String name, boolean value) {
this.addMemberValuePair((MarkerAnnotation) this.getXmlElementAnnotation(declaration), name, value);
}
protected void addXmlElementTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) {
this.addMemberValuePair(
(MarkerAnnotation) this.getXmlElementAnnotation(declaration),
name,
this.newTypeLiteral(declaration.getAst(), typeName));
}
protected Annotation getXmlElementAnnotation(ModifiedDeclaration declaration) {
return declaration.getAnnotationNamed(XmlElementAnnotation.ANNOTATION_NAME);
}
public void testModifyXmlElementWrapper() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlElementWrapper());
assertNull(xmlElementWrapperAnnotation);
xmlElementMapping.addXmlElementWrapper();
xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlElementWrapper());
assertNotNull(xmlElementWrapperAnnotation);
xmlElementMapping.removeXmlElementWrapper();
xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME);
}
public void testUpdateXmlElementWrapper() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlElementWrapper());
assertNull(xmlElementWrapperAnnotation);
//add an XmlElementWrapper annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlElementWrapperAnnotation.ANNOTATION_NAME);
}
});
xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlElementWrapper());
assertNotNull(xmlElementWrapperAnnotation);
//remove the XmlElementWrapper annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlElementWrapperAnnotation.ANNOTATION_NAME);
}
});
xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlElementWrapper());
assertNull(xmlElementWrapperAnnotation);
}
public void testModifyXmlList() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlList());
assertNull(xmlListAnnotation);
xmlElementMapping.addXmlList();
xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlList());
assertNotNull(xmlListAnnotation);
xmlElementMapping.removeXmlList();
xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME);
}
public void testUpdateXmlList() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlList());
assertNull(xmlListAnnotation);
//add an XmlList annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlListAnnotation.ANNOTATION_NAME);
}
});
xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlList());
assertNotNull(xmlListAnnotation);
//remove the XmlList annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlListAnnotation.ANNOTATION_NAME);
}
});
xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlList());
assertNull(xmlListAnnotation);
}
public void testModifyXmlID() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlID());
assertNull(xmlIDAnnotation);
xmlElementMapping.addXmlID();
xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlID());
assertNotNull(xmlIDAnnotation);
xmlElementMapping.removeXmlID();
xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME);
}
public void testUpdateXmlID() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlID());
assertNull(xmlIDAnnotation);
//add an XmlID annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDAnnotation.ANNOTATION_NAME);
}
});
xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlID());
assertNotNull(xmlIDAnnotation);
//remove the XmlID annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlIDAnnotation.ANNOTATION_NAME);
}
});
xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlID());
assertNull(xmlIDAnnotation);
}
public void testModifyXmlIDREF() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlIDREF());
assertNull(xmlIDREFAnnotation);
xmlElementMapping.addXmlIDREF();
xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlIDREF());
assertNotNull(xmlIDREFAnnotation);
xmlElementMapping.removeXmlIDREF();
xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlIDREF());
assertNull(xmlIDREFAnnotation);
}
public void testUpdateXmlIDREF() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlIDREF());
assertNull(xmlIDREFAnnotation);
//add an XmlIDREF annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDREFAnnotation.ANNOTATION_NAME);
}
});
xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlIDREF());
assertNotNull(xmlIDREFAnnotation);
//remove the XmlIDREF annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlIDREFAnnotation.ANNOTATION_NAME);
}
});
xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlIDREF());
assertNull(xmlIDREFAnnotation);
}
public void testModifyXmlAttachmentRef() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlAttachmentRef());
assertNull(xmlAttachmentRefAnnotation);
xmlElementMapping.addXmlAttachmentRef();
xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlAttachmentRef());
assertNotNull(xmlAttachmentRefAnnotation);
xmlElementMapping.removeXmlAttachmentRef();
xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME);
}
public void testUpdateXmlAttachmentRef() throws Exception {
createTypeWithXmlElement();
JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0);
JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0);
XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping();
JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute();
XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlAttachmentRef());
assertNull(xmlAttachmentRefAnnotation);
//add an XmlAttachmentRef annotation
AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute);
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttachmentRefAnnotation.ANNOTATION_NAME);
}
});
xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME);
assertNotNull(xmlElementMapping.getXmlAttachmentRef());
assertNotNull(xmlAttachmentRefAnnotation);
//remove the XmlAttachmentRef annotation
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlAttachmentRefAnnotation.ANNOTATION_NAME);
}
});
xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME);
assertNull(xmlElementMapping.getXmlAttachmentRef());
assertNull(xmlAttachmentRefAnnotation);
}
}