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.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
27 import java.util.ArrayList;
28 import java.util.HashMap;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.crud.exception.CrudException;
34 public class RelationshipSchemaLoaderTest {
38 ClassLoader classLoader = getClass().getClassLoader();
39 File dir = new File(classLoader.getResource( "model").getFile());
40 System.setProperty("CONFIG_HOME", dir.getParent());
41 RelationshipSchemaLoader.resetVersionContextMap();
45 public void loadModels() throws Exception {
46 RelationshipSchemaLoader.resetVersionContextMap();
47 RelationshipSchemaLoader.loadModels();
48 assertFalse( RelationshipSchemaLoader.getVersionContextMap().keySet().isEmpty());
52 public void loadModelsWithAVersion() throws Exception {
53 RelationshipSchemaLoader.resetVersionContextMap();
54 RelationshipSchemaLoader.loadModels("v11");
55 assertEquals(1, RelationshipSchemaLoader.getVersionContextMap().keySet().size());
56 assertEquals("v11", RelationshipSchemaLoader.getLatestSchemaVersion());
60 public void getSchemaForVersion() throws Exception {
61 RelationshipSchemaLoader.resetVersionContextMap();
62 RelationshipSchemaLoader.loadModels("v11");
63 String version = RelationshipSchemaLoader.getLatestSchemaVersion();
64 RelationshipSchema g = RelationshipSchemaLoader.getSchemaForVersion(version);
65 assertNotNull(g.lookupRelationType("org.onap.relationships.inventory.BelongsTo"));
68 public void getSchemaForVersionManualFile() throws Exception {
69 RelationshipSchemaLoader.resetVersionContextMap();
70 RelationshipSchemaLoader.loadModels("v10");
71 String version = RelationshipSchemaLoader.getLatestSchemaVersion();
72 RelationshipSchema g = RelationshipSchemaLoader.getSchemaForVersion(version);
73 assertNotNull(g.lookupRelationType("locatedIn"));
78 public void getSchemaForVersionFail() throws Exception {
79 RelationshipSchemaLoader.resetVersionContextMap();
80 RelationshipSchemaLoader.loadModels();
82 RelationshipSchemaLoader.getSchemaForVersion("v1");
83 } catch (CrudException e) {
84 assertEquals(404, e.getHttpStatus().getStatusCode());
89 public void setVersionContextMap() throws Exception {
90 RelationshipSchemaLoader.resetVersionContextMap();
91 ArrayList<String> jsonString = new ArrayList<String>();
95 "\"from\": \"availability-zone\"," +
96 "\"to\": \"complex\"," +
97 "\"label\": \"groupsResourcesIn\"," +
98 "\"direction\": \"OUT\"," +
99 "\"multiplicity\": \"Many2Many\"," +
100 "\"contains-other-v\": \"NONE\"," +
101 "\"delete-other-v\": \"NONE\"," +
102 "\"SVC-INFRA\": \"NONE\"," +
103 "\"prevent-delete\": \"!${direction}\"" +
106 " \"isParent\":\"java.lang.Boolean\"," +
107 " \"isParent-REV\":\"java.lang.Boolean\"," +
108 " \"usesResource\":\"java.lang.Boolean\"," +
109 " \"usesResource-REV\":\"java.lang.Boolean\"," +
110 " \"SVC-INFRA\":\"java.lang.Boolean\"," +
111 " \"SVC-INFRA-REV\":\"java.lang.Boolean\"," +
112 " \"hasDelTarget\":\"java.lang.Boolean\"," +
113 " \"hasDelTarget-REV\":\"java.lang.Boolean\"" +
115 jsonString.add(rules);
116 jsonString.add(props);
117 RelationshipSchema nRs = new RelationshipSchema(jsonString);
118 Map<String, RelationshipSchema> versionMap = new HashMap<>();
119 versionMap.put("v1", nRs);
120 RelationshipSchemaLoader.setVersionContextMap(versionMap);
121 assertNotNull(RelationshipSchemaLoader.getSchemaForVersion("v1").lookupRelationType("groupsResourcesIn"));