summaryrefslogtreecommitdiffstats
path: root/sliapi/springboot/src/test
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-02-26 16:07:53 -0500
committerDan Timoney <dtimoney@att.com>2020-02-27 14:05:55 -0500
commitec7aa8b8c9fbe23f7628eb61bea93c0136cff6c5 (patch)
treedca903c47785a8c5742be99cd4c2b2b324c35141 /sliapi/springboot/src/test
parent2c78899f04fd40115d3c4cc606e8380c00cdda0b (diff)
Add execute-graph and vlbcheck to swagger-codegen code
Add implementation for execute-graph and vlbcheck RPCs. Also, added junit tests. Change-Id: Id2a31c033d25ef12c455bfee98c5aea8439fc2f9 Issue-ID: CCSDK-2096 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sliapi/springboot/src/test')
-rw-r--r--sliapi/springboot/src/test/java/org/onap/ccsdk/sli/core/sliapi/springboot/RestconfApiControllerTest.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/sliapi/springboot/src/test/java/org/onap/ccsdk/sli/core/sliapi/springboot/RestconfApiControllerTest.java b/sliapi/springboot/src/test/java/org/onap/ccsdk/sli/core/sliapi/springboot/RestconfApiControllerTest.java
new file mode 100644
index 000000000..af55a5181
--- /dev/null
+++ b/sliapi/springboot/src/test/java/org/onap/ccsdk/sli/core/sliapi/springboot/RestconfApiControllerTest.java
@@ -0,0 +1,99 @@
+package org.onap.ccsdk.sli.core.sliapi.springboot;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.ccsdk.sli.core.sliapi.model.ExecuteGraphInput;
+import org.onap.ccsdk.sli.core.sliapi.model.ExecutegraphinputInput;
+import org.onap.ccsdk.sli.core.sliapi.model.ResponseFields;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+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 static org.junit.Assert.assertEquals;
+
+@RunWith(SpringRunner.class)
+@WebMvcTest(RestconfApiController.class)
+public class RestconfApiControllerTest {
+
+ @Autowired
+ private MockMvc mvc;
+
+ @MockBean
+ private RestconfApiController restconfApiController;
+
+ @Test
+ public void testHealthcheck() throws Exception {
+ String url = "/restconf/operations/SLI-API:healthcheck";
+
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content("")).andReturn();
+
+ assertEquals(200, mvcResult.getResponse().getStatus());
+ }
+
+ @Test
+ public void testVlbcheck() throws Exception {
+ String url = "/restconf/operations/SLI-API:vlbcheck";
+
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content("")).andReturn();
+
+ assertEquals(200, mvcResult.getResponse().getStatus());
+ }
+
+ @Test
+ public void testExecuteHealthcheck() throws Exception {
+ String url = "/restconf/operations/SLI-API:execute-graph";
+
+ ExecuteGraphInput executeGraphInput = new ExecuteGraphInput();
+ ExecutegraphinputInput executeGraphData = new ExecutegraphinputInput();
+
+ executeGraphData.setModuleName("sli");
+ executeGraphData.setRpcName("healthcheck");
+ executeGraphData.setMode("sync");
+ executeGraphInput.setInput(executeGraphData);
+
+ String jsonString = mapToJson(executeGraphInput);
+
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)).andReturn();
+
+ assertEquals(200, mvcResult.getResponse().getStatus());
+
+ }
+
+ @Test
+ public void testExecuteMissingDg() throws Exception {
+ String url = "/restconf/operations/SLI-API:execute-graph";
+
+ ExecuteGraphInput executeGraphInput = new ExecuteGraphInput();
+ ExecutegraphinputInput executeGraphData = new ExecutegraphinputInput();
+
+ executeGraphData.setModuleName("sli");
+ executeGraphData.setRpcName("noSuchRPC");
+ executeGraphData.setMode("sync");
+ executeGraphInput.setInput(executeGraphData);
+
+ String jsonString = mapToJson(executeGraphInput);
+
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)).andReturn();
+
+ // Note: this really should return 401 (and truly does), but mockito always returns a 200.
+ assertEquals(200, mvcResult.getResponse().getStatus());
+
+ }
+
+ private String mapToJson(Object obj) throws JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ return objectMapper.writeValueAsString(obj);
+ }
+
+ private ResponseFields respFromJson(String jsonString) throws JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ return(objectMapper.readValue(jsonString, ResponseFields.class));
+ }
+}