1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package org.onap.sdnc.apps.ms.gra.controllers;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.sdnc.apps.ms.gra.core.GenericResourceMsApp;
import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
import org.onap.sdnc.apps.ms.gra.data.OperationalServicesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest(classes={GenericResourceMsApp.class})
@AutoConfigureMockMvc
@Transactional
public class OperationsApiControllerTest {
private final static String PRELOAD_NETWORK_URL = "/operations/GENERIC-RESOURCE-API:preload-network-topology-operation/";
private final static String PRELOAD_VFMODULE_URL = "/operations/GENERIC-RESOURCE-API:preload-vf-module-topology-operation/";
private final static String SERVICE_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:service-topology-operation/";
@Autowired
private MockMvc mvc;
@Autowired
ConfigPreloadDataRepository configPreloadDataRepository;
@Autowired
ConfigServicesRepository configServicesRepository;
@Autowired
OperationalServicesRepository operationalServicesRepository;
@BeforeClass
public static void setUp() throws Exception {
System.out.println("OperationsApiControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir");
System.setProperty("serviceLogicProperties", "src/test/resources/svclogic.properties");
System.setProperty("serviceLogicDirectory", "src/test/resources/svclogic");
System.setProperty("sdnc.config.dir", "src/test/resources");
}
@Test
public void operationsGENERICRESOURCEAPIpreloadNetworkTopologyOperationPost() throws Exception {
// Remove any existing preload data
configPreloadDataRepository.deleteAll();
// Add invalid content
String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
.andReturn();
assertEquals(403, mvcResult.getResponse().getStatus());
assertEquals(0, configPreloadDataRepository.count());
// Add valid content
content = readFileContent("src/test/resources/preload1-rpc-network.json");
mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
.andReturn();
assertEquals(200, mvcResult.getResponse().getStatus());
assertEquals(1, configPreloadDataRepository.count());
}
@Test
public void operationsGENERICRESOURCEAPIpreloadVfModuleTopologyOperationPost() throws Exception {
// Remove any existing preload data
configPreloadDataRepository.deleteAll();
// Add invalid content
String content = readFileContent("src/test/resources/preload1-rpc-network.json");
MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
.andReturn();
assertEquals(403, mvcResult.getResponse().getStatus());
assertEquals(0, configPreloadDataRepository.count());
// Add valid content
content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
.andReturn();
assertEquals(200, mvcResult.getResponse().getStatus());
assertEquals(1, configPreloadDataRepository.count());
}
@Test
public void operationsGENERICRESOURCEAPIserviceTopologyOperationAssignPost() throws Exception {
// Remove any existing service data
configServicesRepository.deleteAll();
operationalServicesRepository.deleteAll();
// Add invalid content
String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(SERVICE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
.andReturn();
assertEquals(200, mvcResult.getResponse().getStatus());
assertEquals(0, configServicesRepository.count());
assertEquals(0, operationalServicesRepository.count());
// Add valid content
content = readFileContent("src/test/resources/service-assign-rpc.json");
mvcResult = mvc.perform(MockMvcRequestBuilders.post(SERVICE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
.andReturn();
assertEquals(200, mvcResult.getResponse().getStatus());
assertEquals(1, configServicesRepository.count());
assertEquals(1, operationalServicesRepository.count());
}
private String readFileContent(String path) throws IOException {
String content = new String(Files.readAllBytes(Paths.get(path)));
return content;
}
}
|