blob: 417a3e1b0e2d652db09d80315f57892eb896d47f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2013 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0, which accompanies this distribution
* and is available at https://www.eclipse.org/legal/epl-2.0/.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.core.tests.internal.resource.java;
import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceModel;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.jpa.core.resource.java.EntityAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.java.MappedSuperclassAnnotation;
@SuppressWarnings("nls")
public class MappedSuperclassTests extends JpaJavaResourceModelTestCase {
public MappedSuperclassTests(String name) {
super(name);
}
private ICompilationUnit createTestMappedSuperclass() throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
return IteratorTools.iterator(JPA.MAPPED_SUPERCLASS);
}
@Override
public void appendTypeAnnotationTo(StringBuilder sb) {
sb.append("@MappedSuperclass");
}
});
}
private ICompilationUnit createTestMappedSuperclassAndEntity() throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
return IteratorTools.iterator(JPA.MAPPED_SUPERCLASS, JPA.ENTITY);
}
@Override
public void appendTypeAnnotationTo(StringBuilder sb) {
sb.append("@MappedSuperclass");
sb.append("@Entity");
}
});
}
public void testMappedSuperclass() throws Exception {
ICompilationUnit cu = this.createTestMappedSuperclass();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceModel mappingAnnotation = resourceType.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME);
assertTrue(mappingAnnotation instanceof MappedSuperclassAnnotation);
}
public void testMappedSuperclassAndEntity() throws Exception {
ICompilationUnit cu = this.createTestMappedSuperclassAndEntity();
JavaResourceType resourceType = buildJavaResourceType(cu);
JavaResourceModel mappingAnnotation = resourceType.getAnnotation(EntityAnnotation.ANNOTATION_NAME);
assertTrue(mappingAnnotation instanceof EntityAnnotation);
MappedSuperclassAnnotation mappedSuperclass = (MappedSuperclassAnnotation) resourceType.getAnnotation(JPA.MAPPED_SUPERCLASS);
assertNotNull(mappedSuperclass);
}
}