From 3549f3d36ed95437939cbe3f626563bf99d02095 Mon Sep 17 00:00:00 2001 From: ParkSeongMin Date: Mon, 2 Nov 2015 01:25:16 +0000 Subject: [PATCH] =?UTF-8?q?test=20case=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + .../resolve/NexacroDataResolveTest.java | 307 ++++++++++++++++++ .../resolve/NexacroExceptionResolveTest.java | 165 ++++++++++ ...roHandlerMethodReturnValueHandlerTest.java | 59 ++++ .../spring/resolve/TestController.java | 173 ++++++++++ .../nexacro/spring/resolve/httpRequest.xml | 53 +++ .../nexacro/spring/resolve/httpResponse.xml | 52 +++ .../spring/resolve/httpResponseMap.xml | 52 +++ .../spring/resolve/httpResponseVariable.xml | 8 + .../servicelayout/RequestMappingView.java | 16 +- .../spring/view/NexacroFileViewTest.java | 5 + .../nexacro/spring/view/NexacroViewTest.java | 53 +++ src/test/resources/log4j2.xml | 4 + src/test/resources/spring/context-servlet.xml | 110 +++++++ 14 files changed, 1049 insertions(+), 9 deletions(-) create mode 100644 src/test/java/com/nexacro/spring/resolve/NexacroDataResolveTest.java create mode 100644 src/test/java/com/nexacro/spring/resolve/NexacroExceptionResolveTest.java create mode 100644 src/test/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandlerTest.java create mode 100644 src/test/java/com/nexacro/spring/resolve/TestController.java create mode 100644 src/test/java/com/nexacro/spring/resolve/httpRequest.xml create mode 100644 src/test/java/com/nexacro/spring/resolve/httpResponse.xml create mode 100644 src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml create mode 100644 src/test/java/com/nexacro/spring/resolve/httpResponseVariable.xml create mode 100644 src/test/java/com/nexacro/spring/view/NexacroFileViewTest.java create mode 100644 src/test/java/com/nexacro/spring/view/NexacroViewTest.java create mode 100644 src/test/resources/spring/context-servlet.xml diff --git a/pom.xml b/pom.xml index 96b2c77..08a77d3 100644 --- a/pom.xml +++ b/pom.xml @@ -127,6 +127,7 @@ 1.6 + javax.servlet javax.servlet-api diff --git a/src/test/java/com/nexacro/spring/resolve/NexacroDataResolveTest.java b/src/test/java/com/nexacro/spring/resolve/NexacroDataResolveTest.java new file mode 100644 index 0000000..3216a57 --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/NexacroDataResolveTest.java @@ -0,0 +1,307 @@ +package com.nexacro.spring.resolve; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import junit.framework.Assert; + +import org.apache.commons.io.IOUtils; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultHandler; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.View; + +import com.nexacro.spring.NexacroConstants; +import com.nexacro.spring.servlet.NexacroInterceptor; +import com.nexacro.spring.view.NexacroView; +import com.nexacro.xapi.data.PlatformData; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(locations = { "classpath*:spring/context-servlet.xml" } ) +public class NexacroDataResolveTest { + + /* +new test method. + +MockMvcBuilders.standaloneMvcSetup( + new TestController()).build() + .perform(get("/form")) + .andExpect(status().isOk()) + .andExpect(content().type("text/plain")) + .andExpect(content().string("hello world") +); + +vs +old test method. + +TestController controller = new TestController(); +MockHttpServletRequest req = new MockHttpRequest(); +MockHttpSerlvetResponse res = new MockHttpResponse(); +ModelAndView mav = controller.form(req, res); +assertThat(res.getStatus(), is(200)); +assertThat(res.getContentType(), is(“text/plain”)); +assertThat(res.getContentAsString (), is(“content”)); + + */ + + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @Before + public void init() { + + mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); + + // 단일 Controller Test +// mockMvc = MockMvcBuilders.standaloneSetup(new SampleController()) +// .setCustomArgumentResolvers(new NexacroMethodArgumentResolver()).build(); + } + + @Test + public void testDefaultProcessing() throws Exception { + + MvcResult andReturn = mockMvc.perform(get("/default").content("")).andExpect(status().isOk()).andReturn(); + + HandlerInterceptor[] interceptors = andReturn.getInterceptors(); + Assert.assertEquals("interceptor count does not match..", 1, interceptors.length); + + if(!(interceptors[0] instanceof NexacroInterceptor)) { + Assert.fail(NexacroInterceptor.class+" not defined."); + } + + ModelAndView modelAndView = andReturn.getModelAndView(); + Object platformDataObj = modelAndView.getModelMap().get(NexacroConstants.ATTRIBUTE.NEXACRO_PLATFORM_DATA); + Assert.assertNotNull(NexacroConstants.ATTRIBUTE.NEXACRO_PLATFORM_DATA +" must be exist in model attribute.", platformDataObj); + + if(!(platformDataObj instanceof PlatformData)) { + Assert.fail(NexacroConstants.ATTRIBUTE.NEXACRO_PLATFORM_DATA +" must be PlatformData instance."); + } + + View view = modelAndView.getView(); + if(!(view instanceof NexacroView)) { + Assert.fail("result rendering should be "+NexacroView.class); + } + + } + + // 데이터셋의 컬럼의 order는 처리하지 않는다. + @Test + public void testResolveDataSetToBean() throws Exception { + + // dataset row type.... + String requestFileName = "src/test/java/com/nexacro/spring/resolve/httpRequest.xml"; + InputStream requestInputStream = new FileInputStream(new File(requestFileName)); + byte[] byteArray = IOUtils.toByteArray(requestInputStream); + + MvcResult andReturn = mockMvc.perform(get("/DataSetToBean").content(byteArray).contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andReturn(); + + MockHttpServletResponse servletResponse = andReturn.getResponse(); + String actualResult = servletResponse.getContentAsString(); + + String responseFileName = "src/test/java/com/nexacro/spring/resolve/httpResponse.xml"; + InputStream responseInputStream = new FileInputStream(new File(responseFileName)); + String expectedResult = IOUtils.toString(responseInputStream); + + Assert.assertEquals("result data has not resolved.", expectedResult, actualResult); + + } + + @Test + public void testResolveDataSetToMap() throws Exception { + + String requestFileName = "src/test/java/com/nexacro/spring/resolve/httpRequest.xml"; + InputStream requestInputStream = new FileInputStream(new File(requestFileName)); + byte[] byteArray = IOUtils.toByteArray(requestInputStream); + + MvcResult andReturn = mockMvc.perform(get("/DataSetToMap").content(byteArray).contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andReturn(); + + MockHttpServletResponse servletResponse = andReturn.getResponse(); + String actualResult = servletResponse.getContentAsString(); + + String responseFileName = "src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml"; + InputStream responseInputStream = new FileInputStream(new File(responseFileName)); + String expectedResult = IOUtils.toString(responseInputStream); + + Assert.assertEquals("result data has not resolved.", expectedResult, actualResult); + +// DataDeserializer deserializer = DataSerializerFactory.getDeserializer(PlatformType.CONTENT_TYPE_XML); +// PlatformData readData = deserializer.readData(new FileReader(new File(responseFileName)), null, PlatformType.DEFAULT_CHAR_SET); +// DataSet expectedDataSet = readData.getDataSet("dsResult"); +// +// // Map 변환 시 column의 order를 처리하지 않기 때문에 데이터셋으로 비교한다. +// readData = deserializer.readData(new StringReader(actualResult), null, PlatformType.DEFAULT_CHAR_SET); +// DataSet actualDataSet = readData.getDataSet("dsResult"); +// +// Assert.assertTrue("Result 'DataSet' structure not same.", expectedDataSet.equalsStructure(actualDataSet)); +// Assert.assertTrue("Result 'DataSet' data should be same.", expectedDataSet.equalsData(actualDataSet)); + + } + + @Test + public void testResolveVariable() throws Exception { + + String requestFileName = "src/test/java/com/nexacro/spring/resolve/httpRequest.xml"; + InputStream requestInputStream = new FileInputStream(new File(requestFileName)); + byte[] byteArray = IOUtils.toByteArray(requestInputStream); + + MvcResult andReturn = mockMvc.perform(get("/Variable").content(byteArray).contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andReturn(); + + MockHttpServletResponse servletResponse = andReturn.getResponse(); + String actualResult = servletResponse.getContentAsString(); + + String responseFileName = "src/test/java/com/nexacro/spring/resolve/httpResponseVariable.xml"; + InputStream responseInputStream = new FileInputStream(new File(responseFileName)); + String expectedResult = IOUtils.toString(responseInputStream); + + Assert.assertEquals("result data has not resolved.", expectedResult, actualResult); + + } + + @Test + public void testSupportedParameter() throws Exception { + + mockMvc.perform(get("/SupportedParameter").content("").contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")); + + } + + @Test + public void testNotEnterRequiredDataSet() throws Exception { + + mockMvc.perform(get("/NotEnterRequiredDataSet").content("").contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andDo(new ResultHandler() { + @Override + public void handle(MvcResult result) throws Exception { + Exception resolvedException = result.getResolvedException(); + if(resolvedException == null) { + Assert.fail("if you do not enter the mandatory parameters should result in an exception."); + } + if(!(resolvedException instanceof MissingNexacroParameterException)) { + Assert.fail("if you do not enter a mandatory parameter 'MissingNexacroParameterException' exceptions should be occured."); + } + } + }); + + } + + @Test + public void testNotEnterRequiredVariable() throws Exception { + + mockMvc.perform(get("/NotEnterRequiredVariable").content("").contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andDo(new ResultHandler() { + @Override + public void handle(MvcResult result) throws Exception { + Exception resolvedException = result.getResolvedException(); + if(resolvedException == null) { + Assert.fail("if you do not enter the mandatory parameters should result in an exception."); + } + if(!(resolvedException instanceof MissingNexacroParameterException)) { + Assert.fail("if you do not enter a mandatory parameter 'MissingNexacroParameterException' exceptions should be occured."); + } + } + }); + + } + + @Test + public void testOptionalDataSet() throws Exception { + + mockMvc.perform(get("/OptionalDataSet").content("").contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andDo(new ResultHandler() { + @Override + public void handle(MvcResult result) throws Exception { + Exception resolvedException = result.getResolvedException(); + if(resolvedException != null) { + Assert.fail("parameter is not mandatory"); + } + } + }); + + } + + @Test + public void testOptionalVariable() throws Exception { + + mockMvc.perform(get("/OptionalVariable").content("").contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/xml;charset=UTF-8")) + .andDo(new ResultHandler() { + @Override + public void handle(MvcResult result) throws Exception { + Exception resolvedException = result.getResolvedException(); + if(resolvedException != null) { + Assert.fail("parameter is not mandatory"); + } + } + }); + + } + + @Test + public void testUnsupportedVoidMethod() throws Exception { + + // void 메서드의 경우 NexacroView에서 처리 하지 않는다. + + mockMvc.perform(get("/Void").content("").contentType(MediaType.TEXT_XML)) + .andExpect(status().isOk()).andDo(new ResultHandler() { + @Override + public void handle(MvcResult result) throws Exception { + // nothing + } + }) + .andExpect(content().string(new BaseMatcher() { + @Override + public boolean matches(Object response) { + String responseString = (String) response; + if(responseString.equals("")) { + return true; + } + return false; + } + @Override + public void describeTo(Description desc) { + desc.appendText("must be empty response. NexacroView should not be processed."); + } + })); + } + +} diff --git a/src/test/java/com/nexacro/spring/resolve/NexacroExceptionResolveTest.java b/src/test/java/com/nexacro/spring/resolve/NexacroExceptionResolveTest.java new file mode 100644 index 0000000..289b7d7 --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/NexacroExceptionResolveTest.java @@ -0,0 +1,165 @@ +package com.nexacro.spring.resolve; + +import java.io.StringReader; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +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.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +import com.nexacro.spring.NexacroConstants; +import com.nexacro.spring.NexacroException; +import com.nexacro.spring.data.NexacroResult; +import com.nexacro.xapi.data.PlatformData; +import com.nexacro.xapi.data.Variable; +import com.nexacro.xapi.tx.DataDeserializer; +import com.nexacro.xapi.tx.DataSerializerFactory; +import com.nexacro.xapi.tx.PlatformException; +import com.nexacro.xapi.tx.PlatformType; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(locations = { "classpath*:spring/context-servlet.xml" } ) +public class NexacroExceptionResolveTest { + + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @Before + public void init() { + mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); + } + + @Test + public void testNexacroException() throws Exception { + + MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/NexacroException").content("")) + // 200 ok + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn(); + + // resolved exception.. + Exception resolvedException = result.getResolvedException(); + Assert.assertNotNull("Exception should be resolved.", resolvedException); + + // check response + String responseString = result.getResponse().getContentAsString(); + + PlatformData readData = readData(responseString); + + // check errorcode + Variable errorCodeVariable = readData.getVariable(NexacroConstants.ERROR.ERROR_CODE); + Assert.assertNotNull("ErrorCode must be not null. an exception occurs should be the exception information(nexacro ErrorCode, ErrorMsg) is returned", errorCodeVariable); + // defined ErrorCode + int expectedErrorCode = -88853; + int actualErrorCode = errorCodeVariable.getInt(); + Assert.assertEquals("Variable 'ErrorCode' must be '-88853'.", expectedErrorCode, actualErrorCode); + + // check errormsg + Variable errorMsgVariable = readData.getVariable(NexacroConstants.ERROR.ERROR_MSG); + Assert.assertNotNull("ErrorMsg must be not null. an exception occurs should be the exception information(nexacro ErrorCode, ErrorMsg) is returned", errorMsgVariable); + String expectedErrorMsg = "errorMsg=user message, stackMessage=nexacro exception"; + String actualErrorMsg = errorMsgVariable.getString(); + Assert.assertEquals("Variable 'ErrorMsg' must be transfered defined message.", expectedErrorMsg, actualErrorMsg); + + } + + @Test + public void testAnotherException() throws Exception { + + MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/AnotherException").content("")) + // 200 ok + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn(); + + // resolved exception.. + Exception resolvedException = result.getResolvedException(); + Assert.assertNotNull("Exception should be resolved.", resolvedException); + + // check response + String responseString = result.getResponse().getContentAsString(); + + PlatformData readData = readData(responseString); + + // check errorcode + Variable errorCodeVariable = readData.getVariable(NexacroConstants.ERROR.ERROR_CODE); + Assert.assertNotNull("ErrorCode must be not null. an exception occurs should be the exception information(nexacro ErrorCode, ErrorMsg) is returned", errorCodeVariable); + // default errorCode + int expectedErrorCode = -1; + int actualErrorCode = errorCodeVariable.getInt(); + Assert.assertEquals("Variable 'ErrorCode' must be '-1'.", expectedErrorCode, actualErrorCode); + + // check errormsg + Variable errorMsgVariable = readData.getVariable(NexacroConstants.ERROR.ERROR_MSG); + Assert.assertNotNull("ErrorMsg must be not null. an exception occurs should be the exception information(nexacro ErrorCode, ErrorMsg) is returned", errorMsgVariable); + String expectedErrorMsg = "another exception"; + String actualErrorMsg = errorMsgVariable.getString(); + Assert.assertEquals("Variable 'ErrorMsg' must be transfered defined message.", expectedErrorMsg, actualErrorMsg); + + } + + @Test + public void testSendUserExceptionMessage() { + + } + + @Test + public void testSendStackMessage() { + // ExceptionResolver의 설정값을 변경해서 Test. 별도 Config를 설정하자. + } + + private PlatformData readData(String responseString) { + PlatformData readData = null; + DataDeserializer deserializer = DataSerializerFactory.getDeserializer(PlatformType.CONTENT_TYPE_XML); + try { + readData = deserializer.readData(new StringReader(responseString), null, PlatformType.DEFAULT_CHAR_SET); + } catch (PlatformException e) { + Assert.fail("response string deserialize failed. e=" + e.getMessage()); + } + + return readData; + } + + + @Controller + public static class ExceptionController { + + @RequestMapping("/NexacroException") + public NexacroResult throwNexacroException() throws NexacroException { + + boolean occuredException = true; + if(occuredException) { + throw new NexacroException("nexacro exception", -88853, "user message"); + } + + return new NexacroResult(); + } + + @RequestMapping("/AnotherException") + public NexacroResult throwAnotherException() throws Exception { + + boolean occuredException = true; + if(occuredException) { + throw new IllegalAccessException("another exception"); + } + + return new NexacroResult(); + } + + } + +} diff --git a/src/test/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandlerTest.java b/src/test/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandlerTest.java new file mode 100644 index 0000000..fde1e9f --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandlerTest.java @@ -0,0 +1,59 @@ +package com.nexacro.spring.resolve; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.stereotype.Controller; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultHandler; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.view.JstlView; +import org.springframework.web.servlet.view.UrlBasedViewResolver; + +import com.nexacro.spring.NexacroConstants; +import com.nexacro.spring.data.NexacroResult; +import com.nexacro.spring.view.NexacroView; + +public class NexacroHandlerMethodReturnValueHandlerTest { + + @Test + public void testNexacroResult() throws Exception { + + UrlBasedViewResolver viewResolver = new UrlBasedViewResolver(); + viewResolver.setViewClass(JstlView.class); + + NexacroView view = new NexacroView(); + + NexacroHandlerMethodReturnValueHandler returnValueHandler = new NexacroHandlerMethodReturnValueHandler(); + returnValueHandler.setView(view); + + standaloneSetup(new PersonController()).setViewResolvers(viewResolver).setCustomReturnValueHandlers(returnValueHandler).build() + .perform(get("/resolveView").content("")) + .andExpect(status().isOk()) + .andExpect(model().size(1)) // platformData + .andExpect(model().attributeExists(NexacroConstants.ATTRIBUTE.NEXACRO_PLATFORM_DATA)) + .andDo(new ResultHandler() { + @Override + public void handle(MvcResult result) throws Exception { + if(!(result.getModelAndView().getView() instanceof NexacroView)) { + Assert.fail("Redering View expected<"+NexacroView.class+">. but was<"+ result.getModelAndView().getView()+">"); + } + } + }); + } + + @Controller + private static class PersonController { + + @RequestMapping(value="/resolveView", method=RequestMethod.GET) + public NexacroResult resolveView() { + NexacroResult view = new NexacroResult(); + return view; + } + } +} diff --git a/src/test/java/com/nexacro/spring/resolve/TestController.java b/src/test/java/com/nexacro/spring/resolve/TestController.java new file mode 100644 index 0000000..3237a1b --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/TestController.java @@ -0,0 +1,173 @@ +package com.nexacro.spring.resolve; + +import java.io.File; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Required; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +import com.nexacro.spring.NexacroException; +import com.nexacro.spring.annotation.ParamDataSet; +import com.nexacro.spring.annotation.ParamVariable; +import com.nexacro.spring.data.NexacroFileResult; +import com.nexacro.spring.data.NexacroFirstRowHandler; +import com.nexacro.spring.data.NexacroResult; +import com.nexacro.spring.data.support.bean.DefaultBean; +import com.nexacro.xapi.data.DataSet; +import com.nexacro.xapi.data.DataSetList; +import com.nexacro.xapi.data.PlatformData; +import com.nexacro.xapi.data.VariableList; +import com.nexacro.xapi.tx.HttpPlatformRequest; +import com.nexacro.xapi.tx.HttpPlatformResponse; + +@Controller +public class TestController { + + @RequestMapping(value="/default", method={RequestMethod.GET}) + public NexacroResult methodDefaultProcessing() throws NexacroException { + return new NexacroResult(); + } + + @RequestMapping(value="/DataSetToBean", method={RequestMethod.GET}) + public NexacroResult methodDataSetToBean(@ParamDataSet(name="ds") List dsList + , @ParamDataSet(name="ds") DataSet ds) throws NexacroException { + if(dsList == null || ds == null) { + throw new NexacroException("DataSet 'ds' have not been resolved"); + } + + if(dsList.size() != 2 || ds.getRowCount() != 2) { + throw new NexacroException("DataSet 'ds' data have not been resolved. expectedRowCount="+2+", actual="+ds.getRowCount()); + } + + NexacroResult result = new NexacroResult(); + result.addDataSet("dsResult", dsList); + + return result; + } + + @RequestMapping(value="/DataSetToMap", method={RequestMethod.GET}) + public NexacroResult methodDataSetToMap(@ParamDataSet(name="ds") List> dsList + , @ParamDataSet(name="ds") DataSet ds) throws NexacroException { + + if(dsList == null || ds == null) { + throw new NexacroException("DataSet 'ds' have not been resolved"); + } + + if(dsList.size() != 2 || ds.getRowCount() != 2) { + throw new NexacroException("DataSet 'ds' data have not been resolved. expectedRowCount="+2+", actual="+ds.getRowCount()); + } + + NexacroResult result = new NexacroResult(); + result.addDataSet("dsResult", dsList); + + return result; + } + + @RequestMapping(value="/Variable", method={RequestMethod.GET}) + public NexacroResult methodVariable(@ParamVariable(name="varInt") int varInt, @ParamVariable(name="varString") String varString) throws NexacroException { + if(varInt != 1) { + throw new NexacroException("Variable 'varInt' must be '1'. input variable have not been resolved."); + } + + if(!"park".equals(varString)) { + throw new NexacroException("Variable 'varString' must be 'park'. input variable have not been resolved."); + } + + NexacroResult result = new NexacroResult(); + result.addVariable("varResultInt", varInt); + result.addVariable("varResultString", varString); + + return result; + } + + @RequestMapping(value="/SupportedParameter") + public NexacroResult methodSupportedParam( + DataSetList dsList + , VariableList varList + , PlatformData platformData + , HttpPlatformRequest platformRequest + , HttpPlatformResponse platformResponse + , NexacroFirstRowHandler firstRowHandler + ) throws NexacroException { + + if(dsList == null) { + throw new NexacroException("VariableList have not bean resolved."); + } + if(varList == null) { + throw new NexacroException("DataSetList have not bean resolved."); + } + if(platformData == null) { + throw new NexacroException("PlatformData have not bean resolved."); + } + if(platformRequest == null) { + throw new NexacroException("HttpPlatformRequest have not bean resolved."); + } + if(platformResponse == null) { + throw new NexacroException("HttpPlatformResponse have not bean resolved."); + } + if(firstRowHandler == null) { + throw new NexacroException("NexacroFirstRowHandler have not bean resolved."); + } + + return new NexacroResult(); + + } + +// @RequestMapping(value="/UnsupportedParameter") +// public NexacroResult methodSupportedParam(@ParamDataSet(name = "" ) Map map) throws NexacroException { +// +// +// return new NexacroResult(); +// } + + @RequestMapping(value="/NotEnterRequiredDataSet") + public NexacroResult methodNotEnterRequiredDataSet(@ParamDataSet(name="required", required=true) List required) throws NexacroException { + + if(required != null) { + throw new NexacroException("'required' data should be null with null input."); + } + + return new NexacroResult(); + } + + @RequestMapping(value="/NotEnterRequiredVariable") + public NexacroResult methodNotEnterRequiredVariable(@ParamVariable(name="required", required=true) int required) throws NexacroException { + + if(required != 0) { + throw new NexacroException("'required' data should be zero with null input."); + } + + return new NexacroResult(); + } + + @RequestMapping(value="/OptionalDataSet") + public NexacroResult methodOptionalDataSet(@ParamDataSet(name="optional", required=false) List missing) throws NexacroException { + return new NexacroResult(); + } + + @RequestMapping(value="/OptionalVariable") + public NexacroResult methodOptionalVariable(@ParamDataSet(name="optional", required=false) String optional) throws NexacroException { + return new NexacroResult(); + } + + @RequestMapping(value="/NexacroFileResult") + public NexacroFileResult methodNexacroFileResult() { + + File file = null; + + NexacroFileResult fileResult = new NexacroFileResult(file); + + return fileResult; + } + + @RequestMapping(value="/Void") + public void methodVoid() { + + // nothing + } + +} diff --git a/src/test/java/com/nexacro/spring/resolve/httpRequest.xml b/src/test/java/com/nexacro/spring/resolve/httpRequest.xml new file mode 100644 index 0000000..e65920f --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/httpRequest.xml @@ -0,0 +1,53 @@ + + + + 1 + park + + + + + + + + + + + + + + + + + + + 11 + 11.1 + seongmin@tobesoft.com + 11 + seongmin + 180.1 + 20090101134516072 + AQE= + park + 1 + java.lang.Object@1c7e2da + 10001 + + + 12 + 11.2 + hyena@tobesoft.com + 12 + hyena + 180.2 + 20090102134516072 + AQI= + lee + 0 + java.lang.Object@69fe571f + 10002 + + + + \ No newline at end of file diff --git a/src/test/java/com/nexacro/spring/resolve/httpResponse.xml b/src/test/java/com/nexacro/spring/resolve/httpResponse.xml new file mode 100644 index 0000000..ca404bc --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/httpResponse.xml @@ -0,0 +1,52 @@ + + + + 0 + + + + + + + + + + + + + + + + + + + 11 + 11.1 + seongmin@tobesoft.com + 11 + seongmin + 180.1 + 20090101134516072 + AQE= + park + 1 + java.lang.Object@1c7e2da + 10001 + + + 12 + 11.2 + hyena@tobesoft.com + 12 + hyena + 180.2 + 20090102134516072 + AQI= + lee + 0 + java.lang.Object@69fe571f + 10002 + + + + diff --git a/src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml b/src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml new file mode 100644 index 0000000..3c29955 --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml @@ -0,0 +1,52 @@ + + + + 0 + + + + + + + + + + + + + + + + + + + 11 + park + 1 + 20090101134516072 + AQE= + 11 + 11.1 + 180.1 + seongmin@tobesoft.com + java.lang.Object@1c7e2da + 10001 + seongmin + + + 12 + lee + 0 + 20090102134516072 + AQI= + 12 + 11.2 + 180.2 + hyena@tobesoft.com + java.lang.Object@69fe571f + 10002 + hyena + + + + diff --git a/src/test/java/com/nexacro/spring/resolve/httpResponseVariable.xml b/src/test/java/com/nexacro/spring/resolve/httpResponseVariable.xml new file mode 100644 index 0000000..8b8ddde --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/httpResponseVariable.xml @@ -0,0 +1,8 @@ + + + + park + 1 + 0 + + diff --git a/src/test/java/com/nexacro/spring/servicelayout/RequestMappingView.java b/src/test/java/com/nexacro/spring/servicelayout/RequestMappingView.java index 69bac21..40434c3 100644 --- a/src/test/java/com/nexacro/spring/servicelayout/RequestMappingView.java +++ b/src/test/java/com/nexacro/spring/servicelayout/RequestMappingView.java @@ -24,16 +24,14 @@ public class RequestMappingView { wac.setServletContext(servletContext); wac.setConfigLocations(new String[] { "com/nexacro/spring/servicelayout/application-config.xml" }); wac.refresh(); - RequestMappingHandlerMapping mapping = wac - .getBean(RequestMappingHandlerMapping.class); - Map map = mapping - .getHandlerMethods(); - for (final Map.Entry entry : map - .entrySet()) { - System.out.println(entry.getKey().getPatternsCondition() - .getPatterns() - + " : " + entry.getValue().getMethod()); + + RequestMappingHandlerMapping mapping = wac.getBean(RequestMappingHandlerMapping.class); + Map map = mapping.getHandlerMethods(); + + for (final Map.Entry entry : map.entrySet()) { + System.out.println(entry.getKey().getPatternsCondition().getPatterns() + " : " + entry.getValue().getMethod()); } + wac.close(); } } \ No newline at end of file diff --git a/src/test/java/com/nexacro/spring/view/NexacroFileViewTest.java b/src/test/java/com/nexacro/spring/view/NexacroFileViewTest.java new file mode 100644 index 0000000..0c5a0c4 --- /dev/null +++ b/src/test/java/com/nexacro/spring/view/NexacroFileViewTest.java @@ -0,0 +1,5 @@ +package com.nexacro.spring.view; + +public class NexacroFileViewTest { + +} diff --git a/src/test/java/com/nexacro/spring/view/NexacroViewTest.java b/src/test/java/com/nexacro/spring/view/NexacroViewTest.java new file mode 100644 index 0000000..3a98998 --- /dev/null +++ b/src/test/java/com/nexacro/spring/view/NexacroViewTest.java @@ -0,0 +1,53 @@ +package com.nexacro.spring.view; + +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import com.nexacro.spring.NexacroConstants; +import com.nexacro.xapi.data.PlatformData; +import com.nexacro.xapi.data.Variable; +import com.nexacro.xapi.tx.DataDeserializer; +import com.nexacro.xapi.tx.DataSerializerFactory; +import com.nexacro.xapi.tx.PlatformType; + +public class NexacroViewTest { + + @Test + public void testRender() throws Exception { + + NexacroView view = new NexacroView(); + + MockHttpServletRequest request = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + + Map model = new HashMap(); + + // initialize RequestContextHolder. (used NexacroView..) + ServletRequestAttributes attributes = new ServletRequestAttributes(request); + RequestContextHolder.setRequestAttributes(attributes); + + view.render(model, request, response); + + String contentAsString = response.getContentAsString(); + + DataDeserializer deserializer = DataSerializerFactory.getDeserializer(PlatformType.CONTENT_TYPE_XML); + PlatformData readData = deserializer.readData(new StringReader(contentAsString), null, PlatformType.DEFAULT_CHAR_SET); + Variable errorCodeVariable = readData.getVariable(NexacroConstants.ERROR.ERROR_CODE); + Assert.assertNotNull("Variable 'ErrorCode' should not be null.", errorCodeVariable); + + int expectedErrorCode = NexacroConstants.ERROR.DEFAULT_ERROR_CODE; + int actualErrorCode = errorCodeVariable.getInt(); + + Assert.assertEquals("successfully ErrorCode must be zero", expectedErrorCode, actualErrorCode); + + } + +} diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml index 600d7d1..ebfd3d3 100644 --- a/src/test/resources/log4j2.xml +++ b/src/test/resources/log4j2.xml @@ -50,6 +50,10 @@ + + + + diff --git a/src/test/resources/spring/context-servlet.xml b/src/test/resources/spring/context-servlet.xml new file mode 100644 index 0000000..22d8176 --- /dev/null +++ b/src/test/resources/spring/context-servlet.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +