-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestAxiomExtension.java
96 lines (74 loc) · 4.2 KB
/
TestAxiomExtension.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.axiom.lang.test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.util.Optional;
import org.testng.annotations.Test;
import com.evolveum.axiom.api.AxiomName;
import com.evolveum.axiom.api.AxiomItem;
import com.evolveum.axiom.api.schema.AxiomSchemaContext;
import com.evolveum.axiom.api.schema.AxiomTypeDefinition;
import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type;
import com.evolveum.axiom.lang.impl.ModelReactorContext;
import com.evolveum.axiom.lang.spi.AxiomSyntaxException;
public class TestAxiomExtension extends AbstractReactorTest {
private static final AxiomName PERSON = AxiomName.from("https://example.org", "Person");
private static final AxiomName STORAGE = AxiomName.from("https://example.org/extension", "type");
private static final AxiomName PERSON_EXTENSION = AxiomName.from("https://schema.org", "SchemaOrgPerson");
private static final String DIR = "multimodel/extension/";
private static final String SCHEMA_ORG = DIR + "person-extension.axiom";
private static final String BASE = DIR + "test-person.axiom";
private static final String ORDER = DIR + "declaration-order.axiom";
private static final String LANG_EXT = DIR + "language-extension.axiom";
private static final String LANG_EXT_USE = DIR + "language-extension-use.axiom";
@Test
public void axiomTestExtension() throws IOException, AxiomSyntaxException {
ModelReactorContext context = ModelReactorContext.defaultReactor();
context.loadModelFromSource(source(SCHEMA_ORG));
context.loadModelFromSource(source(BASE));
AxiomSchemaContext schemaContext = context.computeSchemaContext();
Optional<AxiomTypeDefinition> personDef = schemaContext.getType(PERSON);
assertTrue(personDef.isPresent());
Optional<AxiomTypeDefinition> extPersonDef = schemaContext.getType(PERSON_EXTENSION);
assertTrue(extPersonDef.isPresent());
for(AxiomName item : extPersonDef.get().itemDefinitions().keySet()) {
assertTrue(personDef.get().itemDefinition(item).isPresent());
}
}
@Test
public void axiomTestOrder() throws IOException, AxiomSyntaxException {
ModelReactorContext context = ModelReactorContext.defaultReactor();
context.loadModelFromSource(source(ORDER));
AxiomSchemaContext schemaContext = context.computeSchemaContext();
AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get();
Optional<AxiomTypeDefinition> personDef = schemaContext.getType(PERSON);
assertTrue(personDef.isPresent());
assertEquals(2, personDef.get().itemDefinitions().entrySet().size());
}
@Test
public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxException {
assertTrue(Type.AUGMENTATION_DEFINITION.isSubtypeOf(Type.TYPE_DEFINITION));
ModelReactorContext context = ModelReactorContext.defaultReactor();
context.loadModelFromSource(source(LANG_EXT));
AxiomSchemaContext schemaContext = context.computeSchemaContext();
AxiomTypeDefinition typeDef = schemaContext.getType(Type.TYPE_DEFINITION.name()).get();
assertNotNull(typeDef.itemDefinition(STORAGE).get());
ModelReactorContext extendedLanguage = ModelReactorContext.reactor(schemaContext);
extendedLanguage.loadModelFromSource(source(LANG_EXT));
extendedLanguage.loadModelFromSource(source(LANG_EXT_USE));
schemaContext = extendedLanguage.computeSchemaContext();
Optional<AxiomTypeDefinition> personDef = schemaContext.getType(PERSON);
assertTrue(personDef.isPresent());
AxiomItem<?> extension = personDef.get().asComplex().get().item(STORAGE).get();
assertFalse(extension.values().isEmpty(), "Extension statements should be available.");
assertEquals(2, personDef.get().itemDefinitions().entrySet().size());
}
}