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 ConfigNetworksRepository configNetworksRepository;
52 ConfigVnfsRepository configVnfsRepository;
55 ConfigVfModulesRepository configVfModulesRepository;
58 ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
61 ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
64 ServiceDataHelper serviceDataHelper;
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");
77 public void configGENERICRESOURCEAPIservicesDelete() throws Exception {
83 loadServicesData( "src/test/resources/service1.json");
85 assertEquals(1, configServicesRepository.count());
86 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
88 assertEquals(204, mvcResult.getResponse().getStatus());
89 assertEquals(0, configServicesRepository.count());
92 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
94 assertEquals(204, mvcResult.getResponse().getStatus());
99 public void configGENERICRESOURCEAPIservicesGet() throws Exception {
104 loadServicesData("src/test/resources/service1.json");
105 assert(configServicesRepository.count() > 0);
107 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
109 assertEquals(200, mvcResult.getResponse().getStatus());
113 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(""))
115 assertEquals(404, mvcResult.getResponse().getStatus());
119 public void configGENERICRESOURCEAPIservicesPost() throws Exception {
123 String content = readFileContent("src/test/resources/service1.json");
126 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
128 assertEquals(201, mvcResult.getResponse().getStatus());
129 assertEquals(1, configServicesRepository.count());
131 // Test with existing data - should return 409
132 mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
134 assertEquals(409, mvcResult.getResponse().getStatus());
135 assertEquals(1, configServicesRepository.count());
143 public void configGENERICRESOURCEAPIservicesPut() throws Exception {
147 String content = readFileContent("src/test/resources/service1.json");
150 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
152 assertEquals(201, mvcResult.getResponse().getStatus());
153 assertEquals(1, configServicesRepository.count());
155 // Test with existing data - should return 409
156 mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content(content))
158 assertEquals(204, mvcResult.getResponse().getStatus());
159 assertEquals(1, configServicesRepository.count());
167 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdDelete() throws Exception {
172 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
174 assertEquals(204, mvcResult.getResponse().getStatus());
175 assertEquals(0, configServicesRepository.count());
178 loadServicesData("src/test/resources/service1.json");
179 assertEquals(1, configServicesRepository.count());
182 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
184 assertEquals(204, mvcResult.getResponse().getStatus());
185 assertEquals(0, configServicesRepository.count());
190 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet() throws Exception {
195 loadServicesData("src/test/resources/service1.json");
196 assert(configServicesRepository.count() > 0);
198 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
200 assertEquals(200, mvcResult.getResponse().getStatus());
204 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(""))
206 assertEquals(404, mvcResult.getResponse().getStatus());
210 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost() throws Exception {
214 String content = readFileContent("src/test/resources/service1-serviceitem.json");
217 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
219 assertEquals(201, mvcResult.getResponse().getStatus());
220 assertEquals(1, configServicesRepository.count());
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))
225 assertEquals(409, mvcResult.getResponse().getStatus());
226 assertEquals(1, configServicesRepository.count());
234 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut() throws Exception {
238 String content = readFileContent("src/test/resources/service1-serviceitem.json");
241 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content(content))
243 assertEquals(201, mvcResult.getResponse().getStatus());
244 assertEquals(1, configServicesRepository.count());
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))
249 assertEquals(204, mvcResult.getResponse().getStatus());
250 assertEquals(1, configServicesRepository.count());
257 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete() throws Exception {
262 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
264 assertEquals(404, mvcResult.getResponse().getStatus());
265 assertEquals(0, configServicesRepository.count());
268 loadServicesData("src/test/resources/service1.json");
269 assertEquals(1, configServicesRepository.count());
272 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
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());
284 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet() throws Exception {
289 loadServicesData("src/test/resources/service1.json");
290 assert(configServicesRepository.count() > 0);
292 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
294 assertEquals(200, mvcResult.getResponse().getStatus());
298 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(""))
300 assertEquals(404, mvcResult.getResponse().getStatus());
304 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost() throws Exception {
308 String content = readFileContent("src/test/resources/service1-servicedata.json");
311 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
313 assertEquals(404, mvcResult.getResponse().getStatus());
314 assertEquals(0, configServicesRepository.count());
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))
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());
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))
332 assertEquals(409, mvcResult.getResponse().getStatus());
339 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut() throws Exception {
343 String content = readFileContent("src/test/resources/service1-servicedata.json");
346 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content(content))
348 assertEquals(404, mvcResult.getResponse().getStatus());
349 assertEquals(0, configServicesRepository.count());
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))
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());
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))
366 assertEquals(204, mvcResult.getResponse().getStatus());
373 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete() throws Exception {
378 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
380 assertEquals(404, mvcResult.getResponse().getStatus());
381 assertEquals(0, configServicesRepository.count());
384 loadServicesData("src/test/resources/service1.json");
385 assertEquals(1, configServicesRepository.count());
388 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
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());
398 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet() throws Exception {
403 loadServicesData("src/test/resources/service1.json");
404 assert(configServicesRepository.count() > 0);
406 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
408 assertEquals(200, mvcResult.getResponse().getStatus());
412 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(""))
414 assertEquals(404, mvcResult.getResponse().getStatus());
418 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost() throws Exception {
422 String content = readFileContent("src/test/resources/service1-servicestatus.json");
425 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
427 assertEquals(404, mvcResult.getResponse().getStatus());
428 assertEquals(0, configServicesRepository.count());
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))
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());
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))
445 assertEquals(409, mvcResult.getResponse().getStatus());
452 public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut() throws Exception {
456 String content = readFileContent("src/test/resources/service1-servicestatus.json");
459 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content(content))
461 assertEquals(404, mvcResult.getResponse().getStatus());
462 assertEquals(0, configServicesRepository.count());
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))
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());
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))
479 assertEquals(204, mvcResult.getResponse().getStatus());
486 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet() throws Exception {
491 loadServicesData("src/test/resources/service1.json");
492 assert(configServicesRepository.count() > 0);
494 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
496 assertEquals(200, mvcResult.getResponse().getStatus());
500 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content(""))
502 assertEquals(404, mvcResult.getResponse().getStatus());
506 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete() throws Exception {
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(""))
513 assertEquals(404, mvcResult.getResponse().getStatus());
514 assertEquals(0, configServicesRepository.count());
517 loadVnfData("src/test/resources/vnf-data.json");
518 assertEquals(1, configServicesRepository.count());
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(""))
523 assertEquals(204, mvcResult.getResponse().getStatus());
524 assertEquals(1, configServicesRepository.count());
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(""))
531 assertEquals(404, mvcResult.getResponse().getStatus());
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(""))
538 assertEquals(404, mvcResult.getResponse().getStatus());
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(""))
545 assertEquals(404, mvcResult.getResponse().getStatus());
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(""))
552 assertEquals(404, mvcResult.getResponse().getStatus());
556 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet() throws Exception {
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(""))
563 assertEquals(404, mvcResult.getResponse().getStatus());
564 assertEquals(0, configServicesRepository.count());
567 loadVnfData("src/test/resources/vnf-data.json");
568 assertEquals(1, configServicesRepository.count());
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(""))
573 assertEquals(200, mvcResult.getResponse().getStatus());
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(""))
580 assertEquals(404, mvcResult.getResponse().getStatus());
584 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut() throws Exception {
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")))
590 assertEquals(201, mvcResult.getResponse().getStatus());
591 assertEquals(1, configServicesRepository.count());
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")))
595 assertEquals(204, mvcResult.getResponse().getStatus());
596 assertEquals(1, configServicesRepository.count());
600 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet() throws Exception {
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(""))
607 assertEquals(404, mvcResult.getResponse().getStatus());
608 assertEquals(0, configServicesRepository.count());
611 loadVnfData("src/test/resources/vnf-data.json");
612 assertEquals(1, configServicesRepository.count());
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(""))
617 assertEquals(200, mvcResult.getResponse().getStatus());
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(""))
624 assertEquals(404, mvcResult.getResponse().getStatus());
628 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut() throws Exception {
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")))
634 assertEquals(201, mvcResult.getResponse().getStatus());
635 assertEquals(1, configServicesRepository.count());
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")))
639 assertEquals(204, mvcResult.getResponse().getStatus());
640 assertEquals(1, configServicesRepository.count());
644 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut() throws Exception {
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")))
650 assertEquals(201, mvcResult.getResponse().getStatus());
651 assertEquals(1, configServicesRepository.count());
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")))
655 assertEquals(204, mvcResult.getResponse().getStatus());
656 assertEquals(1, configServicesRepository.count());
660 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut() throws Exception {
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")))
666 assertEquals(201, mvcResult.getResponse().getStatus());
667 assertEquals(1, configServicesRepository.count());
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")))
671 assertEquals(204, mvcResult.getResponse().getStatus());
672 assertEquals(1, configServicesRepository.count());
676 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut() throws Exception {
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")))
682 assertEquals(201, mvcResult.getResponse().getStatus());
683 assertEquals(1, configServicesRepository.count());
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")))
687 assertEquals(204, mvcResult.getResponse().getStatus());
688 assertEquals(1, configServicesRepository.count());
692 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut() throws Exception {
694 configPortMirrorConfigurationsRepository.deleteAll();
696 String content = readFileContent("src/test/resources/port-mirror-configuration-item.json");
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());
703 // Test with existing port-mirror-configuration
705 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
706 assertEquals(2, configPortMirrorConfigurationsRepository.count());
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());
714 configPortMirrorConfigurationsRepository.deleteAll();
718 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete() throws Exception {
720 configPortMirrorConfigurationsRepository.deleteAll();
723 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
724 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
726 assertEquals(204, mvcResult.getResponse().getStatus());
727 assertEquals(0, configPortMirrorConfigurationsRepository.count());
730 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
731 assertEquals(1, configPortMirrorConfigurationsRepository.count());
734 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/")
735 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
737 assertEquals(204, mvcResult.getResponse().getStatus());
738 assertEquals(0, configPortMirrorConfigurationsRepository.count());
742 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet() throws Exception {
744 configPortMirrorConfigurationsRepository.deleteAll();
747 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
748 assert(configPortMirrorConfigurationsRepository.count() > 0);
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());
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();
758 assertEquals(404, mvcResult.getResponse().getStatus());
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();
765 assertEquals(404, mvcResult.getResponse().getStatus());
769 public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet() throws Exception {
771 configPortMirrorConfigurationsRepository.deleteAll();
774 loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
775 assert(configPortMirrorConfigurationsRepository.count() > 0);
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());
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());
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());
794 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut() throws Exception {
796 configContrailRouteAllottedResourcesRepository.deleteAll();
798 String content = readFileContent("src/test/resources/allotted-resource-item.json");
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());
805 // Test with existing allotted-resource
807 configContrailRouteAllottedResourcesRepository.deleteAll();
808 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
809 assertEquals(1, configContrailRouteAllottedResourcesRepository.count());
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());
817 configContrailRouteAllottedResourcesRepository.deleteAll();
821 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete() throws Exception {
823 configContrailRouteAllottedResourcesRepository.deleteAll();
826 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
827 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
829 assertEquals(204, mvcResult.getResponse().getStatus());
830 assertEquals(0, configContrailRouteAllottedResourcesRepository.count());
833 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
834 assertEquals(1, configContrailRouteAllottedResourcesRepository.count());
837 mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
838 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
840 assertEquals(204, mvcResult.getResponse().getStatus());
841 assertEquals(0, configContrailRouteAllottedResourcesRepository.count());
845 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet() throws Exception {
847 configContrailRouteAllottedResourcesRepository.deleteAll();
850 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
851 assert(configContrailRouteAllottedResourcesRepository.count() > 0);
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());
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();
861 assertEquals(404, mvcResult.getResponse().getStatus());
864 configContrailRouteAllottedResourcesRepository.deleteAll();
865 mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/")
866 .contentType(MediaType.APPLICATION_JSON).content("")).andReturn();
868 assertEquals(404, mvcResult.getResponse().getStatus());
872 public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet() throws Exception {
874 configContrailRouteAllottedResourcesRepository.deleteAll();
877 loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json");
878 assert(configContrailRouteAllottedResourcesRepository.count() > 0);
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());
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());
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());
895 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut() throws Exception {
899 String content = readFileContent("src/test/resources/service1-vfmodule-item.json");
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());
906 // Test with existing service and vnf
908 loadServicesData("src/test/resources/service1.json");
909 assertEquals(1, configServicesRepository.count());
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());
921 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete() throws Exception {
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();
929 assertEquals(400, mvcResult.getResponse().getStatus());
930 assertEquals(0, configServicesRepository.count());
933 loadServicesData("src/test/resources/service1.json");
934 assertEquals(1, configServicesRepository.count());
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();
940 assertEquals(200, mvcResult.getResponse().getStatus());
944 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet() throws Exception {
949 loadServicesData("src/test/resources/service1.json");
950 assert(configServicesRepository.count() > 0);
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();
955 assertEquals(200, mvcResult.getResponse().getStatus());
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();
961 assertEquals(404, mvcResult.getResponse().getStatus());
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();
968 assertEquals(404, mvcResult.getResponse().getStatus());
972 public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet() throws Exception {
977 loadServicesData("src/test/resources/service1.json");
978 assert(configServicesRepository.count() > 0);
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());
984 // Test with existing service and vnf but with dummy vf-module-id in input
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());
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());
997 private String readFileContent(String path) throws IOException {
998 String content = new String(Files.readAllBytes(Paths.get(path)));
1002 private void deleteData(String url) throws Exception {
1003 mvc.perform(MockMvcRequestBuilders.delete(url).contentType(MediaType.APPLICATION_JSON).content(""))
1007 private void clearServicesData() {
1008 configServicesRepository.deleteAll();
1009 configNetworksRepository.deleteAll();
1010 configVnfsRepository.deleteAll();
1011 configVfModulesRepository.deleteAll();
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);
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());
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);
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();
1043 // Overrides useNullSvc
1045 svcData = new GenericResourceApiServicedataServiceData();
1046 vnfs.setVnf(new ArrayList<>());
1047 svcData.setVnfs(vnfs);
1050 newService.setSvcInstanceId("test-siid");
1051 newService.setSvcData(objectMapper.writeValueAsString(svcData));
1052 configServicesRepository.save(newService);
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);
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);
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);
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);