我已经看到类似的问题,但是我还没有找到适合我的解决方案。当我使用POSTMAN测试端点时,它可以正常工作。它返回正确的对象,即Attribute = DATA的值。但是,当我在junit上使用mockmvc测试相同的端点时,它将返回200个代码,但值为空。谁能告诉我这是怎么回事?任何帮助将不胜感激。谢谢。
这是我的控制器。
@RequestMapping(params = "cmd=getAppBeforeLstList")
public ModelAndView getAppBeforeLstList(HttpSession session,
HttpServletRequest request,
@RequestParam Map<String, Object> paramMap) throws Exception {
Log.DebugStart();
paramMap = ParamUtils.converterParams(request);
paramMap.put("ssnEnterCd", session.getAttribute("ssnEnterCd"));
paramMap.put("ssnSabun", session.getAttribute("ssnSabun"));
paramMap.put("ssnOrgCd", session.getAttribute("ssnOrgCd"));
List<?> result = appBeforeLstService.getAppBeforeLstList(paramMap);
ModelAndView mv = new ModelAndView();
mv.setViewName("jsonView"); mv.addObject("DATA", result);
Log.DebugEnd();
return mv;
}
并测试源代码。
public void testGet_param(String url, UnaryOperator<MockHttpServletRequestBuilder> operator) throws Exception {
mockMvc.perform(operator.apply(get(url))).andDo(print()).andExpect(status().isOk());
}
@Test
public void getappbeforelstlist() throws Exception {
testGet_param("/AppBeforeLst.do", builder -> builder.param("cmd", "getAppBeforeLstList")
.param("enterCd", enterCd).param("sabun", sabun));
最后是控制台消息。
MockHttpServletRequest:
HTTP Method = GET
Request URI = /AppBeforeLst.do
Parameters = {cmd=[getAppBeforeLstList], enterCd=[ISU_PS], sabun=[91006]}
Headers = {}
Handler:
Type = com.isu.ifm.controller.AppBeforeLstController
Method = public org.springframework.web.servlet.ModelAndView com.isu.ifm.controller.AppBeforeLstController.getAppBeforeLstList(javax.servlet.http.HttpSession,javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.Object>) throws java.lang.Exception
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = jsonView
View = null
Attribute = DATA
value = []
FlashMap:
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = jsonView
Redirected URL = null
Cookies = []
2018-11-27 14:51:15,642 INFO [org.springframework.context.support.GenericApplicationContext::doClose:862] Closing org.springframework.context.support.GenericApplicationContext@6895a785: startup date [Tue Nov 27 14:51:10 KST 2018]; root of context hierarchy
以防万一,这是我使用POSTMAN时的结果。
2018-11-27 15:15:55,635 DEBUG [com.isu.ifm.wrapper.RequestWrapper::<init>:85] URI : /ifm/AppBeforeLst.do
2018-11-27 15:15:55,636 DEBUG [com.isu.ifm.wrapper.RequestWrapper::<init>:86] METHOD : GET
2018-11-27 15:15:55,636 DEBUG [com.isu.ifm.wrapper.RequestWrapper::<init>:126] PARAM : cmd : [getAppBeforeLstList]
enterCd : [ISU_PS]
sabun : [91006]
preHandler ::::::::::::::http://localhost:8083/ifm/AppBeforeLst.do
ISU_PS
91006
preHandler ::::::::::::::/ifm/AppBeforeLst.do
2018-11-27 15:15:55,637 DEBUG [com.isu.ifm.util.Log::Debug:35] ####################com.isu.ifm.controller.AppBeforeLstController.getAppBeforeLstList Start
2018-11-27 15:15:55,638 DEBUG [com.isu.ifm.util.Log::Debug:35] ####################com.isu.ifm.service.AppBeforeLstService.getAppBeforeLstList
[2018-11-27 15:15:55] [DEBUG]『org.apache.commons.dbcp.PoolingDataSource:getConnection(106)』 Elapsed Time [0:00:00.007]
select
1
from
dual
[2018-11-27 15:15:55] [DEBUG]『org.springframework.jdbc.core.JdbcTemplate:query(695)』 Elapsed Time [0:00:00.238]
SELECT DISTINCT DETAIL
, ENTER_CD
, APPL_SEQ
, APPL_CD
, APPL_NM
, APPL_YMD
, APPL_YMD_A
, APPL_SABUN
, AGREE_SABUN
, AGREE_NAME
, APPL_NAME
, APPL_IN_SABUN
, APPL_IN_NAME
, AGREE_YMD
, AGREE_STATUS_CD
, MEMO
, PATH_SEQ
, APPL_STATUS_CD
, APPL_STATUS_CD_NM
, AGREE_SEQ
, GUBUN
, TITLE
, APPL_YMD
FROM (
SELECT '1' AS DETAIL
, A.ENTER_CD
, A.APPL_SEQ
, B.APPL_CD
, C.APPL_NM
, B.APPL_YMD
, TO_CHAR(TO_DATE(B.APPL_YMD,'YYYYMMDD'),'YYYY-MM-DD') AS APPL_YMD_A
, B.APPL_SABUN
, A.AGREE_SABUN
, F_COM_GET_NAMES(A.ENTER_CD,A.AGREE_SABUN) AS AGREE_NAME
, B.APPL_IN_SABUN
, F_COM_GET_NAMES(A.ENTER_CD,B.APPL_SABUN) AS APPL_NAME
, F_COM_GET_NAMES(A.ENTER_CD,B.APPL_IN_SABUN) AS APPL_IN_NAME
, B.AGREE_YMD
, A.AGREE_STATUS_CD
, A.MEMO
, A.PATH_SEQ
, B.APPL_STATUS_CD
, F_COM_GET_GRCODE_NAME(A.ENTER_CD,'R10010',B.APPL_STATUS_CD) APPL_STATUS_CD_NM
, A.AGREE_SEQ
, A.GUBUN
, B.TITLE || decode( B.APPL_CD, '22', ' - ' || F_TIM_GET_APPL_GNT_NM(A.ENTER_CD, A.APPL_SEQ), '') as TITLE
FROM THRI107 A
INNER JOIN THRI103 B
ON B.ENTER_CD = A.ENTER_CD
AND B.APPL_SEQ = A.APPL_SEQ
INNER JOIN THRI101 C
ON C.ENTER_CD = A.ENTER_CD
AND C.APPL_CD = B.APPL_CD
AND C.USE_YN = 'Y'
LEFT OUTER JOIN THRI120 D
ON A.ENTER_CD = D.ENTER_CD
AND A.AGREE_SABUN = D.AGREE_SABUN
AND TO_CHAR(SYSDATE,'YYYYMMDD') BETWEEN D.SDATE AND NVL( D.EDATE, '99991231')
WHERE A.ENTER_CD = 'ISU_PS' /**PARAM*/
AND A.AGREE_STATUS_CD = '10'
AND B.APPL_STATUS_CD IN ('21','31')
AND B.APPL_YMD BETWEEN NVL(TRIM( REPLACE( null /**PARAM*/ ,'-','') ), '00000000') AND NVL(TRIM( REPLACE( null /**PARAM*/ ,'-','')), '99991231')
AND 'Y' = (CASE WHEN B.APPL_STATUS_CD = '31' AND VISUAL_YN = 'N' THEN 'N' ELSE 'Y' END)
AND ( A.AGREE_SABUN = '91006' /**PARAM*/ OR D.DEPUTY_SABUN = '91006' /**PARAM*/ )
AND NVL( A.ORG_APP_YN , 'N' ) = 'N'
UNION ALL
SELECT '1' AS DETAIL
, A.ENTER_CD
, A.APPL_SEQ
, B.APPL_CD
, C.APPL_NM
, B.APPL_YMD
, TO_CHAR(TO_DATE(B.APPL_YMD,'YYYYMMDD'),'YYYY-MM-DD') AS APPL_YMD_A
, B.APPL_SABUN
, A.AGREE_SABUN
, F_COM_GET_NAMES(A.ENTER_CD,A.AGREE_SABUN) AS AGREE_NAME
, B.APPL_IN_SABUN
, F_COM_GET_NAMES(A.ENTER_CD,B.APPL_SABUN) AS APPL_NAME
, F_COM_GET_NAMES(A.ENTER_CD,B.APPL_IN_SABUN) AS APPL_IN_NAME
, B.AGREE_YMD
, A.AGREE_STATUS_CD
, A.MEMO
, A.PATH_SEQ
, B.APPL_STATUS_CD
, F_COM_GET_GRCODE_NAME(A.ENTER_CD,'R10010',B.APPL_STATUS_CD) APPL_STATUS_CD_NM
, A.AGREE_SEQ
, A.GUBUN
, B.TITLE || decode( B.APPL_CD, '22', ' - ' || F_TIM_GET_APPL_GNT_NM(A.ENTER_CD, A.APPL_SEQ), '') as TITLE
FROM THRI107 A
INNER JOIN THRI103 B
ON B.ENTER_CD = A.ENTER_CD
AND B.APPL_SEQ = A.APPL_SEQ
INNER JOIN THRI101 C
ON C.ENTER_CD = A.ENTER_CD
AND C.APPL_CD = B.APPL_CD
AND C.USE_YN = 'Y'
LEFT OUTER JOIN THRI120 D
ON A.ENTER_CD = D.ENTER_CD
AND A.AGREE_SABUN = D.AGREE_SABUN
AND TO_CHAR(SYSDATE,'YYYYMMDD') BETWEEN D.SDATE AND NVL( D.EDATE, '99991231')
WHERE A.ENTER_CD = 'ISU_PS' /**PARAM*/
AND A.AGREE_STATUS_CD = '10'
AND B.APPL_STATUS_CD IN ('21','31')
AND B.APPL_YMD BETWEEN NVL(TRIM( REPLACE( null /**PARAM*/ ,'-','') ), '00000000') AND NVL(TRIM( REPLACE( null /**PARAM*/ ,'-','')), '99991231')
AND 'Y' = (CASE WHEN B.APPL_STATUS_CD = '31' AND VISUAL_YN = 'N' THEN 'N' ELSE 'Y' END)
AND ( A.AGREE_SABUN = null /**PARAM*/ )
AND NVL( A.ORG_APP_YN , 'N' ) = 'Y'
) A
WHERE 1=1
ORDER BY A.APPL_YMD DESC, A.APPL_SEQ DESC
2018-11-27 15:15:55,908 DEBUG [com.isu.dao.Dao::getList:48] ┌────────────────── getAppBeforeLstList Result List Start────────────────────────
2018-11-27 15:15:55,909 DEBUG [com.isu.dao.Dao::getList:74] └────────────────── getAppBeforeLstList Result List End──────────────────────────
2018-11-27 15:15:55,909 DEBUG [com.isu.ifm.util.Log::Debug:35] ####################com.isu.ifm.controller.AppBeforeLstController.getAppBeforeLstList End
2018-11-27 15:15:55,911 DEBUG [com.isu.ifm.wrapper.ResponseWrapper::toByteArray:95] RETURN VALUE : {"DATA":[{"detail":"1","enterCd":"ISU_PS","applSeq":632791,"applCd":"33","applNm":"value","applYmd":"20161030","applYmdA":"2016-10-30","applSabun":"96032","agreeSabun":"91006","agreeName":"","applName":"","applInSabun":"96032","applInName":"","agreeYmd":"","agreeStatusCd":"10","memo":"","pathSeq":null,"applStatusCd":"21","applStatusCdNm":"value","agreeSeq":1,"gubun":"","title":""},{"detail":"1","enterCd":"ISU_PS","applSeq":632790,"applCd":"33","applNm":"value","applYmd":"20161029","applYmdA":"2016-10-29","applSabun":"96032","agreeSabun":"91006","agreeName":"","applName":"","applInSabun":"96032","applInName":"","agreeYmd":"","agreeStatusCd":"10","memo":"","pathSeq":null,"applStatusCd":"21","applStatusCdNm":"value","agreeSeq":1,"gubun":"","title":""},{"detail":"1","enterCd":"ISU_PS","applSeq":632789,"applCd":"33","applNm":"value","applYmd":"20161028","applYmdA":"2016-10-28","applSabun":"96032","agreeSabun":"91006","agreeName":"","applName":"","applInSabun":"96032","applInName":"","agreeYmd":"","agreeStatusCd":"10","memo":"","pathSeq":null,"applStatusCd":"21","applStatusCdNm":"value","agreeSeq":1,"gubun":"","title":""},{"detail":"1","enterCd":"ISU_PS","applSeq":632788,"applCd":"33","applNm":"value","applYmd":"20161027","applYmdA":"2016-10-27","applSabun":"96032","agreeSabun":"91006","agreeName":"","applName":"","applInSabun":"96032","applInName":"","agreeYmd":"","agreeStatusCd":"10","memo":"","pathSeq":null,"applStatusCd":"21","applStatusCdNm":"value","agreeSeq":1,"gubun":"","title":""},{"detail":"1","enterCd":"ISU_PS","applSeq":421788,"applCd":"11","applNm":"value","applYmd":"20130314","applYmdA":"2013-03-14","applSabun":"05080","agreeSabun":"91006","agreeName":"","applName":"value","applInSabun":"05080","applInName":"value","agreeYmd":"","agreeStatusCd":"10","memo":"","pathSeq":null,"applStatusCd":"21","applStatusCdNm":"value","agreeSeq":1,"gubun":"","title":""}]}
[2018-11-27 15:16:01] [DEBUG]『org.apache.commons.pool.impl.GenericObjectPool$Evictor:run(1700)』 Elapsed Time [0:00:00.000]