1 package org.onap.sdnc.apps.ms.gra.controllers;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotEquals;
5 import static org.junit.Assert.assertNull;
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;
13 import com.fasterxml.jackson.databind.ObjectMapper;
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;
31 @RunWith(SpringRunner.class)
32 @SpringBootTest(classes={GenericResourceMsApp.class})
35 public class ConfigApiServicesControllerTest {
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/";
46 ConfigServicesRepository configServicesRepository;
49 ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
52 ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
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");
65 public void configGENERICRESOURCEAPIservicesDelete() throws Exception {
68 configServicesRepository.deleteAll();
71 loadServicesData( "src/test/resources/service1.json");
73 assertEquals(1, configServicesRepository.count());
74 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
76 assertEquals(204, mvcResult.getResponse().getStatus());
77 assertEquals(0, configServicesRepository.count());
80 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
82 assertEquals(204, mvcResult.getResponse().getStatus());
87 public void configGENERICRESOURCEAPIservicesGet() throws Exception {
89 configServicesRepository.deleteAll();
92 loadServicesData("src/test/resources/service1.json");
93 assert(configServicesRepository.count() > 0);
95 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
97 assertEquals(200, mvcResult.getResponse().getStatus());
100 configServicesRepository.deleteAll();
101 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
103 assertEquals(404, mvcResult.getResponse().getStatus());
107 public void configGENERICRESOURCEAPIservicesPost() throws Exception {
109 configServicesRepository.deleteAll();
111 String content = readFileContent("src/test/resources/service1.json");
114 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
116 assertEquals(201, mvcResult.getResponse().getStatus());
117 assertEquals(1, configServicesRepository.count());
119 // Test with existing data - should return 409
120 mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
122 assertEquals(409, mvcResult.getResponse().getStatus());
123 assertEquals(1, configServicesRepository.count());
126 configServicesRepository.deleteAll();
131 public void configGENERICRESOURCEAPIservicesPut() throws Exception {
133 configServicesRepository.deleteAll();
135 String content = readFileContent("src/test/resources/service1.json");
138 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
140 assertEquals(201, mvcResult.getResponse().getStatus());
141 assertEquals(1, configServicesRepository.count());
143 // Test with existing data - should return 409
144 mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
146 assertEquals(204, mvcResult.getResponse().getStatus());
147 assertEquals(1, configServicesRepository.count());
150 configServicesRepository.deleteAll();
155 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdDelete() throws Exception {
157 configServicesRepository.deleteAll();
160 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
162 assertEquals(204, mvcResult.getResponse().getStatus());
163 assertEquals(0, configServicesRepository.count());
166 loadServicesData("src/test/resources/service1.json");
167 assertEquals(1, configServicesRepository.count());
170 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
172 assertEquals(204, mvcResult.getResponse().getStatus());
173 assertEquals(0, configServicesRepository.count());
178 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet() throws Exception {
180 configServicesRepository.deleteAll();
183 loadServicesData("src/test/resources/service1.json");
184 assert(configServicesRepository.count() > 0);
186 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
188 assertEquals(200, mvcResult.getResponse().getStatus());
191 configServicesRepository.deleteAll();
192 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
194 assertEquals(404, mvcResult.getResponse().getStatus());
198 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost() throws Exception {
200 configServicesRepository.deleteAll();
202 String content = readFileContent("src/test/resources/service1-serviceitem.json");
205 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
207 assertEquals(201, mvcResult.getResponse().getStatus());
208 assertEquals(1, configServicesRepository.count());
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))
213 assertEquals(409, mvcResult.getResponse().getStatus());
214 assertEquals(1, configServicesRepository.count());
217 configServicesRepository.deleteAll();
222 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut() throws Exception {
224 configServicesRepository.deleteAll();
226 String content = readFileContent("src/test/resources/service1-serviceitem.json");
229 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
231 assertEquals(201, mvcResult.getResponse().getStatus());
232 assertEquals(1, configServicesRepository.count());
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))
237 assertEquals(204, mvcResult.getResponse().getStatus());
238 assertEquals(1, configServicesRepository.count());
241 configServicesRepository.deleteAll();
245 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete() throws Exception {
247 configServicesRepository.deleteAll();
250 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
252 assertEquals(404, mvcResult.getResponse().getStatus());
253 assertEquals(0, configServicesRepository.count());
256 loadServicesData("src/test/resources/service1.json");
257 assertEquals(1, configServicesRepository.count());
260 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
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());
272 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet() throws Exception {
274 configServicesRepository.deleteAll();
277 loadServicesData("src/test/resources/service1.json");
278 assert(configServicesRepository.count() > 0);
280 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
282 assertEquals(200, mvcResult.getResponse().getStatus());
285 configServicesRepository.deleteAll();
286 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
288 assertEquals(404, mvcResult.getResponse().getStatus());
292 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost() throws Exception {
294 configServicesRepository.deleteAll();
296 String content = readFileContent("src/test/resources/service1-servicedata.json");
299 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
301 assertEquals(404, mvcResult.getResponse().getStatus());
302 assertEquals(0, configServicesRepository.count());
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))
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());
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))
320 assertEquals(409, mvcResult.getResponse().getStatus());
323 configServicesRepository.deleteAll();
327 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut() throws Exception {
329 configServicesRepository.deleteAll();
331 String content = readFileContent("src/test/resources/service1-servicedata.json");
334 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
336 assertEquals(404, mvcResult.getResponse().getStatus());
337 assertEquals(0, configServicesRepository.count());
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))
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());
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))
354 assertEquals(204, mvcResult.getResponse().getStatus());
357 configServicesRepository.deleteAll();
361 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete() throws Exception {
363 configServicesRepository.deleteAll();
366 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
368 assertEquals(404, mvcResult.getResponse().getStatus());
369 assertEquals(0, configServicesRepository.count());
372 loadServicesData("src/test/resources/service1.json");
373 assertEquals(1, configServicesRepository.count());
376 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
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());
386 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet() throws Exception {
388 configServicesRepository.deleteAll();
391 loadServicesData("src/test/resources/service1.json");
392 assert(configServicesRepository.count() > 0);
394 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
396 assertEquals(200, mvcResult.getResponse().getStatus());
399 configServicesRepository.deleteAll();
400 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
402 assertEquals(404, mvcResult.getResponse().getStatus());
406 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost() throws Exception {
408 configServicesRepository.deleteAll();
410 String content = readFileContent("src/test/resources/service1-servicestatus.json");
413 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
415 assertEquals(404, mvcResult.getResponse().getStatus());
416 assertEquals(0, configServicesRepository.count());
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))
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());
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))
433 assertEquals(409, mvcResult.getResponse().getStatus());
436 configServicesRepository.deleteAll();
440 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut() throws Exception {
442 configServicesRepository.deleteAll();
444 String content = readFileContent("src/test/resources/service1-servicestatus.json");
447 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
449 assertEquals(404, mvcResult.getResponse().getStatus());
450 assertEquals(0, configServicesRepository.count());
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))
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());
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))
467 assertEquals(204, mvcResult.getResponse().getStatus());
470 configServicesRepository.deleteAll();
474 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet() throws Exception {
476 configServicesRepository.deleteAll();
479 loadServicesData("src/test/resources/service1.json");
480 assert(configServicesRepository.count() > 0);
482 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
484 assertEquals(200, mvcResult.getResponse().getStatus());
487 configServicesRepository.deleteAll();
488 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
490 assertEquals(404, mvcResult.getResponse().getStatus());
494 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete() throws Exception {
496 configServicesRepository.deleteAll();
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(""))
501 assertEquals(404, mvcResult.getResponse().getStatus());
502 assertEquals(0, configServicesRepository.count());
505 loadVnfData("src/test/resources/vnf-data.json");
506 assertEquals(1, configServicesRepository.count());
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(""))
511 assertEquals(204, mvcResult.getResponse().getStatus());
512 assertEquals(1, configServicesRepository.count());
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(""))
519 assertEquals(404, mvcResult.getResponse().getStatus());
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(""))
526 assertEquals(404, mvcResult.getResponse().getStatus());
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(""))
533 assertEquals(404, mvcResult.getResponse().getStatus());
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(""))
540 assertEquals(404, mvcResult.getResponse().getStatus());
544 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet() throws Exception {
546 configServicesRepository.deleteAll();
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(""))
551 assertEquals(404, mvcResult.getResponse().getStatus());
552 assertEquals(0, configServicesRepository.count());
555 loadVnfData("src/test/resources/vnf-data.json");
556 assertEquals(1, configServicesRepository.count());
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(""))
561 assertEquals(200, mvcResult.getResponse().getStatus());
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(""))
568 assertEquals(404, mvcResult.getResponse().getStatus());
572 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut() throws Exception {
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")))
578 assertEquals(201, mvcResult.getResponse().getStatus());
579 assertEquals(1, configServicesRepository.count());
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")))
583 assertEquals(204, mvcResult.getResponse().getStatus());
584 assertEquals(1, configServicesRepository.count());
588 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet() throws Exception {
590 configServicesRepository.deleteAll();
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(""))
595 assertEquals(404, mvcResult.getResponse().getStatus());
596 assertEquals(0, configServicesRepository.count());
599 loadVnfData("src/test/resources/vnf-data.json");
600 assertEquals(1, configServicesRepository.count());
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(""))
605 assertEquals(200, mvcResult.getResponse().getStatus());
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(""))
612 assertEquals(404, mvcResult.getResponse().getStatus());
616 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut() throws Exception {
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")))
622 assertEquals(201, mvcResult.getResponse().getStatus());
623 assertEquals(1, configServicesRepository.count());
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")))
627 assertEquals(204, mvcResult.getResponse().getStatus());
628 assertEquals(1, configServicesRepository.count());
632 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut() throws Exception {
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")))
638 assertEquals(201, mvcResult.getResponse().getStatus());
639 assertEquals(1, configServicesRepository.count());
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")))
643 assertEquals(204, mvcResult.getResponse().getStatus());
644 assertEquals(1, configServicesRepository.count());
648 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut() throws Exception {
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")))
654 assertEquals(201, mvcResult.getResponse().getStatus());
655 assertEquals(1, configServicesRepository.count());
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")))
659 assertEquals(204, mvcResult.getResponse().getStatus());
660 assertEquals(1, configServicesRepository.count());
664 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut() throws Exception {
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")))
670 assertEquals(201, mvcResult.getResponse().getStatus());
671 assertEquals(1, configServicesRepository.count());
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")))
675 assertEquals(204, mvcResult.getResponse().getStatus());
676 assertEquals(1, configServicesRepository.count());
680 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut() throws Exception {
682 configPortMirrorConfigurationsRepository.deleteAll();
684 String content = readFileContent("src/test/resources/port-mirror-configuration-item.json");
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());
691 // Test with existing port-mirror-configuration
693 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
694 assertEquals(2, configPortMirrorConfigurationsRepository.count());
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());
702 configPortMirrorConfigurationsRepository.deleteAll();
706 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete() throws Exception {
708 configPortMirrorConfigurationsRepository.deleteAll();
711 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
712 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
714 assertEquals(204, mvcResult.getResponse().getStatus());
715 assertEquals(0, configPortMirrorConfigurationsRepository.count());
718 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
719 assertEquals(1, configPortMirrorConfigurationsRepository.count());
722 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
723 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
725 assertEquals(204, mvcResult.getResponse().getStatus());
726 assertEquals(0, configPortMirrorConfigurationsRepository.count());
730 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet() throws Exception {
732 configPortMirrorConfigurationsRepository.deleteAll();
735 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
736 assert(configPortMirrorConfigurationsRepository.count() > 0);
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());
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();
746 assertEquals(404, mvcResult.getResponse().getStatus());
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();
753 assertEquals(404, mvcResult.getResponse().getStatus());
757 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet() throws Exception {
759 configPortMirrorConfigurationsRepository.deleteAll();
762 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
763 assert(configPortMirrorConfigurationsRepository.count() > 0);
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());
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());
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());
782 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut() throws Exception {
784 configContrailRouteAllottedResourcesRepository.deleteAll();
786 String content = readFileContent("src/test/resources/allotted-resource-item.json");
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());
793 // Test with existing allotted-resource
795 configContrailRouteAllottedResourcesRepository.deleteAll();
796 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
797 assertEquals(1, configContrailRouteAllottedResourcesRepository.count());
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());
805 configContrailRouteAllottedResourcesRepository.deleteAll();
809 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete() throws Exception {
811 configContrailRouteAllottedResourcesRepository.deleteAll();
814 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
815 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
817 assertEquals(204, mvcResult.getResponse().getStatus());
818 assertEquals(0, configContrailRouteAllottedResourcesRepository.count());
821 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
822 assertEquals(1, configContrailRouteAllottedResourcesRepository.count());
825 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
826 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
828 assertEquals(204, mvcResult.getResponse().getStatus());
829 assertEquals(0, configContrailRouteAllottedResourcesRepository.count());
833 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet() throws Exception {
835 configContrailRouteAllottedResourcesRepository.deleteAll();
838 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
839 assert(configContrailRouteAllottedResourcesRepository.count() > 0);
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());
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();
849 assertEquals(404, mvcResult.getResponse().getStatus());
852 configContrailRouteAllottedResourcesRepository.deleteAll();
853 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
854 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
856 assertEquals(404, mvcResult.getResponse().getStatus());
860 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet() throws Exception {
862 configContrailRouteAllottedResourcesRepository.deleteAll();
865 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
866 assert(configContrailRouteAllottedResourcesRepository.count() > 0);
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());
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());
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());
883 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut() throws Exception {
885 configServicesRepository.deleteAll();
887 String content = readFileContent("src/test/resources/service1-vfmodule-item.json");
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());
894 // Test with existing service and vnf
896 loadServicesData("src/test/resources/service1.json");
897 assertEquals(1, configServicesRepository.count());
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());
905 configServicesRepository.deleteAll();
909 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete() throws Exception {
911 configServicesRepository.deleteAll();
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();
917 assertEquals(400, mvcResult.getResponse().getStatus());
918 assertEquals(0, configServicesRepository.count());
921 loadServicesData("src/test/resources/service1.json");
922 assertEquals(1, configServicesRepository.count());
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();
928 assertEquals(200, mvcResult.getResponse().getStatus());
932 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet() throws Exception {
934 configServicesRepository.deleteAll();
937 loadServicesData("src/test/resources/service1.json");
938 assert(configServicesRepository.count() > 0);
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();
943 assertEquals(200, mvcResult.getResponse().getStatus());
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();
949 assertEquals(404, mvcResult.getResponse().getStatus());
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();
956 assertEquals(404, mvcResult.getResponse().getStatus());
960 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet() throws Exception {
962 configServicesRepository.deleteAll();
965 loadServicesData("src/test/resources/service1.json");
966 assert(configServicesRepository.count() > 0);
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());
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());
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());
985 private String readFileContent(String path) throws IOException {
986 String content = new String(Files.readAllBytes(Paths.get(path)));
990 private void deleteData(String url) throws Exception {
991 mvc.perform(MockMvcRequestBuilders.delete(url).contentType(MediaType.APPLICATION_JSON).content(""))
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);
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);
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);
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();
1029 // Overrides useNullSvc
1031 svcData = new GenericResourceApiServicedataServiceData();
1032 vnfs.setVnf(new ArrayList<>());
1033 svcData.setVnfs(vnfs);
1036 newService.setSvcInstanceId("test-siid");
1037 newService.setSvcData(objectMapper.writeValueAsString(svcData));
1038 configServicesRepository.save(newService);
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);
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);
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);
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);