diff options
author | Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> | 2020-03-03 21:53:18 +0000 |
---|---|---|
committer | Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> | 2020-03-04 14:22:28 +0000 |
commit | 2ca6b604042735c56797a2eebd5472a6adaf44d4 (patch) | |
tree | 89bb129857c9b10c67b1257ae98f21dc9f0168b7 /sliapi/springboot/src/test | |
parent | ce993645564e2ba43c80fdc80a7265dc4032ceae (diff) |
update sliapi-springboot
organize sli api spring boot project
Issue-ID: CCSDK-2154
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: Ic1690b8addf0134220b49a01d04e41eaeabf7bb6
Diffstat (limited to 'sliapi/springboot/src/test')
-rw-r--r-- | sliapi/springboot/src/test/java/org/onap/ccsdk/sli/core/sliapi/springboot/RestconfApiControllerTest.java | 125 |
1 files changed, 66 insertions, 59 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 index 13f5939c5..e34d11877 100644 --- 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 @@ -1,7 +1,6 @@ package org.onap.ccsdk.sli.core.sliapi.springboot; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.ccsdk.sli.core.sliapi.model.ExecuteGraphInput; @@ -10,94 +9,102 @@ import org.onap.ccsdk.sli.core.sliapi.model.ResponseFields; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +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 static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(SpringRunner.class) -@WebMvcTest(RestconfApiController.class) +@SpringBootTest +@AutoConfigureMockMvc public class RestconfApiControllerTest { + private static final Logger log = LoggerFactory.getLogger(RestconfApiControllerTest.class); - private static final Logger log = LoggerFactory.getLogger(RestconfApiControllerTest.class); - - @Autowired - private MockMvc mvc; - + @Autowired + private MockMvc mvc; - @Test - public void testHealthcheck() throws Exception { - String url = "/restconf/operations/SLI-API:healthcheck"; + @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(); + MvcResult mvcResult = + mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content("")) + .andReturn(); - assertEquals(200, mvcResult.getResponse().getStatus()); - } + assertEquals(200, mvcResult.getResponse().getStatus()); + } - @Test - public void testVlbcheck() throws Exception { - String url = "/restconf/operations/SLI-API:vlbcheck"; + @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(); + MvcResult mvcResult = + mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content("")) + .andReturn(); - assertEquals(200, mvcResult.getResponse().getStatus()); - } + assertEquals(200, mvcResult.getResponse().getStatus()); + } - @Test - public void testExecuteHealthcheck() throws Exception { - String url = "/restconf/operations/SLI-API:execute-graph"; + @Test + public void testExecuteHealthcheck() throws Exception { + String url = "/restconf/operations/SLI-API:execute-graph"; - ExecuteGraphInput executeGraphInput = new ExecuteGraphInput(); - ExecutegraphinputInput executeGraphData = new ExecutegraphinputInput(); + ExecuteGraphInput executeGraphInput = new ExecuteGraphInput(); + ExecutegraphinputInput executeGraphData = new ExecutegraphinputInput(); - executeGraphData.setModuleName("sli"); - executeGraphData.setRpcName("healthcheck"); - executeGraphData.setMode("sync"); - executeGraphInput.setInput(executeGraphData); + executeGraphData.setModuleName("sli"); + executeGraphData.setRpcName("healthcheck"); + executeGraphData.setMode("sync"); + executeGraphInput.setInput(executeGraphData); - String jsonString = mapToJson(executeGraphInput); - log.error("jsonString is {}", jsonString); + String jsonString = mapToJson(executeGraphInput); + log.error("jsonString is {}", jsonString); - MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)).andReturn(); + MvcResult mvcResult = + mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)) + .andReturn(); - assertEquals(200, mvcResult.getResponse().getStatus()); + assertEquals(200, mvcResult.getResponse().getStatus()); - } + } - @Test - public void testExecuteMissingDg() throws Exception { - String url = "/restconf/operations/SLI-API:execute-graph"; + @Test + public void testExecuteMissingDg() throws Exception { + String url = "/restconf/operations/SLI-API:execute-graph"; - ExecuteGraphInput executeGraphInput = new ExecuteGraphInput(); - ExecutegraphinputInput executeGraphData = new ExecutegraphinputInput(); + ExecuteGraphInput executeGraphInput = new ExecuteGraphInput(); + ExecutegraphinputInput executeGraphData = new ExecutegraphinputInput(); - executeGraphData.setModuleName("sli"); - executeGraphData.setRpcName("noSuchRPC"); - executeGraphData.setMode("sync"); - executeGraphInput.setInput(executeGraphData); + executeGraphData.setModuleName("sli"); + executeGraphData.setRpcName("noSuchRPC"); + executeGraphData.setMode("sync"); + executeGraphInput.setInput(executeGraphData); - String jsonString = mapToJson(executeGraphInput); + String jsonString = mapToJson(executeGraphInput); - log.error("jsonString is {}", jsonString); + log.error("jsonString is {}", jsonString); - MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)).andReturn(); + MvcResult mvcResult = + mvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)) + .andReturn(); - assertEquals(401, mvcResult.getResponse().getStatus()); + assertEquals(401, mvcResult.getResponse().getStatus()); - } + } - private String mapToJson(Object obj) throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.writeValueAsString(obj); - } + 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)); - } + private ResponseFields respFromJson(String jsonString) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + return (objectMapper.readValue(jsonString, ResponseFields.class)); + } } |