This week I had to dig deeper into the world of Single sign-on. I learnt a lot of things about it from basic conceptual knowledge to how to setup your own Single sign-on server with Spring Boot. In this post, I will share my learnings with you. In case something is not clear please leave a comment and I will address it.
Over the last year, I have worked with many teams using Spring Boot with Angular/React for developing Java web applications. I consider Spring Boot a pragmatic opinionated way to build Spring applications. Spring Boot makes it easy to build web applications in Java and provides a productive environment for development.
Today, a colleague asked me to help him write a REST API integration test. We use Spring’s MockMvc API to test the REST API. The application uses MongoDB with Spring Data MongoDB. The application uses both MongoTemplate and Mongo based repositories for working with MongoDB. To make tests work independent of MongoDB, we mock Spring MongoDB repository interfaces.
Today a colleague asked me how he could unit test a Spring MVC REST resource. I am using Spring MVC test support for some time now so the obvious answer was to use
MockMvc. In case you have not used
MockMvc, it allows you to declaratively write tests for your Spring MVC controllers. Rather than calling controllers directly, you use the MockMvc fluent API to make a request to a URL and verify the response returned by the API. You can read Spring MVC documentation to learn about MockMvc in detail.
I am a big fan of Spring Boot. It is my preferred choice for building REST APIs in Java. It takes less than 5 minutes(given that you have Maven dependencies on your local machine) to get started with Spring Boot thanks to its auto configuration. In this blog, I will talk about a specific aspect of building REST API with Spring Boot. We will look at the request and response objects. The request object that you receive during the HTTP POST request and response object that you send in the response of HTTP GET request. I will discuss how you can keep these request and response objects to the bare minimum so that we can avoid writing and maintaining useless getters and setters.