test case 추가.
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -127,6 +127,7 @@
|
|||||||
<version>1.6</version>
|
<version>1.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 배포시점에 포함시키지 않는다. 외부의 Servlet Spec을 이용한다. -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
|||||||
@@ -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<String>() {
|
||||||
|
@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.");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
173
src/test/java/com/nexacro/spring/resolve/TestController.java
Normal file
173
src/test/java/com/nexacro/spring/resolve/TestController.java
Normal file
@@ -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<DefaultBean> 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<Map<String, Object>> 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<Map> 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<Map> 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
53
src/test/java/com/nexacro/spring/resolve/httpRequest.xml
Normal file
53
src/test/java/com/nexacro/spring/resolve/httpRequest.xml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Root xmlns="http://www.nexacro.com/platform/dataset" ver="5000">
|
||||||
|
<Parameters>
|
||||||
|
<Parameter id="varInt" type="int">1</Parameter>
|
||||||
|
<Parameter id="varString" type="string">park</Parameter>
|
||||||
|
</Parameters>
|
||||||
|
<Dataset id="ds">
|
||||||
|
<ColumnInfo>
|
||||||
|
<Column id="access" type="bigdecimal" size="8"/>
|
||||||
|
<Column id="commissionPercent" type="float" size="8"/>
|
||||||
|
<Column id="email" type="string" size="32"/>
|
||||||
|
<Column id="employeeId" type="int" size="4"/>
|
||||||
|
<Column id="firstName" type="string" size="32"/>
|
||||||
|
<Column id="height" type="float" size="4"/>
|
||||||
|
<Column id="hireDate" type="datetime" size="17"/>
|
||||||
|
<Column id="image" type="blob" size="256" encrypt="base64"/>
|
||||||
|
<Column id="lastName" type="string" size="32"/>
|
||||||
|
<Column id="male" type="int" size="2"/>
|
||||||
|
<Column id="obj" type="undefined" size="0"/>
|
||||||
|
<Column id="salary" type="bigdecimal" size="16"/>
|
||||||
|
</ColumnInfo>
|
||||||
|
<Rows>
|
||||||
|
<Row>
|
||||||
|
<Col id="access">11</Col>
|
||||||
|
<Col id="commissionPercent">11.1</Col>
|
||||||
|
<Col id="email">seongmin@tobesoft.com</Col>
|
||||||
|
<Col id="employeeId">11</Col>
|
||||||
|
<Col id="firstName">seongmin</Col>
|
||||||
|
<Col id="height">180.1</Col>
|
||||||
|
<Col id="hireDate">20090101134516072</Col>
|
||||||
|
<Col id="image">AQE=</Col>
|
||||||
|
<Col id="lastName">park</Col>
|
||||||
|
<Col id="male">1</Col>
|
||||||
|
<Col id="obj">java.lang.Object@1c7e2da</Col>
|
||||||
|
<Col id="salary">10001</Col>
|
||||||
|
</Row>
|
||||||
|
<Row>
|
||||||
|
<Col id="access">12</Col>
|
||||||
|
<Col id="commissionPercent">11.2</Col>
|
||||||
|
<Col id="email">hyena@tobesoft.com</Col>
|
||||||
|
<Col id="employeeId">12</Col>
|
||||||
|
<Col id="firstName">hyena</Col>
|
||||||
|
<Col id="height">180.2</Col>
|
||||||
|
<Col id="hireDate">20090102134516072</Col>
|
||||||
|
<Col id="image">AQI=</Col>
|
||||||
|
<Col id="lastName">lee</Col>
|
||||||
|
<Col id="male">0</Col>
|
||||||
|
<Col id="obj">java.lang.Object@69fe571f</Col>
|
||||||
|
<Col id="salary">10002</Col>
|
||||||
|
</Row>
|
||||||
|
</Rows>
|
||||||
|
</Dataset>
|
||||||
|
</Root>
|
||||||
52
src/test/java/com/nexacro/spring/resolve/httpResponse.xml
Normal file
52
src/test/java/com/nexacro/spring/resolve/httpResponse.xml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Root xmlns="http://www.nexacro.com/platform/dataset" ver="5000">
|
||||||
|
<Parameters>
|
||||||
|
<Parameter id="ErrorCode" type="int">0</Parameter>
|
||||||
|
</Parameters>
|
||||||
|
<Dataset id="dsResult">
|
||||||
|
<ColumnInfo>
|
||||||
|
<Column id="access" type="bigdecimal" size="8"/>
|
||||||
|
<Column id="commissionPercent" type="float" size="8"/>
|
||||||
|
<Column id="email" type="string" size="32"/>
|
||||||
|
<Column id="employeeId" type="int" size="4"/>
|
||||||
|
<Column id="firstName" type="string" size="32"/>
|
||||||
|
<Column id="height" type="float" size="4"/>
|
||||||
|
<Column id="hireDate" type="datetime" size="17"/>
|
||||||
|
<Column id="image" type="blob" size="256" encrypt="base64"/>
|
||||||
|
<Column id="lastName" type="string" size="32"/>
|
||||||
|
<Column id="male" type="int" size="2"/>
|
||||||
|
<Column id="obj" type="undefined" size="0"/>
|
||||||
|
<Column id="salary" type="bigdecimal" size="16"/>
|
||||||
|
</ColumnInfo>
|
||||||
|
<Rows>
|
||||||
|
<Row>
|
||||||
|
<Col id="access">11</Col>
|
||||||
|
<Col id="commissionPercent">11.1</Col>
|
||||||
|
<Col id="email">seongmin@tobesoft.com</Col>
|
||||||
|
<Col id="employeeId">11</Col>
|
||||||
|
<Col id="firstName">seongmin</Col>
|
||||||
|
<Col id="height">180.1</Col>
|
||||||
|
<Col id="hireDate">20090101134516072</Col>
|
||||||
|
<Col id="image">AQE=</Col>
|
||||||
|
<Col id="lastName">park</Col>
|
||||||
|
<Col id="male">1</Col>
|
||||||
|
<Col id="obj">java.lang.Object@1c7e2da</Col>
|
||||||
|
<Col id="salary">10001</Col>
|
||||||
|
</Row>
|
||||||
|
<Row>
|
||||||
|
<Col id="access">12</Col>
|
||||||
|
<Col id="commissionPercent">11.2</Col>
|
||||||
|
<Col id="email">hyena@tobesoft.com</Col>
|
||||||
|
<Col id="employeeId">12</Col>
|
||||||
|
<Col id="firstName">hyena</Col>
|
||||||
|
<Col id="height">180.2</Col>
|
||||||
|
<Col id="hireDate">20090102134516072</Col>
|
||||||
|
<Col id="image">AQI=</Col>
|
||||||
|
<Col id="lastName">lee</Col>
|
||||||
|
<Col id="male">0</Col>
|
||||||
|
<Col id="obj">java.lang.Object@69fe571f</Col>
|
||||||
|
<Col id="salary">10002</Col>
|
||||||
|
</Row>
|
||||||
|
</Rows>
|
||||||
|
</Dataset>
|
||||||
|
</Root>
|
||||||
52
src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml
Normal file
52
src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Root xmlns="http://www.nexacro.com/platform/dataset" ver="5000">
|
||||||
|
<Parameters>
|
||||||
|
<Parameter id="ErrorCode" type="int">0</Parameter>
|
||||||
|
</Parameters>
|
||||||
|
<Dataset id="dsResult">
|
||||||
|
<ColumnInfo>
|
||||||
|
<Column id="employeeId" type="int" size="4"/>
|
||||||
|
<Column id="lastName" type="string" size="32"/>
|
||||||
|
<Column id="male" type="int" size="4"/>
|
||||||
|
<Column id="hireDate" type="datetime" size="17"/>
|
||||||
|
<Column id="image" type="blob" size="256" encrypt="base64"/>
|
||||||
|
<Column id="access" type="bigdecimal" size="16"/>
|
||||||
|
<Column id="commissionPercent" type="float" size="8"/>
|
||||||
|
<Column id="height" type="float" size="8"/>
|
||||||
|
<Column id="email" type="string" size="32"/>
|
||||||
|
<Column id="obj" type="string" size="32"/>
|
||||||
|
<Column id="salary" type="bigdecimal" size="16"/>
|
||||||
|
<Column id="firstName" type="string" size="32"/>
|
||||||
|
</ColumnInfo>
|
||||||
|
<Rows>
|
||||||
|
<Row>
|
||||||
|
<Col id="employeeId">11</Col>
|
||||||
|
<Col id="lastName">park</Col>
|
||||||
|
<Col id="male">1</Col>
|
||||||
|
<Col id="hireDate">20090101134516072</Col>
|
||||||
|
<Col id="image">AQE=</Col>
|
||||||
|
<Col id="access">11</Col>
|
||||||
|
<Col id="commissionPercent">11.1</Col>
|
||||||
|
<Col id="height">180.1</Col>
|
||||||
|
<Col id="email">seongmin@tobesoft.com</Col>
|
||||||
|
<Col id="obj">java.lang.Object@1c7e2da</Col>
|
||||||
|
<Col id="salary">10001</Col>
|
||||||
|
<Col id="firstName">seongmin</Col>
|
||||||
|
</Row>
|
||||||
|
<Row>
|
||||||
|
<Col id="employeeId">12</Col>
|
||||||
|
<Col id="lastName">lee</Col>
|
||||||
|
<Col id="male">0</Col>
|
||||||
|
<Col id="hireDate">20090102134516072</Col>
|
||||||
|
<Col id="image">AQI=</Col>
|
||||||
|
<Col id="access">12</Col>
|
||||||
|
<Col id="commissionPercent">11.2</Col>
|
||||||
|
<Col id="height">180.2</Col>
|
||||||
|
<Col id="email">hyena@tobesoft.com</Col>
|
||||||
|
<Col id="obj">java.lang.Object@69fe571f</Col>
|
||||||
|
<Col id="salary">10002</Col>
|
||||||
|
<Col id="firstName">hyena</Col>
|
||||||
|
</Row>
|
||||||
|
</Rows>
|
||||||
|
</Dataset>
|
||||||
|
</Root>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Root xmlns="http://www.nexacro.com/platform/dataset" ver="5000">
|
||||||
|
<Parameters>
|
||||||
|
<Parameter id="varResultString" type="string">park</Parameter>
|
||||||
|
<Parameter id="varResultInt" type="int">1</Parameter>
|
||||||
|
<Parameter id="ErrorCode" type="int">0</Parameter>
|
||||||
|
</Parameters>
|
||||||
|
</Root>
|
||||||
@@ -24,16 +24,14 @@ public class RequestMappingView {
|
|||||||
wac.setServletContext(servletContext);
|
wac.setServletContext(servletContext);
|
||||||
wac.setConfigLocations(new String[] { "com/nexacro/spring/servicelayout/application-config.xml" });
|
wac.setConfigLocations(new String[] { "com/nexacro/spring/servicelayout/application-config.xml" });
|
||||||
wac.refresh();
|
wac.refresh();
|
||||||
RequestMappingHandlerMapping mapping = wac
|
|
||||||
.getBean(RequestMappingHandlerMapping.class);
|
RequestMappingHandlerMapping mapping = wac.getBean(RequestMappingHandlerMapping.class);
|
||||||
Map<RequestMappingInfo, HandlerMethod> map = mapping
|
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
|
||||||
.getHandlerMethods();
|
|
||||||
for (final Map.Entry<RequestMappingInfo, HandlerMethod> entry : map
|
for (final Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) {
|
||||||
.entrySet()) {
|
System.out.println(entry.getKey().getPatternsCondition().getPatterns() + " : " + entry.getValue().getMethod());
|
||||||
System.out.println(entry.getKey().getPatternsCondition()
|
|
||||||
.getPatterns()
|
|
||||||
+ " : " + entry.getValue().getMethod());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wac.close();
|
wac.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.nexacro.spring.view;
|
||||||
|
|
||||||
|
public class NexacroFileViewTest {
|
||||||
|
|
||||||
|
}
|
||||||
53
src/test/java/com/nexacro/spring/view/NexacroViewTest.java
Normal file
53
src/test/java/com/nexacro/spring/view/NexacroViewTest.java
Normal file
@@ -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<String, Object> model = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -50,6 +50,10 @@
|
|||||||
<Logger name="com.nexacro.spring" level="TRACE" additivity="false">
|
<Logger name="com.nexacro.spring" level="TRACE" additivity="false">
|
||||||
<AppenderRef ref="console" />
|
<AppenderRef ref="console" />
|
||||||
</Logger>
|
</Logger>
|
||||||
|
<!-- 'TRACE' only performance logging. parseRequest, resolveData, sendData -->
|
||||||
|
<Logger name="com.nexacro.performance" level="DEBUG" additivity="false">
|
||||||
|
<AppenderRef ref="console" />
|
||||||
|
</Logger>
|
||||||
<Root level="DEBUG">
|
<Root level="DEBUG">
|
||||||
<AppenderRef ref="console" />
|
<AppenderRef ref="console" />
|
||||||
<AppenderRef ref="file" />
|
<AppenderRef ref="file" />
|
||||||
|
|||||||
110
src/test/resources/spring/context-servlet.xml
Normal file
110
src/test/resources/spring/context-servlet.xml
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- DispatcherServlet application context for Application's web tier. -->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
|
||||||
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
|
||||||
|
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
|
||||||
|
|
||||||
|
<!-- The controllers are autodetected POJOs labeled with the @Controller annotation. -->
|
||||||
|
<context:component-scan base-package="com.nexacro.spring.resolve">
|
||||||
|
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
|
||||||
|
</context:component-scan>
|
||||||
|
|
||||||
|
<!-- nexacro config -->
|
||||||
|
<bean id="nexacroInterceptor" class="com.nexacro.spring.servlet.NexacroInterceptor"/>
|
||||||
|
|
||||||
|
<!-- nexacro method argument resolver -->
|
||||||
|
<bean id="nexacroMethodArgumentResolver" class="com.nexacro.spring.resolve.NexacroMethodArgumentResolver">
|
||||||
|
<!--
|
||||||
|
<property name="convertListeners">
|
||||||
|
<list>
|
||||||
|
<ref bean="nexacroListener" />
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
-->
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- <bean id="beanNameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/> -->
|
||||||
|
<bean id="nexacroView" class="com.nexacro.spring.view.NexacroView" >
|
||||||
|
<property name="defaultContentType" value="PlatformXml" />
|
||||||
|
<property name="defaultCharset" value="UTF-8" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="nexacroFileView" class="com.nexacro.spring.view.NexacroFileView" />
|
||||||
|
|
||||||
|
<!-- nexacro method return value handler -->
|
||||||
|
<bean id="nexacroMethodReturnValueHandler" class="com.nexacro.spring.resolve.NexacroHandlerMethodReturnValueHandler" >
|
||||||
|
<!-- <property name="view" value="nexacroView" /> -->
|
||||||
|
<property name="view" ref="nexacroView" />
|
||||||
|
<property name="fileView" ref="nexacroFileView" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- nexacro exception resolver -->
|
||||||
|
<bean id="exceptionResolver" class="com.nexacro.spring.resolve.NexacroMappingExceptionResolver" p:order="1">
|
||||||
|
<property name="view" ref="nexacroView" />
|
||||||
|
<property name="shouldLogStackTrace" value="true" />
|
||||||
|
<property name="shouldSendStackTrace" value="true" />
|
||||||
|
<!-- shouldSendStackTrace 가 false 일 경우 nexacro platform으로 전송되는 에러메시지 -->
|
||||||
|
<property name="defaultErrorMsg" value="An Error Occured. check the ErrorCode for detail of error infomation" />
|
||||||
|
</bean>
|
||||||
|
<!-- nexacro config finish -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- HandlerMappings 선언 시작 (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) -->
|
||||||
|
<!-- set interceptor of AnnotationHandlerMapping
|
||||||
|
- @MVC 개발을 하려면 RequestMappingHandlerMapping(3.1 이상)을 사용해야 한다. 단, jdk 1.5 이상의 개발환경이어야 한다.
|
||||||
|
- jdk 1.5이상의 개발환경이라면, BeanNameUrlHandlerMapping과 함께 RequestMappingHandlerMapping(3.1 이상)도
|
||||||
|
- 기본 HandlerMapping이다. 따라서 빈 설정 파일에 별도로 선언해주지 않아도 된다. (단, 다른 HandlerMapping과 함께 사용한다면 선언해주어야 한다.)
|
||||||
|
-->
|
||||||
|
<!-- Session 검사를 하지 않는 URL처리를 위한 HandlerMapping -->
|
||||||
|
<bean id="annotationMapper" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" p:order="1">
|
||||||
|
<property name="interceptors">
|
||||||
|
<list>
|
||||||
|
<ref bean="nexacroInterceptor" />
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
<!-- HandlerMappings 선언 끝 -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
- This bean processes annotated handler methods, applying Application-specific PropertyEditors
|
||||||
|
- for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter.
|
||||||
|
-->
|
||||||
|
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
|
||||||
|
<property name="customArgumentResolvers">
|
||||||
|
<list>
|
||||||
|
<!-- regist Nexacro Argument Resolvers.. -->
|
||||||
|
<ref bean="nexacroMethodArgumentResolver"/>
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
<property name="customReturnValueHandlers">
|
||||||
|
<list>
|
||||||
|
<!-- regist Nexacro Return Value Handler.. -->
|
||||||
|
<ref bean="nexacroMethodReturnValueHandler"/>
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
- 추가적인 어떤 맵핑 작업을 하지 않고 URL의 상징적인 view 이름을 사용하는 ViewResolver
|
||||||
|
- 단순 JSP만 사용할 경우 사용이 가능하다.
|
||||||
|
- 보통 해당 클래스를 확장하여 제공하는 별도의 ViewResolver를 사용한다.
|
||||||
|
- This bean configures the 'prefix' and 'suffix' properties of
|
||||||
|
- InternalResourceViewResolver, which resolves logical view names
|
||||||
|
- returned by Controllers. For example, a logical view name of "vets"
|
||||||
|
- will be mapped to "/WEB-INF/jsp/vets.jsp".
|
||||||
|
-->
|
||||||
|
<bean id="urlBasedView" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1"
|
||||||
|
p:viewClass="org.springframework.web.servlet.view.JstlView"
|
||||||
|
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
||||||
Reference in New Issue
Block a user