-
Notifications
You must be signed in to change notification settings - Fork 14
/
SingularObjectPropertyStrategyTest.java
70 lines (58 loc) · 3.07 KB
/
SingularObjectPropertyStrategyTest.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
61
62
63
64
65
66
67
68
69
70
package cz.cvut.kbss.jopa.oom;
import cz.cvut.kbss.jopa.environment.OWLClassP;
import cz.cvut.kbss.jopa.environment.utils.MetamodelMocks;
import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
import cz.cvut.kbss.ontodriver.descriptor.AxiomValueDescriptor;
import cz.cvut.kbss.ontodriver.model.*;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.net.URI;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
public class SingularObjectPropertyStrategyTest {
private static final URI PK = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa#entity");
private static final URI PROPERTY = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/attributes#hasA");
private static final URI VALUE = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/individualAAA");
@Mock
private EntityMappingHelper mapperMock;
private MetamodelMocks metamodelMocks;
private Descriptor descriptor = new EntityDescriptor();
private AxiomValueGatherer gatherer;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
this.metamodelMocks = new MetamodelMocks();
this.gatherer = new AxiomValueGatherer(NamedResource.create(PK), null);
}
@Test
public void buildInstanceFieldSupportsPlainIdentifierValues() throws Exception {
final FieldStrategy<? extends FieldSpecification<? super OWLClassP, ?>, OWLClassP> strategy = new SingularObjectPropertyStrategy<>(
metamodelMocks.forOwlClassP().entityType(), metamodelMocks.forOwlClassP().pUriAttribute(), descriptor,
mapperMock);
strategy.addValueFromAxiom(
new AxiomImpl<>(NamedResource.create(PK), Assertion.createObjectPropertyAssertion(PROPERTY, false),
new Value<>(NamedResource.create(VALUE))));
final OWLClassP p = new OWLClassP();
strategy.buildInstanceFieldValue(p);
assertEquals(VALUE, p.getIndividualUri());
}
@Test
public void buildsAxiomFromPlainIdentifierValue() throws Exception {
final OWLClassP p = new OWLClassP();
p.setIndividualUri(VALUE);
final FieldStrategy<? extends FieldSpecification<? super OWLClassP, ?>, OWLClassP> strategy = new SingularObjectPropertyStrategy<>(
metamodelMocks.forOwlClassP().entityType(), metamodelMocks.forOwlClassP().pUriAttribute(), descriptor,
mapperMock);
strategy.buildAxiomValuesFromInstance(p, gatherer);
final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(gatherer);
assertEquals(1, valueDescriptor.getAssertions().size());
final List<Value<?>> axioms = valueDescriptor.getAssertionValues(Assertion.createObjectPropertyAssertion(PROPERTY, false));
assertEquals(1, axioms.size());
assertEquals(NamedResource.create(VALUE), axioms.get(0).getValue());
}
}