reset password
Author Message
Safa Al Mahbub
Posts: 13
Posted 17:32 Oct 25, 2018 |

Hi There, 
Can anyone help me figure why I keep getting an error. I copied over all the dependancies/files that I was supposed to and I have my RESTful Api working with Postman. However when I try to do the MockMvc an error is occurring. I am only testing the get user/1 method. When I run as TestNG Test I always get the following error/stack trace. 

 

[RemoteTestNG] detected TestNG version 6.14.3

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

2018-10-25 17:24:18,181 ERROR RestExceptionHandler General Error

org.springframework.web.util.NestedServletException: Handler dispatch failed

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1006) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) [javax.jar:?]

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:71) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) [javax.jar:?]

at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:166) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:133) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:165) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at springrest.api.controller.UserControllerTest.getUser(UserControllerTest.java:40) [test-classes/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]

at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) [testng-6.14.3.jar:?]

at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:230) [testng-6.14.3.jar:?]

at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:180) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:242) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeMethod(Invoker.java:579) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) [testng-6.14.3.jar:?]

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) [testng-6.14.3.jar:?]

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) [testng-6.14.3.jar:?]

at org.testng.TestRunner.privateRun(TestRunner.java:648) [testng-6.14.3.jar:?]

at org.testng.TestRunner.run(TestRunner.java:505) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.run(SuiteRunner.java:364) [testng-6.14.3.jar:?]

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng-6.14.3.jar:?]

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuites(TestNG.java:1049) [testng-6.14.3.jar:?]

at org.testng.TestNG.run(TestNG.java:1017) [testng-6.14.3.jar:?]

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) [testng-remote.jar:?]

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) [testng-remote.jar:?]

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) [testng-remote.jar:?]

2018-10-25 17:24:18,181 ERROR RestExceptionHandler General Error

org.springframework.web.util.NestedServletException: Handler dispatch failed

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1006) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) [javax.jar:?]

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:71) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) [javax.jar:?]

at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:166) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:133) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:165) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at springrest.api.controller.UserControllerTest.getUser(UserControllerTest.java:40) [test-classes/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]

at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) [testng-6.14.3.jar:?]

at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:230) [testng-6.14.3.jar:?]

at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:180) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:242) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeMethod(Invoker.java:579) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) [testng-6.14.3.jar:?]

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) [testng-6.14.3.jar:?]

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) [testng-6.14.3.jar:?]

at org.testng.TestRunner.privateRun(TestRunner.java:648) [testng-6.14.3.jar:?]

at org.testng.TestRunner.run(TestRunner.java:505) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.run(SuiteRunner.java:364) [testng-6.14.3.jar:?]

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng-6.14.3.jar:?]

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuites(TestNG.java:1049) [testng-6.14.3.jar:?]

at org.testng.TestNG.run(TestNG.java:1017) [testng-6.14.3.jar:?]

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) [testng-remote.jar:?]

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) [testng-remote.jar:?]

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) [testng-remote.jar:?]

2018-10-25 17:24:18,220 WARN ExceptionHandlerExceptionResolver Failed to invoke @ExceptionHandler method: public org.springframework.http.ResponseEntity<java.lang.Object> springrest.api.error.RestExceptionHandler.handleOtherExceptions(java.lang.Exception)

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;

at org.springframework.http.server.ServletServerHttpResponse$ServletResponseHttpHeaders.getFirst(ServletServerHttpResponse.java:142) ~[spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:868) ~[spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:216) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:224) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82) ~[spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:404) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:61) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1255) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.TestDispatcherServlet.processHandlerException(TestDispatcherServlet.java:133) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1062) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) [javax.jar:?]

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:71) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) [javax.jar:?]

at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:166) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:133) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:165) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at springrest.api.controller.UserControllerTest.getUser(UserControllerTest.java:40) [test-classes/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]

at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) [testng-6.14.3.jar:?]

at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:230) [testng-6.14.3.jar:?]

at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:180) [spring-test-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:242) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeMethod(Invoker.java:579) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) [testng-6.14.3.jar:?]

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) [testng-6.14.3.jar:?]

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) [testng-6.14.3.jar:?]

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) [testng-6.14.3.jar:?]

at org.testng.TestRunner.privateRun(TestRunner.java:648) [testng-6.14.3.jar:?]

at org.testng.TestRunner.run(TestRunner.java:505) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) [testng-6.14.3.jar:?]

at org.testng.SuiteRunner.run(SuiteRunner.java:364) [testng-6.14.3.jar:?]

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng-6.14.3.jar:?]

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) [testng-6.14.3.jar:?]

at org.testng.TestNG.runSuites(TestNG.java:1049) [testng-6.14.3.jar:?]

at org.testng.TestNG.run(TestNG.java:1017) [testng-6.14.3.jar:?]

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) [testng-remote.jar:?]

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) [testng-remote.jar:?]

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) [testng-remote.jar:?]

FAILED: getUser

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I

at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1079)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)

at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:71)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:166)

at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:133)

at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:165)

at springrest.api.controller.UserControllerTest.getUser(UserControllerTest.java:40)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)

at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:230)

at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:180)

at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:242)

at org.testng.internal.Invoker.invokeMethod(Invoker.java:579)

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)

at org.testng.TestRunner.privateRun(TestRunner.java:648)

at org.testng.TestRunner.run(TestRunner.java:505)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)

at org.testng.SuiteRunner.run(SuiteRunner.java:364)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)

at org.testng.TestNG.runSuites(TestNG.java:1049)

at org.testng.TestNG.run(TestNG.java:1017)

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================

    Default test

    Tests run: 1, Failures: 1, Skips: 0

===============================================

===============================================

Default suite

Total tests run: 1, Failures: 1, Skips: 0

===============================================

Victor
Posts: 23
Posted 02:07 Oct 26, 2018 |

Based on the error message, I found this solution: https://stackoverflow.com/questions/44730096/javax-servlet-http-httpservletresponse-getstatus-not-found

If that doesn't work, please upload your test code for further debugging.

Good luck.