mercredi 14 novembre 2018

MockMVC not mapping query parameters

When I test REST API endpoints using POSTMAN, It works fine. This is the console message.

    path : -1
****** doFilter!!!!!!!!!!!!!!!!!!!
2018-11-15 10:52:56,949 DEBUG [com.isu.ifm.wrapper.RequestWrapper::<init>:85] URI : /ifm/Board.do
2018-11-15 10:52:56,949 DEBUG [com.isu.ifm.wrapper.RequestWrapper::<init>:86] METHOD : GET
2018-11-15 10:52:56,950 DEBUG [com.isu.ifm.wrapper.RequestWrapper::<init>:126] PARAM : comments : [a]
enterCd : [ISU_PS]
bbsCd : [10003]
bbsSeq : [1]
cmd : [saveCmt]
sabun : [91006]

preHandler ::::::::::::::http://localhost:8083/ifm/Board.do
ISU_PS
91006
preHandler ::::::::::::::/ifm/Board.do
[2018-11-15 10:52:56] [DEBUG]『org.apache.commons.dbcp.PoolingDataSource:getConnection(106)』 Elapsed Time [0:00:00.007]

    select
        1 
    from
        dual


[2018-11-15 10:52:56] [DEBUG]『org.springframework.jdbc.core.JdbcTemplate:execute(644)』 Elapsed Time [0:00:00.023]


                        INSERT INTO TSYS730(ENTER_CD, SABUN, BBS_SEQ, COMMENTS_SEQ, COMMENTS, CHKDATE, CHKID, BBS_CD)
                        VALUES( 'ISU_PS' /**PARAM*/,  '91006' /**PARAM*/,  '1' /**PARAM*/, BOARD_COMTSEQ.nextval,  'a' /**PARAM*/, sysdate,  '91006' /**PARAM*/,  '10003' /**PARAM*/)



Query Result[INSERT]: 1row

2018-11-15 10:52:56,984 DEBUG [com.isu.ifm.wrapper.ResponseWrapper::toByteArray:95] RETURN VALUE : {"message":"","map":{"comments":"a","enterCd":"ISU_PS","bbsCd":"10003","bbsSeq":"1","cmd":"saveCmt","sabun":"91006","ssnEnterCd":"ISU_PS","ssnSabun":"91006"},"code":1}

But when I try to test same endpoints using jUnit with MockMVC, it gets parameters but cannot map in query.

    2018-11-15 10:49:19,669 DEBUG [com.isu.dao.Dao::getList:48] ┌────────────────── getCmtList Result List Start────────────────────────
2018-11-15 10:49:19,670 DEBUG [com.isu.dao.Dao::getList:74] └────────────────── getCmtList Result List End──────────────────────────

MockHttpServletRequest:
         HTTP Method = GET
         Request URI = /Board.do
          Parameters = {cmd=[getCmtList], enterCd=[ISU_PS], sabun=[91006], bbsCd=[10001], bbsSeq=[1]}
             Headers = {}

             Handler:
                Type = com.isu.ifm.controller.BoardController
              Method = public org.springframework.web.servlet.ModelAndView com.isu.ifm.controller.BoardController.getCmtList(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 = []
           Attribute = Message
               value = 

            FlashMap:

MockHttpServletResponse:
              Status = 200
       Error message = null
             Headers = {}
        Content type = null
                Body = 
       Forwarded URL = jsonView
      Redirected URL = null
             Cookies = []
2018-11-15 10:49:19,706  INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter::initControllerAdviceCache:517] Looking for @ControllerAdvice: org.springframework.test.web.servlet.setup.StubWebApplicationContext@39c1fe0b
2018-11-15 10:49:19,753 ERROR [org.anyframe.query.QueryService::processException:1889] Query Service : Fail to [update [query id = 'saveCmt'], 

                        INSERT INTO TSYS730(ENTER_CD, SABUN, BBS_SEQ, COMMENTS_SEQ, COMMENTS, CHKDATE, CHKID, BBS_CD)
                        VALUES(:ssnEnterCd, :ssnSabun, :bbsSeq, BOARD_COMTSEQ.nextval, :comments, sysdate, :ssnSabun, :bbsCd)


            , PreparedStatementCallback; SQL [

                        INSERT INTO TSYS730(ENTER_CD, SABUN, BBS_SEQ, COMMENTS_SEQ, COMMENTS, CHKDATE, CHKID, BBS_CD)
                        VALUES(?, ?, ?, BOARD_COMTSEQ.nextval, ?, sysdate, ?, ?)


            ]; ORA-01400: cannot insert NULL in ("EHR_ISU4"."TSYS730"."ENTER_CD") 
; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL in ("EHR_ISU4"."TSYS730"."ENTER_CD") 
].
 Query = [org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [

                        INSERT INTO TSYS730(ENTER_CD, SABUN, BBS_SEQ, COMMENTS_SEQ, COMMENTS, CHKDATE, CHKID, BBS_CD)
                        VALUES(?, ?, ?, BOARD_COMTSEQ.nextval, ?, sysdate, ?, ?)


            ]; ORA-01400: cannot insert NULL in ("EHR_ISU4"."TSYS730"."ENTER_CD") 
; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL in ("EHR_ISU4"."TSYS730"."ENTER_CD")
] 
 Reason = [{}].

