-
Notifications
You must be signed in to change notification settings - Fork 14
/
EntityFieldSeekerTest.java
60 lines (50 loc) · 2.54 KB
/
EntityFieldSeekerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cz.cvut.kbss.jopa.model.metamodel;
import cz.cvut.kbss.jopa.environment.OWLClassM;
import cz.cvut.kbss.jopa.environment.OWLClassQ;
import cz.cvut.kbss.jopa.model.annotations.Id;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import org.junit.Test;
import java.lang.reflect.Field;
import java.net.URI;
import java.util.Collection;
import static org.junit.Assert.*;
@SuppressWarnings("unused")
public class EntityFieldSeekerTest {
private EntityFieldSeeker fieldSeeker = new EntityFieldSeeker();
@Test
public void discoverFieldsInEntityClassWithoutParentsFindsAllDeclaredFields() throws Exception {
final Collection<Field> result = fieldSeeker.discoverFields(OWLClassM.class);
assertTrue(result.size() >= 7); // Can't use equals, because the AspectJ joint points are also returned
assertTrue(result.contains(OWLClassM.getUriField()));
assertTrue(result.contains(OWLClassM.getBooleanAttributeField()));
assertTrue(result.contains(OWLClassM.getDateAttributeField()));
assertTrue(result.contains(OWLClassM.getDoubleAttributeField()));
assertTrue(result.contains(OWLClassM.getEnumAttributeField()));
assertTrue(result.contains(OWLClassM.getIntAttributeField()));
assertTrue(result.contains(OWLClassM.getLongAttributeField()));
}
@Test
public void discoverFieldsFindsFieldsInEntityAndMappedSuperclass() throws Exception {
final Collection<Field> result = fieldSeeker.discoverFields(OWLClassQ.class);
assertTrue(result.size() >= 5); // Can't use equals, because the AspectJ joint points are also returned
assertTrue(result.contains(OWLClassQ.getUriField()));
assertTrue(result.contains(OWLClassQ.getLabelField()));
assertTrue(result.contains(OWLClassQ.getOwlClassAField()));
assertTrue(result.contains(OWLClassQ.getParentStringField()));
assertTrue(result.contains(OWLClassQ.getStringAttributeField()));
}
@Test
public void discoverFieldsIgnoresNonEntitySuperclasses() throws Exception {
final Collection<Field> result = fieldSeeker.discoverFields(Child.class);
assertTrue(result.contains(Child.class.getDeclaredField("uri")));
assertFalse(result.contains(NonEntityParent.class.getDeclaredField("label")));
}
private static class NonEntityParent {
private String label;
}
@OWLClass(iri = "http://krizik.felk.cvut.cz/ontologies/jopa/entities#ChildWithNonEntityParent")
private static class Child extends NonEntityParent {
@Id
private URI uri;
}
}