75e1a31c455e29d798d5bc5534caf17540860e2f
[sdnc/apps.git] /
1 package org.onap.sdnc.apps.ms.gra.controllers;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotEquals;
5 import static org.junit.Assert.assertNull;
6
7 import java.io.IOException;
8 import java.nio.file.Files;
9 import java.nio.file.Paths;
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import com.fasterxml.jackson.databind.ObjectMapper;
14
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.onap.sdnc.apps.ms.gra.GenericResourceMsApp;
19 import org.onap.sdnc.apps.ms.gra.data.*;
20 import org.onap.sdnc.apps.ms.gra.swagger.model.*;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
23 import org.springframework.boot.test.context.SpringBootTest;
24 import org.springframework.http.MediaType;
25 import org.springframework.test.context.junit4.SpringRunner;
26 import org.springframework.test.web.servlet.MockMvc;
27 import org.springframework.test.web.servlet.MvcResult;
28 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
29 import org.springframework.transaction.annotation.Transactional;
30
31 @RunWith(SpringRunner.class)
32 @SpringBootTest(classes={GenericResourceMsApp.class})
33 @AutoConfigureMockMvc
34 @Transactional
35 public class ConfigApiServicesControllerTest {
36
37     private final static String CONFIG_SERVICES_URL = "/config/GENERIC-RESOURCE-API:services/";
38     private final static String CONFIG_SERVICES_SERVICE_URL = "/config/GENERIC-RESOURCE-API:services/service/";
39     private final static String CONFIG_CR_ARS_CR_AR_URL = "/config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/";
40     private final static String CONFIG_PM_CONFIGS_PM_CONFIG_URL = "/config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/";
41
42     @Autowired
43     private MockMvc mvc;
44
45     @Autowired
46     ConfigServicesRepository configServicesRepository;
47
48     @Autowired
49     ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
50
51     @Autowired
52     ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
53
54     @BeforeClass
55     public static void setUp() throws Exception {
56         System.out.println("ConfigApiServicesControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir");
57         System.setProperty("serviceLogicProperties", "src/test/resources/svclogic.properties");
58         System.setProperty("serviceLogicDirectory", "src/test/resources/svclogic");
59         System.setProperty("sdnc.config.dir", "src/test/resources");
60    
61     }
62
63
64     @Test
65     public void configGENERICRESOURCEAPIservicesDelete() throws Exception {
66
67         // Clean up data
68         configServicesRepository.deleteAll();
69
70         // Load test data
71         loadServicesData( "src/test/resources/service1.json");
72
73         assertEquals(1, configServicesRepository.count());
74         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
75                 .andReturn();
76         assertEquals(204, mvcResult.getResponse().getStatus());
77         assertEquals(0, configServicesRepository.count());
78
79         // Test with no data
80         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
81                 .andReturn();
82         assertEquals(204, mvcResult.getResponse().getStatus());
83
84     }
85
86     @Test
87     public void configGENERICRESOURCEAPIservicesGet() throws Exception {
88         // Clean up data
89         configServicesRepository.deleteAll();
90
91         // Test with data
92         loadServicesData("src/test/resources/service1.json");
93         assert(configServicesRepository.count() > 0);
94
95         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
96                 .andReturn();
97         assertEquals(200, mvcResult.getResponse().getStatus());
98
99         // Test with no data
100         configServicesRepository.deleteAll();
101         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
102                 .andReturn();
103         assertEquals(404, mvcResult.getResponse().getStatus());
104     }
105
106     @Test
107     public void configGENERICRESOURCEAPIservicesPost() throws Exception {
108         // Clean up data
109         configServicesRepository.deleteAll();
110
111         String content = readFileContent("src/test/resources/service1.json");
112
113         // Test with no data
114         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
115                 .andReturn();
116         assertEquals(201, mvcResult.getResponse().getStatus());
117         assertEquals(1, configServicesRepository.count());
118
119         // Test with existing data - should return 409
120         mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
121                 .andReturn();
122         assertEquals(409, mvcResult.getResponse().getStatus());
123         assertEquals(1, configServicesRepository.count());
124
125         // Clean up data
126         configServicesRepository.deleteAll();
127
128     }
129
130     @Test
131     public void configGENERICRESOURCEAPIservicesPut() throws Exception {
132         // Clean up data
133         configServicesRepository.deleteAll();
134
135         String content = readFileContent("src/test/resources/service1.json");
136
137         // Test with no data
138         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
139                 .andReturn();
140         assertEquals(201, mvcResult.getResponse().getStatus());
141         assertEquals(1, configServicesRepository.count());
142
143         // Test with existing data - should return 409
144         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
145                 .andReturn();
146         assertEquals(204, mvcResult.getResponse().getStatus());
147         assertEquals(1, configServicesRepository.count());
148
149         // Clean up data
150         configServicesRepository.deleteAll();
151
152     }
153
154     @Test
155     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdDelete() throws Exception {
156         // Clean up data
157         configServicesRepository.deleteAll();
158
159         // Test with no data
160         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
161                 .andReturn();
162         assertEquals(204, mvcResult.getResponse().getStatus());
163         assertEquals(0, configServicesRepository.count());
164
165         // Load data
166         loadServicesData("src/test/resources/service1.json");
167         assertEquals(1, configServicesRepository.count());
168
169         // Test with data
170         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
171                 .andReturn();
172         assertEquals(204, mvcResult.getResponse().getStatus());
173         assertEquals(0, configServicesRepository.count());
174
175     }
176
177     @Test
178     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet() throws Exception {
179         // Clean up data
180         configServicesRepository.deleteAll();
181
182         // Test with data
183         loadServicesData("src/test/resources/service1.json");
184         assert(configServicesRepository.count() > 0);
185
186         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
187                 .andReturn();
188         assertEquals(200, mvcResult.getResponse().getStatus());
189
190         // Test with no data
191         configServicesRepository.deleteAll();
192         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
193                 .andReturn();
194         assertEquals(404, mvcResult.getResponse().getStatus());
195     }
196
197     @Test
198     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost() throws Exception {
199         // Clean up data
200         configServicesRepository.deleteAll();
201
202         String content = readFileContent("src/test/resources/service1-serviceitem.json");
203
204         // Test with no data
205         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
206                 .andReturn();
207         assertEquals(201, mvcResult.getResponse().getStatus());
208         assertEquals(1, configServicesRepository.count());
209
210         // Test with existing data - should return 409
211         mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
212                 .andReturn();
213         assertEquals(409, mvcResult.getResponse().getStatus());
214         assertEquals(1, configServicesRepository.count());
215
216         // Clean up data
217         configServicesRepository.deleteAll();
218
219     }
220
221     @Test
222     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut() throws Exception {
223         // Clean up data
224         configServicesRepository.deleteAll();
225
226         String content = readFileContent("src/test/resources/service1-serviceitem.json");
227
228         // Test with no data
229         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
230                 .andReturn();
231         assertEquals(201, mvcResult.getResponse().getStatus());
232         assertEquals(1, configServicesRepository.count());
233
234         // Test with existing data - should return 409
235         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
236                 .andReturn();
237         assertEquals(204, mvcResult.getResponse().getStatus());
238         assertEquals(1, configServicesRepository.count());
239
240         // Clean up data
241         configServicesRepository.deleteAll();
242     }
243
244     @Test
245     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete() throws Exception {
246         // Clean up data
247         configServicesRepository.deleteAll();
248
249         // Test with no data
250         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
251                 .andReturn();
252         assertEquals(404, mvcResult.getResponse().getStatus());
253         assertEquals(0, configServicesRepository.count());
254
255         // Load data
256         loadServicesData("src/test/resources/service1.json");
257         assertEquals(1, configServicesRepository.count());
258
259         // Test with data
260         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
261                 .andReturn();
262         assertEquals(204, mvcResult.getResponse().getStatus());
263         assertEquals(1, configServicesRepository.count());
264         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId("service1");
265         assertEquals(1, services.size());
266         assertEquals(null, services.get(0).getSvcData());
267
268
269     }
270
271     @Test
272     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet() throws Exception {
273         // Clean up data
274         configServicesRepository.deleteAll();
275
276         // Test with data
277         loadServicesData("src/test/resources/service1.json");
278         assert(configServicesRepository.count() > 0);
279
280         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
281                 .andReturn();
282         assertEquals(200, mvcResult.getResponse().getStatus());
283
284         // Test with no data
285         configServicesRepository.deleteAll();
286         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
287                 .andReturn();
288         assertEquals(404, mvcResult.getResponse().getStatus());
289     }
290
291     @Test
292     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost() throws Exception {
293         // Clean up data
294         configServicesRepository.deleteAll();
295
296         String content = readFileContent("src/test/resources/service1-servicedata.json");
297
298         // Test with no data
299         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
300                 .andReturn();
301         assertEquals(404, mvcResult.getResponse().getStatus());
302         assertEquals(0, configServicesRepository.count());
303
304         // Test with empty service data
305         ConfigServices service = new ConfigServices();
306         service.setSvcInstanceId("service1");
307         configServicesRepository.save(service);
308         assertEquals(1, configServicesRepository.count());
309         mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
310                 .andReturn();
311         assertEquals(201, mvcResult.getResponse().getStatus());
312         assertEquals(1, configServicesRepository.count());
313         List<ConfigServices> updatedService = configServicesRepository.findBySvcInstanceId("service1");
314         assertEquals(1, updatedService.size());
315         assertNotEquals(null, updatedService.get(0).getSvcData());
316
317         // Test with existing data - should return 409
318         mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
319                 .andReturn();
320         assertEquals(409, mvcResult.getResponse().getStatus());
321
322         // Clean up data
323         configServicesRepository.deleteAll();
324     }
325
326     @Test
327     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut() throws Exception {
328         // Clean up data
329         configServicesRepository.deleteAll();
330
331         String content = readFileContent("src/test/resources/service1-servicedata.json");
332
333         // Test with no data
334         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
335                 .andReturn();
336         assertEquals(404, mvcResult.getResponse().getStatus());
337         assertEquals(0, configServicesRepository.count());
338
339         // Test with empty service data
340         ConfigServices service = new ConfigServices();
341         service.setSvcInstanceId("service1");
342         configServicesRepository.save(service);
343         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
344                 .andReturn();
345         assertEquals(201, mvcResult.getResponse().getStatus());
346         assertEquals(1, configServicesRepository.count());
347         List<ConfigServices> updatedService = configServicesRepository.findBySvcInstanceId("service1");
348         assertEquals(1, updatedService.size());
349         assertNotEquals(null, updatedService.get(0).getSvcData());
350
351         // Test with existing data - should return 204
352         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
353                 .andReturn();
354         assertEquals(204, mvcResult.getResponse().getStatus());
355
356         // Clean up data
357         configServicesRepository.deleteAll();
358     }
359
360     @Test
361     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete() throws Exception {
362         // Clean up data
363         configServicesRepository.deleteAll();
364
365         // Test with no data
366         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
367                 .andReturn();
368         assertEquals(404, mvcResult.getResponse().getStatus());
369         assertEquals(0, configServicesRepository.count());
370
371         // Load data
372         loadServicesData("src/test/resources/service1.json");
373         assertEquals(1, configServicesRepository.count());
374
375         // Test with data
376         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
377                 .andReturn();
378         assertEquals(204, mvcResult.getResponse().getStatus());
379         assertEquals(1, configServicesRepository.count());
380         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId("service1");
381         assertEquals(1, services.size());
382         assertEquals(null, services.get(0).getServiceStatus());
383     }
384
385     @Test
386     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet() throws Exception {
387         // Clean up data
388         configServicesRepository.deleteAll();
389
390         // Test with data
391         loadServicesData("src/test/resources/service1.json");
392         assert(configServicesRepository.count() > 0);
393
394         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
395                 .andReturn();
396         assertEquals(200, mvcResult.getResponse().getStatus());
397
398         // Test with no data
399         configServicesRepository.deleteAll();
400         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
401                 .andReturn();
402         assertEquals(404, mvcResult.getResponse().getStatus());
403     }
404
405     @Test
406     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost() throws Exception {
407         // Clean up data
408         configServicesRepository.deleteAll();
409
410         String content = readFileContent("src/test/resources/service1-servicestatus.json");
411
412         // Test with no data
413         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
414                 .andReturn();
415         assertEquals(404, mvcResult.getResponse().getStatus());
416         assertEquals(0, configServicesRepository.count());
417
418         // Test with empty service data
419         ConfigServices service = new ConfigServices();
420         service.setSvcInstanceId("service1");
421         configServicesRepository.save(service);
422         mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
423                 .andReturn();
424         assertEquals(201, mvcResult.getResponse().getStatus());
425         assertEquals(1, configServicesRepository.count());
426         List<ConfigServices> updatedService = configServicesRepository.findBySvcInstanceId("service1");
427         assertEquals(1, updatedService.size());
428         assertNotEquals(null, updatedService.get(0).getServiceStatus());
429
430         // Test with existing data - should return 409
431         mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
432                 .andReturn();
433         assertEquals(409, mvcResult.getResponse().getStatus());
434
435         // Clean up data
436         configServicesRepository.deleteAll();
437     }
438
439     @Test
440     public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut() throws Exception {
441         // Clean up data
442         configServicesRepository.deleteAll();
443
444         String content = readFileContent("src/test/resources/service1-servicestatus.json");
445
446         // Test with no data
447         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
448                 .andReturn();
449         assertEquals(404, mvcResult.getResponse().getStatus());
450         assertEquals(0, configServicesRepository.count());
451
452         // Test with empty service status
453         ConfigServices service = new ConfigServices();
454         service.setSvcInstanceId("service1");
455         configServicesRepository.save(service);
456         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
457                 .andReturn();
458         assertEquals(201, mvcResult.getResponse().getStatus());
459         assertEquals(1, configServicesRepository.count());
460         List<ConfigServices> updatedService = configServicesRepository.findBySvcInstanceId("service1");
461         assertEquals(1, updatedService.size());
462         assertNotEquals(null, updatedService.get(0).getServiceStatus());
463
464         // Test with existing data - should return 204
465         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
466                 .andReturn();
467         assertEquals(204, mvcResult.getResponse().getStatus());
468
469         // Clean up data
470         configServicesRepository.deleteAll();
471     }
472
473     @Test
474     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet() throws Exception {
475         // Clean up data
476         configServicesRepository.deleteAll();
477
478         // Test with data
479         loadServicesData("src/test/resources/service1.json");
480         assert(configServicesRepository.count() > 0);
481
482         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
483                 .andReturn();
484         assertEquals(200, mvcResult.getResponse().getStatus());
485
486         // Test with no data
487         configServicesRepository.deleteAll();
488         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
489                 .andReturn();
490         assertEquals(404, mvcResult.getResponse().getStatus());
491     }
492
493     @Test
494     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete() throws Exception {
495         // Clean up data
496         configServicesRepository.deleteAll();
497
498         // Test with no data
499         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
500                                       .andReturn();
501         assertEquals(404, mvcResult.getResponse().getStatus());
502         assertEquals(0, configServicesRepository.count());
503
504         // Load data
505         loadVnfData("src/test/resources/vnf-data.json");
506         assertEquals(1, configServicesRepository.count());
507
508         // Test with data
509         mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
510                             .andReturn();
511         assertEquals(204, mvcResult.getResponse().getStatus());
512         assertEquals(1, configServicesRepository.count());
513
514         configServicesRepository.deleteAll();
515         loadVnfData("src/test/resources/vnf-data.json");
516         assertEquals(1, configServicesRepository.count());
517         mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c/").contentType(MediaType.APPLICATION_JSON).content(""))
518                             .andReturn();
519         assertEquals(404, mvcResult.getResponse().getStatus());
520
521         configServicesRepository.deleteAll();
522         createBadVnfData(true, true);
523         assertEquals(1, configServicesRepository.count());
524         mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
525                             .andReturn();
526         assertEquals(404, mvcResult.getResponse().getStatus());
527
528         configServicesRepository.deleteAll();
529         createBadVnfData(false, false);
530         assertEquals(1, configServicesRepository.count());
531         mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
532                             .andReturn();
533         assertEquals(404, mvcResult.getResponse().getStatus());
534
535         configServicesRepository.deleteAll();
536         createBadVnfData(false, true);
537         assertEquals(1, configServicesRepository.count());
538         mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
539                             .andReturn();
540         assertEquals(404, mvcResult.getResponse().getStatus());
541     }
542
543     @Test
544     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet() throws Exception {
545         // Clean up data
546         configServicesRepository.deleteAll();
547
548         // Test with no data
549         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
550                                       .andReturn();
551         assertEquals(404, mvcResult.getResponse().getStatus());
552         assertEquals(0, configServicesRepository.count());
553
554         // Load data
555         loadVnfData("src/test/resources/vnf-data.json");
556         assertEquals(1, configServicesRepository.count());
557
558         // Test with data
559         mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
560                             .andReturn();
561         assertEquals(200, mvcResult.getResponse().getStatus());
562
563         configServicesRepository.deleteAll();
564         createBadVnfData(false, false);
565         assertEquals(1, configServicesRepository.count());
566         mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(""))
567                             .andReturn();
568         assertEquals(404, mvcResult.getResponse().getStatus());
569     }
570
571     @Test
572     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut() throws Exception {
573         // Clean up data
574         configServicesRepository.deleteAll();
575         assertEquals(0, configServicesRepository.count());
576         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-data.json")))
577                                       .andReturn();
578         assertEquals(201, mvcResult.getResponse().getStatus());
579         assertEquals(1, configServicesRepository.count());
580
581         mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-data.json")))
582                             .andReturn();
583         assertEquals(204, mvcResult.getResponse().getStatus());
584         assertEquals(1, configServicesRepository.count());
585     }
586
587     @Test
588     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet() throws Exception {
589         // Clean up data
590         configServicesRepository.deleteAll();
591
592         // Test with no data
593         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
594                                       .andReturn();
595         assertEquals(404, mvcResult.getResponse().getStatus());
596         assertEquals(0, configServicesRepository.count());
597
598         // Load data
599         loadVnfData("src/test/resources/vnf-data.json");
600         assertEquals(1, configServicesRepository.count());
601
602         // Test with data
603         mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
604                             .andReturn();
605         assertEquals(200, mvcResult.getResponse().getStatus());
606
607         configServicesRepository.deleteAll();
608         createBadVnfData(false, false);
609         assertEquals(1, configServicesRepository.count());
610         mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
611                             .andReturn();
612         assertEquals(404, mvcResult.getResponse().getStatus());
613     }
614
615     @Test
616     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut() throws Exception {
617         // Clean up data
618         configServicesRepository.deleteAll();
619         assertEquals(0, configServicesRepository.count());
620         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-level-oper-status/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-level-oper-status.json")))
621                                       .andReturn();
622         assertEquals(201, mvcResult.getResponse().getStatus());
623         assertEquals(1, configServicesRepository.count());
624
625         mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-level-oper-status/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-level-oper-status.json")))
626                             .andReturn();
627         assertEquals(204, mvcResult.getResponse().getStatus());
628         assertEquals(1, configServicesRepository.count());
629     }
630
631     @Test
632     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut() throws Exception {
633         // Clean up data
634         configServicesRepository.deleteAll();
635         assertEquals(0, configServicesRepository.count());
636         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/onap-model-information/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-onap-model-info.json")))
637                                       .andReturn();
638         assertEquals(201, mvcResult.getResponse().getStatus());
639         assertEquals(1, configServicesRepository.count());
640
641         mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/onap-model-information/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-onap-model-info.json")))
642                             .andReturn();
643         assertEquals(204, mvcResult.getResponse().getStatus());
644         assertEquals(1, configServicesRepository.count());
645     }
646
647     @Test
648     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut() throws Exception {
649         // Clean up data
650         configServicesRepository.deleteAll();
651         assertEquals(0, configServicesRepository.count());
652         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-vnf-networks.json")))
653                                       .andReturn();
654         assertEquals(201, mvcResult.getResponse().getStatus());
655         assertEquals(1, configServicesRepository.count());
656
657         mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-vnf-networks.json")))
658                             .andReturn();
659         assertEquals(204, mvcResult.getResponse().getStatus());
660         assertEquals(1, configServicesRepository.count());
661     }
662
663     @Test
664     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut() throws Exception {
665         // Clean up data
666         configServicesRepository.deleteAll();
667         assertEquals(0, configServicesRepository.count());
668         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/test-network-role/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-vnf-networks-network-role.json")))
669                                       .andReturn();
670         assertEquals(201, mvcResult.getResponse().getStatus());
671         assertEquals(1, configServicesRepository.count());
672
673         mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/test-network-role/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-vnf-networks-network-role.json")))
674                             .andReturn();
675         assertEquals(204, mvcResult.getResponse().getStatus());
676         assertEquals(1, configServicesRepository.count());
677     }
678
679     @Test
680     public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut() throws Exception {
681         // Clean up data
682         configPortMirrorConfigurationsRepository.deleteAll();
683
684         String content = readFileContent("src/test/resources/port-mirror-configuration-item.json");
685
686         // Test with no data
687         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-2/")
688                 .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn();
689         assertEquals(201, mvcResult.getResponse().getStatus());
690
691         // Test with existing port-mirror-configuration
692         // Load data
693         loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
694         assertEquals(2, configPortMirrorConfigurationsRepository.count());
695
696         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-2/")
697                 .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn();
698         assertEquals(204, mvcResult.getResponse().getStatus());
699         assertEquals(2, configPortMirrorConfigurationsRepository.count());
700
701         // Clean up data
702         configPortMirrorConfigurationsRepository.deleteAll();
703     }
704
705     @Test
706     public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete() throws Exception {
707         // Clean up data
708         configPortMirrorConfigurationsRepository.deleteAll();
709
710         // Test with no data
711         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
712                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
713
714         assertEquals(204, mvcResult.getResponse().getStatus());
715         assertEquals(0, configPortMirrorConfigurationsRepository.count());
716
717         // Load data
718         loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
719         assertEquals(1, configPortMirrorConfigurationsRepository.count());
720
721         // Test with data
722         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
723                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
724
725         assertEquals(204, mvcResult.getResponse().getStatus());
726         assertEquals(0, configPortMirrorConfigurationsRepository.count());
727     }
728
729     @Test
730     public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet() throws Exception {
731         // Clean up data
732         configPortMirrorConfigurationsRepository.deleteAll();
733
734         // Test with data
735         loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
736         assert(configPortMirrorConfigurationsRepository.count() > 0);
737
738         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
739                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
740         assertEquals(200, mvcResult.getResponse().getStatus());
741
742         // Test with bad allotted-resource-id in input
743         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"dummy/")
744                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
745
746         assertEquals(404, mvcResult.getResponse().getStatus());
747
748         // Test with no data
749         configPortMirrorConfigurationsRepository.deleteAll();
750         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
751                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
752
753         assertEquals(404, mvcResult.getResponse().getStatus());
754     }
755
756     @Test
757     public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet() throws Exception {
758         // Clean up data
759         configPortMirrorConfigurationsRepository.deleteAll();
760
761         // Test with data
762         loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
763         assert(configPortMirrorConfigurationsRepository.count() > 0);
764
765         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/configuration-data/port-mirror-configuration-topology/")
766                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
767         assertEquals(200, mvcResult.getResponse().getStatus());
768
769         // Test with dummy allotted-resource-id
770         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"dummy/configuration-data/port-mirror-configuration-topology/")
771                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
772         assertEquals(404, mvcResult.getResponse().getStatus());
773
774         // Test with no data
775         configPortMirrorConfigurationsRepository.deleteAll();
776         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/configuration-data/port-mirror-configuration-topology/")
777                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
778         assertEquals(404, mvcResult.getResponse().getStatus());
779     }
780
781     @Test
782     public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut() throws Exception {
783         // Clean up data
784         configContrailRouteAllottedResourcesRepository.deleteAll();
785
786         String content = readFileContent("src/test/resources/allotted-resource-item.json");
787
788         // Test with no data
789         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_CR_ARS_CR_AR_URL+"ar2/")
790                 .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn();
791         assertEquals(201, mvcResult.getResponse().getStatus());
792
793         // Test with existing allotted-resource
794         // Load data
795         configContrailRouteAllottedResourcesRepository.deleteAll();
796         loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
797         assertEquals(1, configContrailRouteAllottedResourcesRepository.count());
798
799         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_CR_ARS_CR_AR_URL+"ar2/")
800                 .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn();
801         assertEquals(201, mvcResult.getResponse().getStatus());
802         assertEquals(2, configContrailRouteAllottedResourcesRepository.count());
803
804         // Clean up data
805         configContrailRouteAllottedResourcesRepository.deleteAll();
806     }
807
808     @Test
809     public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete() throws Exception {
810         // Clean up data
811         configContrailRouteAllottedResourcesRepository.deleteAll();
812
813         // Test with no data
814         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
815                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
816
817         assertEquals(204, mvcResult.getResponse().getStatus());
818         assertEquals(0, configContrailRouteAllottedResourcesRepository.count());
819
820         // Load data
821         loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
822         assertEquals(1, configContrailRouteAllottedResourcesRepository.count());
823
824         // Test with data
825         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
826                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
827
828         assertEquals(204, mvcResult.getResponse().getStatus());
829         assertEquals(0, configContrailRouteAllottedResourcesRepository.count());
830     }
831
832     @Test
833     public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet() throws Exception {
834         // Clean up data
835         configContrailRouteAllottedResourcesRepository.deleteAll();
836
837         // Test with data
838         loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
839         assert(configContrailRouteAllottedResourcesRepository.count() > 0);
840
841         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
842                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
843         assertEquals(200, mvcResult.getResponse().getStatus());
844
845         // Test with bad allotted-resource-id in input
846         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"dummy/")
847                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
848
849         assertEquals(404, mvcResult.getResponse().getStatus());
850
851         // Test with no data
852         configContrailRouteAllottedResourcesRepository.deleteAll();
853         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
854                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
855
856         assertEquals(404, mvcResult.getResponse().getStatus());
857     }
858
859     @Test
860     public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet() throws Exception {
861         // Clean up data
862         configContrailRouteAllottedResourcesRepository.deleteAll();
863
864         // Test with data
865         loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
866         assert(configContrailRouteAllottedResourcesRepository.count() > 0);
867
868         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/allotted-resource-data/contrail-route-topology/")
869                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
870         assertEquals(200, mvcResult.getResponse().getStatus());
871
872         // Test with dummy allotted-resource-id
873         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"dummy/allotted-resource-data/contrail-route-topology/").contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
874         assertEquals(404, mvcResult.getResponse().getStatus());
875
876         // Test with no data
877         configContrailRouteAllottedResourcesRepository.deleteAll();
878         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/allotted-resource-data/contrail-route-topology/").contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
879         assertEquals(404, mvcResult.getResponse().getStatus());
880     }
881
882     @Test
883     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut() throws Exception {
884         // Clean up data
885         configServicesRepository.deleteAll();
886
887         String content = readFileContent("src/test/resources/service1-vfmodule-item.json");
888
889         // Test with no data
890         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/vf-1/")
891                 .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn();
892         assertEquals(400, mvcResult.getResponse().getStatus());
893
894         // Test with existing service and vnf
895         // Load data
896         loadServicesData("src/test/resources/service1.json");
897         assertEquals(1, configServicesRepository.count());
898
899         mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/vf-1/")
900                 .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn();
901         assertEquals(200, mvcResult.getResponse().getStatus());
902         assertEquals(1, configServicesRepository.count());
903
904         // Clean up data
905         configServicesRepository.deleteAll();
906     }
907
908     @Test
909     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete() throws Exception {
910         // Clean up data
911         configServicesRepository.deleteAll();
912
913         // Test with no data
914         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/")
915                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
916
917         assertEquals(400, mvcResult.getResponse().getStatus());
918         assertEquals(0, configServicesRepository.count());
919
920         // Load data
921         loadServicesData("src/test/resources/service1.json");
922         assertEquals(1, configServicesRepository.count());
923
924         // Test with data
925         mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/")
926                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
927
928         assertEquals(200, mvcResult.getResponse().getStatus());
929     }
930
931     @Test
932     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet() throws Exception {
933         // Clean up data
934         configServicesRepository.deleteAll();
935
936         // Test with data
937         loadServicesData("src/test/resources/service1.json");
938         assert(configServicesRepository.count() > 0);
939
940         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/")
941                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
942
943         assertEquals(200, mvcResult.getResponse().getStatus());
944
945         // Test with bad vf-module-id in input
946         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/dummyid/")
947                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
948
949         assertEquals(404, mvcResult.getResponse().getStatus());
950
951         // Test with no data
952         configServicesRepository.deleteAll();
953         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/")
954                 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
955
956         assertEquals(404, mvcResult.getResponse().getStatus());
957     }
958
959     @Test
960     public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet() throws Exception {
961         // Clean up data
962         configServicesRepository.deleteAll();
963
964         // Test with data
965         loadServicesData("src/test/resources/service1.json");
966         assert(configServicesRepository.count() > 0);
967
968         MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/vf-module-data/vf-module-topology/").contentType(MediaType.APPLICATION_JSON)
969                 .content("")).andReturn();
970         assertEquals(200, mvcResult.getResponse().getStatus());
971
972         // Test with existing service and vnf but with dummy vf-module-id in input
973         configServicesRepository.deleteAll();
974         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/dummy/vf-module-data/vf-module-topology/").contentType(MediaType.APPLICATION_JSON)
975                 .content("")).andReturn();
976         assertEquals(404, mvcResult.getResponse().getStatus());
977
978         // Test with no data
979         configServicesRepository.deleteAll();
980         mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/vf-module-data/vf-module-topology/").contentType(MediaType.APPLICATION_JSON)
981                 .content("")).andReturn();
982         assertEquals(404, mvcResult.getResponse().getStatus());
983     }
984
985     private String readFileContent(String path) throws IOException {
986         String content = new String(Files.readAllBytes(Paths.get(path)));
987         return content;
988     }
989
990     private void deleteData(String url) throws Exception {
991         mvc.perform(MockMvcRequestBuilders.delete(url).contentType(MediaType.APPLICATION_JSON).content(""))
992                 .andReturn();
993     }
994
995     private void loadServicesData(String path) throws IOException {
996         ObjectMapper objectMapper = new ObjectMapper();
997         String content = readFileContent(path);
998         GenericResourceApiServiceModelInfrastructure services = objectMapper.readValue(content, GenericResourceApiServiceModelInfrastructure.class);
999
1000         for (GenericResourceApiServicemodelinfrastructureService service : services.getService()) {
1001             ConfigServices newService = new ConfigServices();
1002             newService.setSvcInstanceId(service.getServiceInstanceId());
1003             newService.setSvcData(objectMapper.writeValueAsString(service.getServiceData()));
1004             newService.setServiceStatus(service.getServiceStatus());
1005             configServicesRepository.save(newService);
1006         }
1007     }
1008
1009     private void loadVnfData(String path) throws IOException {
1010         ObjectMapper objectMapper = new ObjectMapper();
1011         String content = readFileContent(path);
1012         GenericResourceApiServicedataServiceData svcData = new GenericResourceApiServicedataServiceData();
1013         GenericResourceApiServicedataServicedataVnfsVnf vnfData = objectMapper.readValue(content, GenericResourceApiServicedataServicedataVnfsVnf.class);
1014         svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1015         svcData.getVnfs().setVnf(new ArrayList<>());
1016         svcData.getVnfs().addVnfItem(vnfData);
1017         ConfigServices newService = new ConfigServices();
1018         newService.setSvcData(objectMapper.writeValueAsString(svcData));
1019         newService.setSvcInstanceId("test-siid");
1020         configServicesRepository.save(newService);
1021     }
1022
1023     private void createBadVnfData(boolean useNullSvc, boolean useNullVnfs) throws IOException {
1024         ObjectMapper objectMapper = new ObjectMapper();
1025         ConfigServices newService = new ConfigServices();
1026         GenericResourceApiServicedataServiceData svcData = useNullSvc ? null : new GenericResourceApiServicedataServiceData();
1027         GenericResourceApiServicedataServicedataVnfs vnfs = useNullVnfs ? null : new GenericResourceApiServicedataServicedataVnfs();
1028
1029         // Overrides useNullSvc
1030         if(!useNullVnfs) {
1031             svcData = new GenericResourceApiServicedataServiceData();
1032             vnfs.setVnf(new ArrayList<>());
1033             svcData.setVnfs(vnfs);
1034         }
1035
1036         newService.setSvcInstanceId("test-siid");
1037         newService.setSvcData(objectMapper.writeValueAsString(svcData));
1038         configServicesRepository.save(newService);
1039     }
1040
1041     private void loadContrailRouteAllottedResourceData(String path) throws IOException {
1042         ObjectMapper objectMapper = new ObjectMapper();
1043         String content = readFileContent(path);
1044         GenericResourceApiContrailRouteAllottedResources allottedResources = objectMapper.readValue(content, GenericResourceApiContrailRouteAllottedResources.class);
1045
1046         for (GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource allottedResource : allottedResources.getContrailRouteAllottedResource()) {
1047             ConfigContrailRouteAllottedResources newContrailRouteAllottedResource = new ConfigContrailRouteAllottedResources();
1048             newContrailRouteAllottedResource.setAllottedResourceId(allottedResource.getAllottedResourceId());
1049             newContrailRouteAllottedResource.setArData(objectMapper.writeValueAsString(allottedResource.getAllottedResourceData()));
1050             newContrailRouteAllottedResource.setAllottedResourceStatus(allottedResource.getAllottedResourceStatus());
1051             configContrailRouteAllottedResourcesRepository.save(newContrailRouteAllottedResource);
1052         }
1053     }
1054
1055     private void loadPortMirrorConfigurationData(String path) throws IOException {
1056         ObjectMapper objectMapper = new ObjectMapper();
1057         String content = readFileContent(path);
1058         GenericResourceApiPortMirrorConfigurations pmConfigurations = objectMapper.readValue(content, GenericResourceApiPortMirrorConfigurations.class);
1059
1060         for (GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration pmConfig : pmConfigurations.getPortMirrorConfiguration()) {
1061             ConfigPortMirrorConfigurations newPmConfig = new ConfigPortMirrorConfigurations();
1062             newPmConfig.setConfigureationId(pmConfig.getConfigurationId());
1063             newPmConfig.setPmcData(objectMapper.writeValueAsString(pmConfig.getConfigurationData()));
1064             newPmConfig.setPortMirrorConfigurationStatus(pmConfig.getConfigurationStatus());
1065             configPortMirrorConfigurationsRepository.save(newPmConfig);
1066         }
1067     }
1068
1069 }