Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – testing REST controllers


Similarly, we can test the REST-based controllers as well. Just perform the following steps:

  1. Open pom.xml and you will find pom.xml under the root directory of the project itself.

  2. 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.

  3. A Select Dependency window will appear; enter Group Id as com.jayway.jsonpath, Artifact Id as json-path-assert, and Version as 0.8.1. Select Scope as test, click on the OK button, and save pom.xml.

  4. Now create a class called CartRestControllerTest under the com.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.servlet...