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.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
11 import org.springframework.boot.test.context.SpringBootTest;
12 import org.springframework.http.MediaType;
13 import org.springframework.test.context.junit4.SpringRunner;
14 import org.springframework.test.web.servlet.MockMvc;
15 import org.springframework.test.web.servlet.MvcResult;
16 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
17 import org.springframework.transaction.annotation.Transactional;
19 import java.io.IOException;
20 import java.nio.file.Files;
21 import java.nio.file.Paths;
23 import static org.junit.Assert.*;
25 @RunWith(SpringRunner.class)
26 @SpringBootTest(classes={GenericResourceMsApp.class})
29 public class OperationsApiControllerTest {
31 private final static String PRELOAD_NETWORK_URL = "/operations/GENERIC-RESOURCE-API:preload-network-topology-operation/";
32 private final static String PRELOAD_VFMODULE_URL = "/operations/GENERIC-RESOURCE-API:preload-vf-module-topology-operation/";
39 ConfigPreloadDataRepository configPreloadDataRepository;
42 public static void setUp() throws Exception {
43 System.out.println("OperationsApiControllerTest: Setting serviceLogicProperties and serviceLogicDirectory");
44 System.setProperty("serviceLogicProperties", "src/test/resources/svclogic.properties");
45 System.setProperty("serviceLogicDirectory", "target/docker-stage/opt/onap/sdnc/svclogic/graphs/generic-resource-api");
50 public void operationsGENERICRESOURCEAPIpreloadNetworkTopologyOperationPost() throws Exception {
52 // Remove any existing preload data
53 configPreloadDataRepository.deleteAll();
55 // Add invalid content
56 String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
57 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
59 assertEquals(403, mvcResult.getResponse().getStatus());
60 assertEquals(0, configPreloadDataRepository.count());
63 content = readFileContent("src/test/resources/preload1-rpc-network.json");
64 mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
66 assertEquals(200, mvcResult.getResponse().getStatus());
67 assertEquals(1, configPreloadDataRepository.count());
72 public void operationsGENERICRESOURCEAPIpreloadVfModuleTopologyOperationPost() throws Exception {
73 // Remove any existing preload data
74 configPreloadDataRepository.deleteAll();
76 // Add invalid content
77 String content = readFileContent("src/test/resources/preload1-rpc-network.json");
78 MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
80 assertEquals(403, mvcResult.getResponse().getStatus());
81 assertEquals(0, configPreloadDataRepository.count());
84 content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
85 mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
87 assertEquals(200, mvcResult.getResponse().getStatus());
88 assertEquals(1, configPreloadDataRepository.count());
91 private String readFileContent(String path) throws IOException {
92 String content = new String(Files.readAllBytes(Paths.get(path)));