Time for action – testing REST controllers
Similarly, we can test the REST-based controllers as well. Just perform the following steps:
- Open
pom.xml
and you will findpom.xml
under the root directory of the project itself. - You will be able to see some tabs at the bottom of the
pom.xml
file; select the Dependencies tab and click on the Add button of the Dependencies section. - A Select Dependency window will appear; enter Group Id as
com.jayway.jsonpath
, Artifact Id asjson-path-assert
, and Version as0.8.1
. Select Scope astest
, click on the OK button, and savepom.xml
. - Now create a class called
CartRestControllerTest
under thecom.packt.webstore.controller
package in the source folder,src/test/java
. Now add the following code to it:package com.packt.webstore.controller; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web...