c39479f53cb474bd7e274a7b27febf9400e6bbd0
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / genxsd / PutRelationPathSetTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.util.genxsd;
21
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.setup.SchemaVersion;
29 import org.onap.aai.setup.SchemaVersions;
30 import org.onap.aai.util.GenerateXsd;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
33 import org.springframework.test.annotation.DirtiesContext;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.TestPropertySource;
36 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37
38 import java.io.BufferedWriter;
39 import java.io.File;
40 import java.io.FileWriter;
41
42 import static org.hamcrest.CoreMatchers.is;
43 import static org.hamcrest.MatcherAssert.assertThat;
44 import static org.junit.Assert.assertTrue;
45
46 @RunWith(SpringJUnit4ClassRunner.class)
47 @ContextConfiguration(classes = {
48         SchemaVersions.class,
49         EdgeIngestor.class
50 })
51 @TestPropertySource(properties = {
52                 "schema.uri.base.path = /aai"
53 })
54 @Ignore("This test needs to get major rework done as it is written very poorly")
55 public class PutRelationPathSetTest {
56         private static final String EDGEFILENAME = "src/test/resources/dbedgerules/EdgeDescriptionRules_test.json";
57
58         private static String json;
59         private SchemaVersion v ;
60         private File relationsFile ;
61         private String target = "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
62         private String opId = "createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZoneRelationshipListRelationship";
63         private String path = "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/availability-zones/availability-zone/{availability-zone-name}/relationship-list/relationship";
64         PutRelationPathSet prp = null;
65          @Autowired
66          SchemaVersions schemaVersions;
67
68          @Autowired
69          EdgeIngestor edgeIngestor;
70         
71
72         @Before
73         public void setUpBeforeClass() throws Exception {
74             v = schemaVersions.getDefaultVersion();
75             
76                 relationsFile = new File(GenerateXsd.getYamlDir() + "/relations/" + v.toString()+"/createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZone.json");
77                 json = "{"
78                                 + "     \"rules\": ["
79                                 + "             {"
80                                 + "                     \"from\": \"availability-zone\","
81                                 + "                     \"to\": \"complex\","
82                                 + "                     \"label\": \"org.onap.relationships.inventory.LocatedIn\","
83                                 + "                     \"direction\": \"OUT\","
84                                 + "                     \"multiplicity\": \"MANY2ONE\","
85                                 + "                     \"contains-other-v\": \"NONE\","
86                                 + "                     \"delete-other-v\": \"NONE\","
87                                 + "                     \"SVC-INFRA\": \"NONE\","
88                                 + "                     \"prevent-delete\": \"!${direction}\","
89                                 + "                     \"default\": \"true\","
90                                 + "                     \"description\":\"this description\""
91                                 + "             },"
92                                 + "    {"
93                                 + "                     \"from\": \"availability-zone\","
94                                 + "                     \"to\": \"service-capability\","
95                                 + "                     \"label\": \"org.onap.relationships.inventory.AppliesTo\","
96                                 + "                     \"direction\": \"OUT\","
97                                 + "                     \"multiplicity\": \"MANY2MANY\","
98                                 + "                     \"contains-other-v\": \"NONE\","
99                                 + "                     \"delete-other-v\": \"NONE\","
100                                 + "                     \"SVC-INFRA\": \"NONE\","
101                                 + "                     \"prevent-delete\": \"!${direction}\","
102                                 + "                     \"default\": \"true\","
103                                 + "                     \"description\":\"\""
104                                 + "             },"
105                                 + "             {"
106                                 + "                     \"from\": \"availability-zone\","
107                                 + "                     \"to\": \"cloud-region\","
108                                 + "                     \"label\": \"org.onap.relationships.inventory.BelongsTo\","
109                                 + "                     \"direction\": \"OUT\","
110                                 + "                     \"multiplicity\": \"MANY2ONE\","
111                                 + "                     \"contains-other-v\": \"!${direction}\","
112                                 + "                     \"delete-other-v\": \"!${direction}\","
113                                 + "                     \"SVC-INFRA\": \"NONE\","
114                                 + "                     \"prevent-delete\": \"NONE\","
115                                 + "                     \"default\": \"true\","
116                                 + "                     \"description\":\"\""
117                                 + "             },"
118                                 + "             {"
119                                 + "                     \"from\": \"ctag-pool\","
120                                 + "                     \"to\": \"availability-zone\","
121                                 + "                     \"label\": \"org.onap.relationships.inventory.AppliesTo\","
122                                 + "                     \"direction\": \"OUT\","
123                                 + "                     \"multiplicity\": \"MANY2MANY\","
124                                 + "                     \"contains-other-v\": \"NONE\","
125                                 + "                     \"delete-other-v\": \"NONE\","
126                                 + "                     \"SVC-INFRA\": \"NONE\","
127                                 + "                     \"prevent-delete\": \"!${direction}\","
128                                 + "                     \"default\": \"true\","
129                                 + "                     \"description\":\"\""
130                                 + "             },"
131                                 + "             {"
132                                 + "                     \"from\": \"dvs-switch\","
133                                 + "                     \"to\": \"availability-zone\","
134                                 + "                     \"label\": \"org.onap.relationships.inventory.AppliesTo\","
135                                 + "                     \"direction\": \"OUT\","
136                                 + "                     \"multiplicity\": \"MANY2MANY\","
137                                 + "                     \"contains-other-v\": \"NONE\","
138                                 + "                     \"delete-other-v\": \"NONE\","
139                                 + "                     \"SVC-INFRA\": \"NONE\","
140                                 + "                     \"prevent-delete\": \"!${direction}\","
141                                 + "                     \"default\": \"true\","
142                                 + "                     \"description\":\"\""
143                                 + "             },"
144                                 + "             {"
145                                 + "                     \"from\": \"generic-vnf\","
146                                 + "                     \"to\": \"availability-zone\","
147                                 + "                     \"label\": \"org.onap.relationships.inventory.Uses\","
148                                 + "                     \"direction\": \"OUT\","
149                                 + "                     \"multiplicity\": \"MANY2MANY\","
150                                 + "                     \"contains-other-v\": \"NONE\","
151                                 + "                     \"delete-other-v\": \"NONE\","
152                                 + "                     \"SVC-INFRA\": \"${direction}\","
153                                 + "                     \"prevent-delete\": \"!${direction}\","
154                                 + "                     \"default\": \"true\","
155                                 + "                     \"description\":\"\""
156                                 + "             },"
157                                 + "             {"
158                                 + "                     \"from\": \"vf-module\","
159                                 + "                     \"to\": \"vnfc\","
160                                 + "                     \"label\": \"org.onap.relationships.inventory.Uses\","
161                                 + "                     \"direction\": \"OUT\","
162                                 + "                     \"multiplicity\": \"ONE2MANY\","
163                                 + "                     \"contains-other-v\": \"NONE\","
164                                 + "                     \"delete-other-v\": \"NONE\","
165                                 + "                     \"SVC-INFRA\": \"${direction}\","
166                                 + "                     \"prevent-delete\": \"${direction}\","
167                                 + "                     \"default\": \"true\","
168                                 + "                     \"description\":\"\""
169                                 + "             },"
170                                 + "             {"
171                                 + "                     \"from\": \"pserver\","
172                                 + "                     \"to\": \"availability-zone\","
173                                 + "                     \"label\": \"org.onap.relationships.inventory.MemberOf\","
174                                 + "                     \"direction\": \"OUT\","
175                                 + "                     \"multiplicity\": \"MANY2ONE\","
176                                 + "                     \"contains-other-v\": \"NONE\","
177                                 + "                     \"delete-other-v\": \"NONE\","
178                                 + "                     \"SVC-INFRA\": \"${direction}\","
179                                 + "                     \"prevent-delete\": \"!${direction}\","
180                                 + "                     \"default\": \"true\","
181                                 + "                     \"description\":\"\""
182                                 + "             },"
183                                 + "             {"
184                                 + "                     \"from\": \"vce\","
185                                 + "                     \"to\": \"availability-zone\","
186                                 + "                     \"label\": \"org.onap.relationships.inventory.Uses\","
187                                 + "                     \"direction\": \"OUT\","
188                                 + "                     \"multiplicity\": \"MANY2MANY\","
189                                 + "                     \"contains-other-v\": \"NONE\","
190                                 + "                     \"delete-other-v\": \"NONE\","
191                                 + "                     \"SVC-INFRA\": \"NONE\","
192                                 + "                     \"prevent-delete\": \"!${direction}\","
193                                 + "                     \"default\": \"true\","
194                                 + "                     \"description\":\"\""
195                                 + "             },"
196                                 + "     ]}";
197        
198                 BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
199                 bw.write(json);
200                 bw.close();
201                 
202         }
203
204         @Before
205         public void setUp() throws Exception {
206
207                 DeleteOperation.deletePaths.put("/cloud-infrastructure/pservers/pserver/{hostname}","pserver");
208                 DeleteOperation.deletePaths.put("/network/vces/vce/{vnf-id}","vce");
209                 DeleteOperation.deletePaths.put("/cloud-infrastructure/complexes/complex/{physical-location-id}","complex");
210                 DeleteOperation.deletePaths.put("/service-design-and-creation/service-capabilities/service-capability/{service-type}/{vnf-type}","service-capability");
211                 DeleteOperation.deletePaths.put("/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}","cloud-region");
212                 DeleteOperation.deletePaths.put("/network/generic-vnfs/generic-vnf/{vnf-id}","generic-vnf");
213                 DeleteOperation.deletePaths.put("/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/dvs-switches/dvs-switch/{switch-name}","dvs-switch");
214                 DeleteOperation.deletePaths.put("/cloud-infrastructure/complexes/complex/{physical-location-id}/ctag-pools/ctag-pool/{target-pe}/{availability-zone-name}","ctag-pool");
215                 
216                 DeleteOperation.deletePaths.put(path.replace("/relationship-list/relationship", ""),"availability-zone");
217                 PutRelationPathSet.add(opId, path);
218         }
219         @AfterClass
220         public static void tearDownAfterClass() throws Exception {
221                 File edges = new File(EDGEFILENAME);
222                 edges.delete();
223         }
224         @Test
225         public void testAdd() {
226                 PutRelationPathSet.add(opId, path);
227                 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
228                 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
229         }
230
231         @Test
232         public void testPutRelationPathSet() {
233
234                 this.prp = new PutRelationPathSet(v);
235                 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
236                 prp.generateRelations(edgeIngestor);
237                 assertTrue(this.relationsFile.exists());
238                 this.relationsFile.delete();
239         }
240
241         @Test
242         public void testPutRelationPathSetStringString() {
243                 this.prp = new PutRelationPathSet(opId, path, v);
244                 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
245         }
246
247         @Test
248         public void testGenerateRelations() {
249                 PutRelationPathSet prp = new PutRelationPathSet(opId, "availability-zone", v);
250                 prp.generateRelations(edgeIngestor);
251                 assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
252                 assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
253                 assertTrue(this.relationsFile.exists());
254 //              this.relationsFile.delete();
255         }
256
257 }
258
259