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=========================================================
21 package org.onap.aai.schemagen.genxsd;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.junit.Assert.assertTrue;
27 import java.io.BufferedWriter;
29 import java.io.FileWriter;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.aai.edges.EdgeIngestor;
37 import org.onap.aai.schemagen.GenerateXsd;
38 import org.onap.aai.setup.SchemaVersion;
39 import org.onap.aai.setup.SchemaVersions;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.springframework.test.context.TestPropertySource;
43 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
45 @RunWith(SpringJUnit4ClassRunner.class)
46 @ContextConfiguration(classes = {SchemaVersions.class, EdgeIngestor.class})
47 @TestPropertySource(properties = {"schema.uri.base.path = /aai"})
48 @Ignore("This test needs to get major rework done as it is written very poorly")
49 public class PutRelationPathSetTest {
50 private static final String EDGEFILENAME =
51 "src/test/resources/dbedgerules/EdgeDescriptionRules_test.json";
53 private static String json;
54 private SchemaVersion v;
55 private File relationsFile;
56 private String target =
57 "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
59 "createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZoneRelationshipListRelationship";
61 "/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;
70 public void setUpBeforeClass() throws Exception {
71 v = schemaVersions.getDefaultVersion();
73 relationsFile = new File(GenerateXsd.getYamlDir() + "/relations/" + v.toString()
74 + "/createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZone.json");
75 json = "{" + " \"rules\": [" + " {" + " \"from\": \"availability-zone\","
76 + " \"to\": \"complex\","
77 + " \"label\": \"org.onap.relationships.inventory.LocatedIn\","
78 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2ONE\","
79 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
80 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
81 + " \"default\": \"true\"," + " \"description\":\"this description\""
82 + " }," + " {" + " \"from\": \"availability-zone\","
83 + " \"to\": \"service-capability\","
84 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
85 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
86 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
87 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
88 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " {"
89 + " \"from\": \"availability-zone\"," + " \"to\": \"cloud-region\","
90 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\","
91 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2ONE\","
92 + " \"contains-other-v\": \"!${direction}\","
93 + " \"delete-other-v\": \"!${direction}\"," + " \"SVC-INFRA\": \"NONE\","
94 + " \"prevent-delete\": \"NONE\"," + " \"default\": \"true\","
95 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"ctag-pool\","
96 + " \"to\": \"availability-zone\","
97 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
98 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
99 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
100 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
101 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " {"
102 + " \"from\": \"dvs-switch\"," + " \"to\": \"availability-zone\","
103 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
104 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
105 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
106 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
107 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " {"
108 + " \"from\": \"generic-vnf\"," + " \"to\": \"availability-zone\","
109 + " \"label\": \"org.onap.relationships.inventory.Uses\","
110 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
111 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
112 + " \"SVC-INFRA\": \"${direction}\","
113 + " \"prevent-delete\": \"!${direction}\"," + " \"default\": \"true\","
114 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"vf-module\","
115 + " \"to\": \"vnfc\","
116 + " \"label\": \"org.onap.relationships.inventory.Uses\","
117 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"ONE2MANY\","
118 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
119 + " \"SVC-INFRA\": \"${direction}\","
120 + " \"prevent-delete\": \"${direction}\"," + " \"default\": \"true\","
121 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"pserver\","
122 + " \"to\": \"availability-zone\","
123 + " \"label\": \"org.onap.relationships.inventory.MemberOf\","
124 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2ONE\","
125 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
126 + " \"SVC-INFRA\": \"${direction}\","
127 + " \"prevent-delete\": \"!${direction}\"," + " \"default\": \"true\","
128 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"vce\","
129 + " \"to\": \"availability-zone\","
130 + " \"label\": \"org.onap.relationships.inventory.Uses\","
131 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
132 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
133 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
134 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " ]}";
136 BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
143 public void setUp() throws Exception {
145 DeleteOperation.deletePaths.put("/cloud-infrastructure/pservers/pserver/{hostname}",
147 DeleteOperation.deletePaths.put("/network/vces/vce/{vnf-id}", "vce");
148 DeleteOperation.deletePaths
149 .put("/cloud-infrastructure/complexes/complex/{physical-location-id}", "complex");
150 DeleteOperation.deletePaths.put(
151 "/service-design-and-creation/service-capabilities/service-capability/{service-type}/{vnf-type}",
152 "service-capability");
153 DeleteOperation.deletePaths.put(
154 "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}",
156 DeleteOperation.deletePaths.put("/network/generic-vnfs/generic-vnf/{vnf-id}",
158 DeleteOperation.deletePaths.put(
159 "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/dvs-switches/dvs-switch/{switch-name}",
161 DeleteOperation.deletePaths.put(
162 "/cloud-infrastructure/complexes/complex/{physical-location-id}/ctag-pools/ctag-pool/{target-pe}/{availability-zone-name}",
165 DeleteOperation.deletePaths.put(path.replace("/relationship-list/relationship", ""),
166 "availability-zone");
167 PutRelationPathSet.add(opId, path);
171 public static void tearDownAfterClass() throws Exception {
172 File edges = new File(EDGEFILENAME);
177 public void testAdd() {
178 PutRelationPathSet.add(opId, path);
179 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
180 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
184 public void testPutRelationPathSet() {
186 this.prp = new PutRelationPathSet(v);
187 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
188 prp.generateRelations(edgeIngestor);
189 assertTrue(this.relationsFile.exists());
190 this.relationsFile.delete();
194 public void testPutRelationPathSetStringString() {
195 this.prp = new PutRelationPathSet(opId, path, v);
196 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
200 public void testGenerateRelations() {
201 PutRelationPathSet prp = new PutRelationPathSet(opId, "availability-zone", v);
202 prp.generateRelations(edgeIngestor);
203 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
204 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
205 assertTrue(this.relationsFile.exists());
206 // this.relationsFile.delete();