2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.util.genxsd;
22 import com.jayway.jsonpath.DocumentContext;
23 import com.jayway.jsonpath.JsonPath;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.onap.aai.introspection.Version;
28 import org.onap.aai.util.GenerateXsd;
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.junit.Assert.assertTrue;
36 public class PutRelationPathSetTest {
37 private DocumentContext jsonContext;
39 private EdgeRuleSet edgeRuleSet;
40 private Version v = Version.getLatest();
41 private File relationsFile = new File(GenerateXsd.getYamlDir() + "/relations/" + v.name()+"/createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZone.json");
42 private String target = "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
43 private String opId = "createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZoneRelationshipListRelationship";
44 private String path = "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
45 PutRelationPathSet prp = null;
50 public static void setUpBeforeClass() throws Exception {
54 public void setUp() throws Exception {
58 + " \"from\": \"availability-zone\","
59 + " \"to\": \"complex\","
60 + " \"label\": \"org.onap.relationships.inventory.LocatedIn\","
61 + " \"direction\": \"OUT\","
62 + " \"multiplicity\": \"MANY2ONE\","
63 + " \"contains-other-v\": \"NONE\","
64 + " \"delete-other-v\": \"NONE\","
65 + " \"SVC-INFRA\": \"NONE\","
66 + " \"prevent-delete\": \"!${direction}\","
67 + " \"default\": \"true\","
68 + " \"description\":\"this description\""
71 + " \"from\": \"availability-zone\","
72 + " \"to\": \"service-capability\","
73 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
74 + " \"direction\": \"OUT\","
75 + " \"multiplicity\": \"MANY2MANY\","
76 + " \"contains-other-v\": \"NONE\","
77 + " \"delete-other-v\": \"NONE\","
78 + " \"SVC-INFRA\": \"NONE\","
79 + " \"prevent-delete\": \"!${direction}\","
80 + " \"default\": \"true\","
81 + " \"description\":\"\""
84 + " \"from\": \"availability-zone\","
85 + " \"to\": \"cloud-region\","
86 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\","
87 + " \"direction\": \"OUT\","
88 + " \"multiplicity\": \"MANY2ONE\","
89 + " \"contains-other-v\": \"!${direction}\","
90 + " \"delete-other-v\": \"!${direction}\","
91 + " \"SVC-INFRA\": \"NONE\","
92 + " \"prevent-delete\": \"NONE\","
93 + " \"default\": \"true\","
94 + " \"description\":\"\""
97 + " \"from\": \"ctag-pool\","
98 + " \"to\": \"availability-zone\","
99 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
100 + " \"direction\": \"OUT\","
101 + " \"multiplicity\": \"MANY2MANY\","
102 + " \"contains-other-v\": \"NONE\","
103 + " \"delete-other-v\": \"NONE\","
104 + " \"SVC-INFRA\": \"NONE\","
105 + " \"prevent-delete\": \"!${direction}\","
106 + " \"default\": \"true\","
107 + " \"description\":\"\""
110 + " \"from\": \"dvs-switch\","
111 + " \"to\": \"availability-zone\","
112 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
113 + " \"direction\": \"OUT\","
114 + " \"multiplicity\": \"MANY2MANY\","
115 + " \"contains-other-v\": \"NONE\","
116 + " \"delete-other-v\": \"NONE\","
117 + " \"SVC-INFRA\": \"NONE\","
118 + " \"prevent-delete\": \"!${direction}\","
119 + " \"default\": \"true\","
120 + " \"description\":\"\""
123 + " \"from\": \"generic-vnf\","
124 + " \"to\": \"availability-zone\","
125 + " \"label\": \"org.onap.relationships.inventory.Uses\","
126 + " \"direction\": \"OUT\","
127 + " \"multiplicity\": \"MANY2MANY\","
128 + " \"contains-other-v\": \"NONE\","
129 + " \"delete-other-v\": \"NONE\","
130 + " \"SVC-INFRA\": \"${direction}\","
131 + " \"prevent-delete\": \"!${direction}\","
132 + " \"default\": \"true\","
133 + " \"description\":\"\""
136 + " \"from\": \"vf-module\","
137 + " \"to\": \"vnfc\","
138 + " \"label\": \"org.onap.relationships.inventory.Uses\","
139 + " \"direction\": \"OUT\","
140 + " \"multiplicity\": \"ONE2MANY\","
141 + " \"contains-other-v\": \"NONE\","
142 + " \"delete-other-v\": \"NONE\","
143 + " \"SVC-INFRA\": \"${direction}\","
144 + " \"prevent-delete\": \"${direction}\","
145 + " \"default\": \"true\","
146 + " \"description\":\"\""
149 + " \"from\": \"pserver\","
150 + " \"to\": \"availability-zone\","
151 + " \"label\": \"org.onap.relationships.inventory.MemberOf\","
152 + " \"direction\": \"OUT\","
153 + " \"multiplicity\": \"MANY2ONE\","
154 + " \"contains-other-v\": \"NONE\","
155 + " \"delete-other-v\": \"NONE\","
156 + " \"SVC-INFRA\": \"${direction}\","
157 + " \"prevent-delete\": \"!${direction}\","
158 + " \"default\": \"true\","
159 + " \"description\":\"\""
162 + " \"from\": \"vce\","
163 + " \"to\": \"availability-zone\","
164 + " \"label\": \"org.onap.relationships.inventory.Uses\","
165 + " \"direction\": \"OUT\","
166 + " \"multiplicity\": \"MANY2MANY\","
167 + " \"contains-other-v\": \"NONE\","
168 + " \"delete-other-v\": \"NONE\","
169 + " \"SVC-INFRA\": \"NONE\","
170 + " \"prevent-delete\": \"!${direction}\","
171 + " \"default\": \"true\","
172 + " \"description\":\"\""
175 jsonContext = JsonPath.parse(json);
176 this.edgeRuleSet = new EdgeRuleSet(jsonContext);
177 DeleteOperation.deletePaths.put("/cloud-infrastructure/pservers/pserver/{hostname}","pserver");
178 DeleteOperation.deletePaths.put("/network/vces/vce/{vnf-id}","vce");
179 DeleteOperation.deletePaths.put("/cloud-infrastructure/complexes/complex/{physical-location-id}","complex");
180 DeleteOperation.deletePaths.put("/service-design-and-creation/service-capabilities/service-capability/{service-type}/{vnf-type}","service-capability");
181 DeleteOperation.deletePaths.put("/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}","cloud-region");
182 DeleteOperation.deletePaths.put("/network/generic-vnfs/generic-vnf/{vnf-id}","generic-vnf");
183 DeleteOperation.deletePaths.put("/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/dvs-switches/dvs-switch/{switch-name}","dvs-switch");
184 DeleteOperation.deletePaths.put("/cloud-infrastructure/complexes/complex/{physical-location-id}/ctag-pools/ctag-pool/{target-pe}/{availability-zone-name}","ctag-pool");
186 DeleteOperation.deletePaths.put(path.replace("/relationship-list/relationship", ""),"availability-zone");
187 PutRelationPathSet.add(opId, path);
191 public void testAdd() {
192 PutRelationPathSet.add(opId, path);
193 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
194 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
198 public void testPutRelationPathSet() {
200 this.prp = new PutRelationPathSet(v);
201 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
202 prp.generateRelations(edgeRuleSet);
203 assertTrue(this.relationsFile.exists());
204 this.relationsFile.delete();
208 public void testPutRelationPathSetStringString() {
209 this.prp = new PutRelationPathSet(opId, path, v);
210 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
214 public void testGenerateRelations() {
215 PutRelationPathSet prp = new PutRelationPathSet(opId, "availability-zone", v);
216 prp.generateRelations(edgeRuleSet);
217 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
218 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
219 assertTrue(this.relationsFile.exists());
220 this.relationsFile.delete();