Skip to main content

Posts

Showing posts with the label spring

Mock unit testing with Mockito and Spring (Ejb and Rest service)

In this tutorial we are going to learn about mock unit testing. We are using here Mockito with Spring to write unit tests. We will also see how to mock an EJB session bean inside mocked service without constructor/setters injection. What is mocking Mocking is a technique to replace the actual implementation with some dummy or provided code chunk during unit testing. For example if we need to unit test some service which persist data to database then we can mock that persist method to add it to some in-memory collection. Also we can mock data retrieval to get the data from same collection or so. Mockito provide various class and features to implement the mocking seamlessly. Maven dependency We are using Spring (XML base configuration) and mockito for mock testing. Below dependencies are required. <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.9.RELEASE</ver...

Distributed configuration using spring cloud config

What is spring cloud config Spring cloud config helps application in externalising the configuration properties in a server/client model. Which means there is a config server where all client application connects and read the properties related to their application. Properties can be accessed basis on application name and configured profile. It supports resource based configuration using GIT repository or local file system over HTTP. Properties are managed in form of key-value pair. Though it easily integrate with spring boot application but can be used by any application in other languages also as properties can be accessed through REST URLs also. We are going to learn below things here. GIT repository for configuration management Cloud config server Config client GIT Repository Here we are going to use GIT for configuration management which will be configured in config server. Setting up a GIT repository is very easy. We have to create the properties file using some na...