2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.schema;
23 import static org.junit.Assert.*;
24 import edu.emory.mathcs.backport.java.util.Arrays;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.crud.exception.CrudException;
30 import java.util.ArrayList;
31 import java.util.HashMap;
34 import static org.junit.Assert.*;
36 public class RelationshipSchemaLoaderTest {
40 ClassLoader classLoader = getClass().getClassLoader();
41 File dir = new File(classLoader.getResource( "model").getFile());
42 System.setProperty("CONFIG_HOME", dir.getParent());
43 RelationshipSchemaLoader.resetVersionContextMap();
47 public void loadModels() throws Exception {
48 RelationshipSchemaLoader.loadModels();
49 assertFalse( RelationshipSchemaLoader.getVersionContextMap().keySet().isEmpty());
53 public void loadModelsWithAVersion() throws Exception {
54 RelationshipSchemaLoader.loadModels("v11");
55 assertEquals(1, RelationshipSchemaLoader.getVersionContextMap().keySet().size());
56 assertEquals("v11", RelationshipSchemaLoader.getLatestSchemaVersion());
60 public void getSchemaForVersion() throws Exception {
61 RelationshipSchemaLoader.loadModels("v11");
62 String version = RelationshipSchemaLoader.getLatestSchemaVersion();
63 RelationshipSchema g = RelationshipSchemaLoader.getSchemaForVersion(version);
64 assertNotNull(g.lookupRelationType("org.onap.relationships.inventory.BelongsTo"));
68 public void getSchemaForVersionFail() throws Exception {
69 RelationshipSchemaLoader.loadModels();
71 RelationshipSchemaLoader.getSchemaForVersion("v1");
72 } catch (CrudException e) {
73 assertEquals(404, e.getHttpStatus().getStatusCode());
78 public void setVersionContextMap() throws Exception {
79 ArrayList<String> jsonString = new ArrayList<String>();
83 "\"from\": \"availability-zone\"," +
84 "\"to\": \"complex\"," +
85 "\"label\": \"groupsResourcesIn\"," +
86 "\"direction\": \"OUT\"," +
87 "\"multiplicity\": \"Many2Many\"," +
88 "\"contains-other-v\": \"NONE\"," +
89 "\"delete-other-v\": \"NONE\"," +
90 "\"SVC-INFRA\": \"NONE\"," +
91 "\"prevent-delete\": \"!${direction}\"" +
94 " \"isParent\":\"java.lang.Boolean\"," +
95 " \"isParent-REV\":\"java.lang.Boolean\"," +
96 " \"usesResource\":\"java.lang.Boolean\"," +
97 " \"usesResource-REV\":\"java.lang.Boolean\"," +
98 " \"SVC-INFRA\":\"java.lang.Boolean\"," +
99 " \"SVC-INFRA-REV\":\"java.lang.Boolean\"," +
100 " \"hasDelTarget\":\"java.lang.Boolean\"," +
101 " \"hasDelTarget-REV\":\"java.lang.Boolean\"" +
103 jsonString.add(rules);
104 jsonString.add(props);
105 RelationshipSchema nRs = new RelationshipSchema(jsonString);
106 Map<String, RelationshipSchema> versionMap = new HashMap<>();
107 versionMap.put("v1", nRs);
108 RelationshipSchemaLoader.setVersionContextMap(versionMap);
109 assertNotNull(RelationshipSchemaLoader.getSchemaForVersion("v1").lookupRelationType("groupsResourcesIn"));