stealthrabbi / spring-boot-mvc-test

A Test Spring Boot application that uses Spring MVC Controllers and unit tested.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-boot-mvc-test

A Test Spring Boot application that uses Spring MVC Controllers and is unit tested.

There's also an example of populating a spring bean with values from a properties file (AppPropertiesContainer).

unit test result badge

Build and Test

Dependencies

All dependencies are managed in the build.gradle file.

Explanation of Code

This is a Spring Boot application. AppBootMain contains the main function that builds the application as a Spring Boot web app.

The domain_model package has a simple POJO class that gets returned by the Controller.

The data_repository package has a simple Repository class and interface representing a data store. The concreate class just contains a static list of objects. The interface exists so the dependency can be mocked using Mockito.

The web_controllers package contains Spring MVC Controllers that map REST URIs to methods that return objects.

View the test package to see Spring Tests for the Controllers. AbstractSpringTest is a simple base class to be used for all unit tests for spring managed classes. AbstractControllerTest sets up a MockMvc to invoke calls on the REST interface. StudentControllerTest tests the StudentController Controller. It creates a mockito mock for the StudentRepository and injects it in to the controller. MockMvc is used to invoke calls on the REST interface and check returned JSON values.

About

A Test Spring Boot application that uses Spring MVC Controllers and unit tested.


Languages

Language:CSS 52.3%Language:Java 45.3%Language:HTML 1.4%Language:JavaScript 0.9%