Replace all tab characters in java files with two spaces to remove linter warning
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / 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.schemagen.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.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;
35
36 import java.io.BufferedWriter;
37 import java.io.File;
38 import java.io.FileWriter;
39
40 import static org.hamcrest.CoreMatchers.is;
41 import static org.hamcrest.MatcherAssert.assertThat;
42 import static org.junit.Assert.assertTrue;
43
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(classes = {
46   SchemaVersions.class,
47   EdgeIngestor.class
48 })
49 @TestPropertySource(properties = {
50     "schema.uri.base.path = /aai"
51 })
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";
55
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;
63    @Autowired
64      SchemaVersions schemaVersions;
65
66    @Autowired
67      EdgeIngestor edgeIngestor;
68
69
70   @Before
71   public void setUpBeforeClass() throws Exception {
72       v = schemaVersions.getDefaultVersion();
73
74     relationsFile = new File(GenerateXsd.getYamlDir() + "/relations/" + v.toString()+"/createOrUpdateCloudInfrastructureCloudRegionsCloudRegionAvailabilityZonesAvailabilityZone.json");
75     json = "{"
76         + "  \"rules\": ["
77         + "    {"
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\""
89         + "    },"
90         + "    {"
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\":\"\""
102         + "    },"
103         + "    {"
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\":\"\""
115         + "    },"
116         + "    {"
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\":\"\""
128         + "    },"
129         + "    {"
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\":\"\""
141         + "    },"
142         + "    {"
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\":\"\""
154         + "    },"
155         + "    {"
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\":\"\""
167         + "    },"
168         + "    {"
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\":\"\""
180         + "    },"
181         + "    {"
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\":\"\""
193         + "    },"
194         + "  ]}";
195
196     BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
197     bw.write(json);
198     bw.close();
199
200   }
201
202   @Before
203   public void setUp() throws Exception {
204
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");
213
214     DeleteOperation.deletePaths.put(path.replace("/relationship-list/relationship", ""),"availability-zone");
215     PutRelationPathSet.add(opId, path);
216   }
217   @AfterClass
218   public static void tearDownAfterClass() throws Exception {
219     File edges = new File(EDGEFILENAME);
220     edges.delete();
221   }
222   @Test
223   public void testAdd() {
224     PutRelationPathSet.add(opId, path);
225     assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
226     assertThat(PutRelationPathSet.putRelationPaths.get(opId), is(target));
227   }
228
229   @Test
230   public void testPutRelationPathSet() {
231
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();
237   }
238
239   @Test
240   public void testPutRelationPathSetStringString() {
241     this.prp = new PutRelationPathSet(opId, path, v);
242     assertThat(PutRelationPathSet.putRelationPaths.size(), is(1));
243   }
244
245   @Test
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();
253   }
254
255 }
256
257