blob: bbd0a16f4d1652bee13f5469e51bcac1577fd2f5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 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.eclipselink.core.tests.internal.resource.java;
import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_2.ELJaxb_2_2_PlatformDefinition;
import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb;
import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlKeyAnnotation;
public class XmlKeyAnnotationTests
extends ELJaxbJavaResourceModelTestCase {
public XmlKeyAnnotationTests(String name) {
super(name);
}
@Override
protected AnnotationDefinition[] annotationDefinitions() {
return ELJaxb_2_2_PlatformDefinition.instance().getAnnotationDefinitions();
}
@Override
protected NestableAnnotationDefinition[] nestableAnnotationDefinitions() {
return ELJaxb_2_2_PlatformDefinition.instance().getNestableAnnotationDefinitions();
}
private ICompilationUnit createTestXmlKey()
throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
return new ArrayIterator<String>(ELJaxb.XML_KEY);
}
@Override
public void appendIdFieldAnnotationTo(StringBuilder sb) {
sb.append("@XmlKey");
}
});
}
private XmlKeyAnnotation getXmlKeyAnnotation(JavaResourceAttribute resourceAttribute) {
return (XmlKeyAnnotation) resourceAttribute.getAnnotation(ELJaxb.XML_KEY);
}
public void testGetNull() throws Exception {
ICompilationUnit cu = createTestXmlKey();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceField resourceAttribute = getField(resourceType, 0);
XmlKeyAnnotation annotation = getXmlKeyAnnotation(resourceAttribute);
assertTrue(annotation != null);
}
}