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