TestCase 추가
This commit is contained in:
@@ -56,6 +56,16 @@ public class NexacroConverterFactoryTest {
|
||||
converter = NexacroConverterFactory.getConverter(source, target);
|
||||
Assert.assertNotNull(source + " -> " + target + " converter not registed.", converter);
|
||||
|
||||
source = DataSet.class;
|
||||
target = Object.class;
|
||||
converter = NexacroConverterFactory.getConverter(source, target);
|
||||
Assert.assertNotNull(source + " -> " + target + " converter not registed.", converter);
|
||||
|
||||
source = Object.class;
|
||||
target = DataSet.class;
|
||||
converter = NexacroConverterFactory.getConverter(source, target);
|
||||
Assert.assertNotNull(source + " -> " + target + " converter not registed.", converter);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.nexacro.spring.data.support;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -14,11 +13,8 @@ import org.junit.Test;
|
||||
|
||||
import com.nexacro.spring.data.convert.ConvertDefinition;
|
||||
import com.nexacro.spring.data.convert.NexacroConvertException;
|
||||
import com.nexacro.spring.data.support.NexacroTestUtil.StaticPropertyBean;
|
||||
import com.nexacro.spring.data.support.bean.DefaultBean;
|
||||
import com.nexacro.spring.util.ReflectionUtil;
|
||||
import com.nexacro.xapi.data.ColumnHeader;
|
||||
import com.nexacro.xapi.data.ConstantColumnHeader;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
|
||||
public class ObjectToDataSetConverterTest {
|
||||
@@ -88,7 +84,8 @@ public class ObjectToDataSetConverterTest {
|
||||
}
|
||||
|
||||
DataSet dataset = (DataSet) ds;
|
||||
Assert.assertEquals("lastName", dataset.getObject(0, "lastName"));
|
||||
Assert.assertEquals(map.get("firstName"), dataset.getObject(0, "firstName"));
|
||||
Assert.assertEquals(map.get("lastName"), dataset.getObject(0, "lastName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,8 +26,6 @@ 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.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@@ -43,10 +41,11 @@ import com.nexacro.xapi.tx.DataDeserializer;
|
||||
import com.nexacro.xapi.tx.DataSerializerFactory;
|
||||
import com.nexacro.xapi.tx.PlatformException;
|
||||
import com.nexacro.xapi.tx.PlatformType;
|
||||
import com.nexacro.xapi.tx.impl.PlatformXmlDataDeserializer;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(locations = { "classpath*:spring/context-servlet.xml" } )
|
||||
@ContextConfiguration(locations = { "classpath*:spring/context-servlet.xml" })
|
||||
public class NexacroDataResolveTest {
|
||||
|
||||
/*
|
||||
@@ -174,6 +173,62 @@ assertThat(res.getContentAsString (), is(“content”));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDataSetWithASingleRowToMap() 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("/DataSetWithASingleRowToMap").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();
|
||||
|
||||
PlatformXmlDataDeserializer deserializer = new PlatformXmlDataDeserializer();
|
||||
PlatformData actualPlatformData = deserializer.readData(new StringReader(actualResult), null, "UTF-8");
|
||||
DataSet actualTedDataSet = actualPlatformData.getDataSet(0);
|
||||
|
||||
String responseFileName = "src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml";
|
||||
InputStream responseInputStream = new FileInputStream(new File(responseFileName));
|
||||
String expectedResult = IOUtils.toString(responseInputStream);
|
||||
|
||||
PlatformData expectedPlatformData = deserializer.readData(new StringReader(expectedResult), null, "UTF-8");
|
||||
DataSet expectedDataSet = expectedPlatformData.getDataSet(0);
|
||||
|
||||
Assert.assertEquals("result data has not resolved.", expectedDataSet.getObject(0, "employeeId"), actualTedDataSet.getObject(0, "employeeId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDataSetWithASingleRowToObject() 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("/DataSetWithASingleRowToObject").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();
|
||||
|
||||
PlatformXmlDataDeserializer deserializer = new PlatformXmlDataDeserializer();
|
||||
PlatformData actualPlatformData = deserializer.readData(new StringReader(actualResult), null, "UTF-8");
|
||||
DataSet actualTedDataSet = actualPlatformData.getDataSet(0);
|
||||
|
||||
String responseFileName = "src/test/java/com/nexacro/spring/resolve/httpResponseMap.xml";
|
||||
InputStream responseInputStream = new FileInputStream(new File(responseFileName));
|
||||
String expectedResult = IOUtils.toString(responseInputStream);
|
||||
|
||||
PlatformData expectedPlatformData = deserializer.readData(new StringReader(expectedResult), null, "UTF-8");
|
||||
DataSet expectedDataSet = expectedPlatformData.getDataSet(0);
|
||||
|
||||
Assert.assertEquals("result data has not resolved.", expectedDataSet.getObject(0, "employeeId"), actualTedDataSet.getObject(0, "employeeId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveVariable() throws Exception {
|
||||
|
||||
|
||||
@@ -69,6 +69,32 @@ public class TestController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/DataSetWithASingleRowToMap", method={RequestMethod.GET})
|
||||
public NexacroResult methodDataSetWithOneRowToMap(@ParamDataSet(name="ds") Map<String, Object> map) throws NexacroException {
|
||||
|
||||
if(map == null) {
|
||||
throw new NexacroException("DataSet 'ds' have not been resolved");
|
||||
}
|
||||
|
||||
NexacroResult result = new NexacroResult();
|
||||
result.addDataSet("dsResult", map);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/DataSetWithASingleRowToObject", method={RequestMethod.GET})
|
||||
public NexacroResult methodDataSetWithOneRowToObject(@ParamDataSet(name="ds") DefaultBean defaultBean) throws NexacroException {
|
||||
|
||||
if(defaultBean == null) {
|
||||
throw new NexacroException("DataSet 'ds' have not been resolved");
|
||||
}
|
||||
|
||||
NexacroResult result = new NexacroResult();
|
||||
result.addDataSet("dsResult", defaultBean);
|
||||
|
||||
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) {
|
||||
|
||||
@@ -78,7 +78,10 @@
|
||||
- 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">
|
||||
-->
|
||||
<bean class="com.nexacro.spring.resolve.NexacroRequestMappingHandlerAdapter">
|
||||
<property name="customArgumentResolvers">
|
||||
<list>
|
||||
<!-- regist Nexacro Argument Resolvers.. -->
|
||||
|
||||
Reference in New Issue
Block a user