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.schemagen.genxsd;
22 import org.junit.AfterClass;
23 import org.junit.Before;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.onap.aai.edges.EdgeIngestor;
28 import org.onap.aai.schemagen.GenerateXsd;
29 import org.onap.aai.setup.SchemaVersion;
30 import org.onap.aai.setup.SchemaVersions;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.TestPropertySource;
34 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import java.io.BufferedWriter;
38 import java.io.FileWriter;
40 import static org.hamcrest.CoreMatchers.is;
41 import static org.hamcrest.MatcherAssert.assertThat;
42 import static org.junit.Assert.assertTrue;
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(classes = {
49 @TestPropertySource(properties = {
50 "schema.uri.base.path = /aai"
52 @Ignore("This test needs to get major rework done as it is written very poorly")
53 public class PutRelationPathSetTest {
54 private static final String EDGEFILENAME = "src/test/resources/dbedgerules/EdgeDescriptionRules_test.json";
56 private static String json;
57 private SchemaVersion v ;
58 private File relationsFile ;
59 private String target = "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
60 private String opId = "createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZoneRelationshipListRelationship";
61 private String path = "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
62 PutRelationPathSet prp = null;
64 SchemaVersions schemaVersions;
67 EdgeIngestor edgeIngestor;
71 public void setUpBeforeClass() throws Exception {
72 v = schemaVersions.getDefaultVersion();
74 relationsFile = new File(GenerateXsd.getYamlDir() + "/relations/" + v.toString()+"/createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZone.json");
78 + " \"from\": \"availability-zone\","
79 + " \"to\": \"complex\","
80 + " \"label\": \"org.onap.relationships.inventory.LocatedIn\","
81 + " \"direction\": \"OUT\","
82 + " \"multiplicity\": \"MANY2ONE\","
83 + " \"contains-other-v\": \"NONE\","
84 + " \"delete-other-v\": \"NONE\","
85 + " \"SVC-INFRA\": \"NONE\","
86 + " \"prevent-delete\": \"!${direction}\","
87 + " \"default\": \"true\","
88 + " \"description\":\"this description\""
91 + " \"from\": \"availability-zone\","
92 + " \"to\": \"service-capability\","
93 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
94 + " \"direction\": \"OUT\","
95 + " \"multiplicity\": \"MANY2MANY\","
96 + " \"contains-other-v\": \"NONE\","
97 + " \"delete-other-v\": \"NONE\","
98 + " \"SVC-INFRA\": \"NONE\","
99 + " \"prevent-delete\": \"!${direction}\","
100 + " \"default\": \"true\","
101 + " \"description\":\"\""
104 + " \"from\": \"availability-zone\","
105 + " \"to\": \"cloud-region\","
106 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\","
107 + " \"direction\": \"OUT\","
108 + " \"multiplicity\": \"MANY2ONE\","
109 + " \"contains-other-v\": \"!${direction}\","
110 + " \"delete-other-v\": \"!${direction}\","
111 + " \"SVC-INFRA\": \"NONE\","
112 + " \"prevent-delete\": \"NONE\","
113 + " \"default\": \"true\","
114 + " \"description\":\"\""
117 + " \"from\": \"ctag-pool\","
118 + " \"to\": \"availability-zone\","
119 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
120 + " \"direction\": \"OUT\","
121 + " \"multiplicity\": \"MANY2MANY\","
122 + " \"contains-other-v\": \"NONE\","
123 + " \"delete-other-v\": \"NONE\","
124 + " \"SVC-INFRA\": \"NONE\","
125 + " \"prevent-delete\": \"!${direction}\","
126 + " \"default\": \"true\","
127 + " \"description\":\"\""
130 + " \"from\": \"dvs-switch\","
131 + " \"to\": \"availability-zone\","
132 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
133 + " \"direction\": \"OUT\","
134 + " \"multiplicity\": \"MANY2MANY\","
135 + " \"contains-other-v\": \"NONE\","
136 + " \"delete-other-v\": \"NONE\","
137 + " \"SVC-INFRA\": \"NONE\","
138 + " \"prevent-delete\": \"!${direction}\","
139 + " \"default\": \"true\","
140 + " \"description\":\"\""
143 + " \"from\": \"generic-vnf\","
144 + " \"to\": \"availability-zone\","
145 + " \"label\": \"org.onap.relationships.inventory.Uses\","
146 + " \"direction\": \"OUT\","
147 + " \"multiplicity\": \"MANY2MANY\","
148 + " \"contains-other-v\": \"NONE\","
149 + " \"delete-other-v\": \"NONE\","
150 + " \"SVC-INFRA\": \"${direction}\","
151 + " \"prevent-delete\": \"!${direction}\","
152 + " \"default\": \"true\","
153 + " \"description\":\"\""
156 + " \"from\": \"vf-module\","
157 + " \"to\": \"vnfc\","
158 + " \"label\": \"org.onap.relationships.inventory.Uses\","
159 + " \"direction\": \"OUT\","
160 + " \"multiplicity\": \"ONE2MANY\","
161 + " \"contains-other-v\": \"NONE\","
162 + " \"delete-other-v\": \"NONE\","
163 + " \"SVC-INFRA\": \"${direction}\","
164 + " \"prevent-delete\": \"${direction}\","
165 + " \"default\": \"true\","
166 + " \"description\":\"\""
169 + " \"from\": \"pserver\","
170 + " \"to\": \"availability-zone\","
171 + " \"label\": \"org.onap.relationships.inventory.MemberOf\","
172 + " \"direction\": \"OUT\","
173 + " \"multiplicity\": \"MANY2ONE\","
174 + " \"contains-other-v\": \"NONE\","
175 + " \"delete-other-v\": \"NONE\","
176 + " \"SVC-INFRA\": \"${direction}\","
177 + " \"prevent-delete\": \"!${direction}\","
178 + " \"default\": \"true\","
179 + " \"description\":\"\""
182 + " \"from\": \"vce\","
183 + " \"to\": \"availability-zone\","
184 + " \"label\": \"org.onap.relationships.inventory.Uses\","
185 + " \"direction\": \"OUT\","
186 + " \"multiplicity\": \"MANY2MANY\","
187 + " \"contains-other-v\": \"NONE\","
188 + " \"delete-other-v\": \"NONE\","
189 + " \"SVC-INFRA\": \"NONE\","
190 + " \"prevent-delete\": \"!${direction}\","
191 + " \"default\": \"true\","
192 + " \"description\":\"\""
196 BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
203 public void setUp() throws Exception {
205 DeleteOperation.deletePaths.put("/cloud-infrastructure/pservers/pserver/{hostname}","pserver");
206 DeleteOperation.deletePaths.put("/network/vces/vce/{vnf-id}","vce");
207 DeleteOperation.deletePaths.put("/cloud-infrastructure/complexes/complex/{physical-location-id}","complex");
208 DeleteOperation.deletePaths.put("/service-design-and-creation/service-capabilities/service-capability/{service-type}/{vnf-type}","service-capability");
209 DeleteOperation.deletePaths.put("/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}","cloud-region");
210 DeleteOperation.deletePaths.put("/network/generic-vnfs/generic-vnf/{vnf-id}","generic-vnf");
211 DeleteOperation.deletePaths.put("/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/dvs-switches/dvs-switch/{switch-name}","dvs-switch");
212 DeleteOperation.deletePaths.put("/cloud-infrastructure/complexes/complex/{physical-location-id}/ctag-pools/ctag-pool/{target-pe}/{availability-zone-name}","ctag-pool");
214 DeleteOperation.deletePaths.put(path.replace("/relationship-list/relationship", ""),"availability-zone");
215 PutRelationPathSet.add(opId, path);
218 public static void tearDownAfterClass() throws Exception {
219 File edges = new File(EDGEFILENAME);
223 public void testAdd() {
224 PutRelationPathSet.add(opId, path);
225 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
226 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
230 public void testPutRelationPathSet() {
232 this.prp = new PutRelationPathSet(v);
233 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
234 prp.generateRelations(edgeIngestor);
235 assertTrue(this.relationsFile.exists());
236 this.relationsFile.delete();
240 public void testPutRelationPathSetStringString() {
241 this.prp = new PutRelationPathSet(opId, path, v);
242 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
246 public void testGenerateRelations() {
247 PutRelationPathSet prp = new PutRelationPathSet(opId, "availability-zone", v);
248 prp.generateRelations(edgeIngestor);
249 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
250 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
251 assertTrue(this.relationsFile.exists());
252 // this.relationsFile.delete();