MockHttpServletRequest:
         HTTP Method = GET
         Request URI = /Board.do
          Parameters = {cmd=[saveCmt], enterCd=[ISU_PS], sabun=[91006], bbsCd=[10001], bbsSeq=[1], comments=[a]}
             Headers = {}

             Handler:
                Type = com.isu.ifm.controller.BoardController
              Method = public org.springframework.web.servlet.ModelAndView com.isu.ifm.controller.BoardController.saveCmt(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 = code
               value = -1
           Attribute = message
               value = fail
           Attribute = map
               value = {cmd=saveCmt, enterCd=ISU_PS, sabun=91006, bbsCd=10001, bbsSeq=1, comments=a, ssnEnterCd=null, ssnSabun=null}

            FlashMap:

MockHttpServletResponse:
              Status = 200
       Error message = null
             Headers = {}
        Content type = null
                Body = 
       Forwarded URL = jsonView
      Redirected URL = null
             Cookies = []
2018-11-15 10:49:19,788  INFO [org.springframework.context.support.GenericApplicationContext::doClose:862] Closing org.springframework.context.support.GenericApplicationContext@9660f4e: startup date [Thu Nov 15 10:49:14 KST 2018]; root of context hierarchy

Here is my testcase code.

    public MockMvc mockMvc;

public void testGetMethod_param(String url, UnaryOperator<MockHttpServletRequestBuilder> operator)
            throws Exception {
        mockMvc.perform(operator.apply(get(url))).andDo(print()).andExpect(status().isOk());
    }




 @ContextConfiguration("file:src/main/webapp/WEB-INF/**/*.xml")
public class BoardControllerTest extends HttpRequestTestMethod implements CoreParameters, AdapterServiceParameters{

    @Autowired
    public BoardController boardController;


    @Before
    public void setUp() throws Exception {
        mockMvc = MockMvcBuilders.standaloneSetup(boardController).build();
    }
    @Test
    public void savecmt() throws Exception {
        testGetMethod_param("/Board.do", builder->builder
                .param("cmd", "saveCmt")
                .param("enterCd", enterCd)
                .param("sabun", sabun)
                .param("bbsCd", bbsCd)
                .param("bbsSeq", bbsSeq)
                .param("comments", comments));
    }

If I deliberately set enterCd to NULL, I get this following message.

[2018-11-15 11:06:02] [ERROR]『oracle.jdbc.driver.T4CTTIoer:processError(439)』
java.sql.SQLIntegrityConstraintViolationException


                        INSERT INTO TSYS730(ENTER_CD, SABUN, BBS_SEQ, COMMENTS_SEQ, COMMENTS, CHKDATE, CHKID, BBS_CD)
                        VALUES( null /**PARAM*/,  '91006' /**PARAM*/,  '1' /**PARAM*/, BOARD_COMTSEQ.nextval,  'a' /**PARAM*/, sysdate,  '91006' /**PARAM*/,  '10003' /**PARAM*/)



ORA-01400: cannot insert Null in ("EHR_ISU4"."TSYS730"."ENTER_CD")

But as attached above, when using jUnit, all parameters are set to "?"

Query = [org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [

                        INSERT INTO TSYS730(ENTER_CD, SABUN, BBS_SEQ, COMMENTS_SEQ, COMMENTS, CHKDATE, CHKID, BBS_CD)
                        VALUES(?, ?, ?, BOARD_COMTSEQ.nextval, ?, sysdate, ?, ?)


            ]; ORA-01400: cannot insert Null in ("EHR_ISU4"."TSYS730"."ENTER_CD") 
; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert Null in ("EHR_ISU4"."TSYS730"."ENTER_CD") 
] 

Can anyone tell me what is wrong here? Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire