当我使用POSTMAN测试REST API端点时,它工作正常。这是控制台消息。
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}
但是当我尝试使用带有MockMVC的jUnit测试相同的端点时,它会获取参数,但无法在查询中映射。
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
这是我的测试用例代码。
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));
}
如果我故意将enterCd设置为NULL,则会收到以下消息。
[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")
但是如上所述,使用jUnit时,所有参数都设置为“?”
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")
]
谁能告诉我这是怎么回事? 任何帮助将不胜感激。