1 package org.onap.sdnc.apps.ms.gra.controllers;
3 import org.junit.BeforeClass;
5 import org.junit.runner.RunWith;
6 import org.onap.sdnc.apps.ms.gra.core.GenericResourceMsApp;
7 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
8 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
9 import org.onap.sdnc.apps.ms.gra.data.OperationalServicesRepository;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
12 import org.springframework.boot.test.context.SpringBootTest;
13 import org.springframework.http.MediaType;
14 import org.springframework.test.context.junit4.SpringRunner;
15 import org.springframework.test.web.servlet.MockMvc;
16 import org.springframework.test.web.servlet.MvcResult;
17 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
18 import org.springframework.transaction.annotation.Transactional;
20 import java.io.IOException;
21 import java.nio.file.Files;
22 import java.nio.file.Paths;
24 import static org.junit.Assert.*;
26 @RunWith(SpringRunner.class)
27 @SpringBootTest(classes={GenericResourceMsApp.class})
30 public class OperationsApiControllerTest {
32 private final static String PRELOAD_NETWORK_URL = "/operations/GENERIC-RESOURCE-API:preload-network-topology-operation/";
33 private final static String PRELOAD_VFMODULE_URL = "/operations/GENERIC-RESOURCE-API:preload-vf-module-topology-operation/";
34 private final static String SERVICE_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:service-topology-operation/";
41 ConfigPreloadDataRepository configPreloadDataRepository;
44 ConfigServicesRepository configServicesRepository;
47 OperationalServicesRepository operationalServicesRepository;
50 public static void setUp() throws Exception {
51 System.out.println("OperationsApiControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir");
52 System.setProperty("serviceLogicProperties", "src/test/resources/svclogic.properties");
53 System.setProperty("serviceLogicDirectory", "src/test/resources/svclogic");
54 System.setProperty("sdnc.config.dir", "src/test/resources");
60 public void operationsGENERICRESOURCEAPIpreloadNetworkTopologyOperationPost() throws Exception {
62 // Remove any existing preload data
63 configPreloadDataRepository.deleteAll();
65 // Add invalid content
66 String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
67 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
69 assertEquals(403, mvcResult.getResponse().getStatus());
70 assertEquals(0, configPreloadDataRepository.count());
73 content = readFileContent("src/test/resources/preload1-rpc-network.json");
74 mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
76 assertEquals(200, mvcResult.getResponse().getStatus());
77 assertEquals(1, configPreloadDataRepository.count());
82 public void operationsGENERICRESOURCEAPIpreloadVfModuleTopologyOperationPost() throws Exception {
83 // Remove any existing preload data
84 configPreloadDataRepository.deleteAll();
86 // Add invalid content
87 String content = readFileContent("src/test/resources/preload1-rpc-network.json");
88 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
90 assertEquals(403, mvcResult.getResponse().getStatus());
91 assertEquals(0, configPreloadDataRepository.count());
94 content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
95 mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
97 assertEquals(200, mvcResult.getResponse().getStatus());
98 assertEquals(1, configPreloadDataRepository.count());
102 public void operationsGENERICRESOURCEAPIserviceTopologyOperationAssignPost() throws Exception {
104 // Remove any existing service data
105 configServicesRepository.deleteAll();
106 operationalServicesRepository.deleteAll();
108 // Add invalid content
109 String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
110 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(SERVICE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
112 assertEquals(200, mvcResult.getResponse().getStatus());
113 assertEquals(0, configServicesRepository.count());
114 assertEquals(0, operationalServicesRepository.count());
117 content = readFileContent("src/test/resources/service-assign-rpc.json");
118 mvcResult = mvc.perform(MockMvcRequestBuilders.post(SERVICE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
120 assertEquals(200, mvcResult.getResponse().getStatus());
121 assertEquals(1, configServicesRepository.count());
122 assertEquals(1, operationalServicesRepository.count());
126 private String readFileContent(String path) throws IOException {
127 String content = new String(Files.readAllBytes(Paths.get(path)));