1 package org.onap.schema;
3 import static org.junit.Assert.*;
4 import edu.emory.mathcs.backport.java.util.Arrays;
5 import org.junit.Before;
7 import org.onap.crud.exception.CrudException;
10 import java.util.ArrayList;
11 import java.util.HashMap;
14 import static org.junit.Assert.*;
16 public class RelationshipSchemaLoaderTest {
20 ClassLoader classLoader = getClass().getClassLoader();
21 File dir = new File(classLoader.getResource( "model").getFile());
22 System.setProperty("CONFIG_HOME", dir.getParent());
23 RelationshipSchemaLoader.resetVersionContextMap();
27 public void loadModels() throws Exception {
28 RelationshipSchemaLoader.loadModels();
29 assertFalse( RelationshipSchemaLoader.getVersionContextMap().keySet().isEmpty());
33 public void loadModelsWithAVersion() throws Exception {
34 RelationshipSchemaLoader.loadModels("v11");
35 assertEquals(1, RelationshipSchemaLoader.getVersionContextMap().keySet().size());
36 assertEquals("v11", RelationshipSchemaLoader.getLatestSchemaVersion());
40 public void getSchemaForVersion() throws Exception {
41 RelationshipSchemaLoader.loadModels("v11");
42 String version = RelationshipSchemaLoader.getLatestSchemaVersion();
43 RelationshipSchema g = RelationshipSchemaLoader.getSchemaForVersion(version);
44 assertNotNull(g.lookupRelationType("isMemberOf"));
48 public void getSchemaForVersionFail() throws Exception {
49 RelationshipSchemaLoader.loadModels();
51 RelationshipSchemaLoader.getSchemaForVersion("v1");
52 } catch (CrudException e) {
53 assertEquals(404, e.getHttpStatus().getStatusCode());
58 public void setVersionContextMap() throws Exception {
59 ArrayList<String> jsonString = new ArrayList<String>();
63 "\"from\": \"availability-zone\"," +
64 "\"to\": \"complex\"," +
65 "\"label\": \"groupsResourcesIn\"," +
66 "\"direction\": \"OUT\"," +
67 "\"multiplicity\": \"Many2Many\"," +
68 "\"contains-other-v\": \"NONE\"," +
69 "\"delete-other-v\": \"NONE\"," +
70 "\"SVC-INFRA\": \"NONE\"," +
71 "\"prevent-delete\": \"!${direction}\"" +
74 " \"isParent\":\"java.lang.Boolean\"," +
75 " \"isParent-REV\":\"java.lang.Boolean\"," +
76 " \"usesResource\":\"java.lang.Boolean\"," +
77 " \"usesResource-REV\":\"java.lang.Boolean\"," +
78 " \"SVC-INFRA\":\"java.lang.Boolean\"," +
79 " \"SVC-INFRA-REV\":\"java.lang.Boolean\"," +
80 " \"hasDelTarget\":\"java.lang.Boolean\"," +
81 " \"hasDelTarget-REV\":\"java.lang.Boolean\"" +
83 jsonString.add(rules);
84 jsonString.add(props);
85 RelationshipSchema nRs = new RelationshipSchema(jsonString);
86 Map<String, RelationshipSchema> versionMap = new HashMap<>();
87 versionMap.put("v1", nRs);
88 RelationshipSchemaLoader.setVersionContextMap(versionMap);
89 assertNotNull(RelationshipSchemaLoader.getSchemaForVersion("v1").lookupRelationType("groupsResourcesIn"));