Skip to main content

Posts

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</version>…
Recent posts

CORS implementation using Java Filter

What is CORS CORS is cross origin resource sharing which allows or block the cross domain calls from a web application between different domains. By default you are able to make Ajax calls to other domain. To enable it that provider also need to add certain headers to allow the requester domain.
CORS Headers Below are the required headers to implement the CORS.
Access-Control-Allow-Origin In this header we specify the domain from which we want to allow the access, for example: example.com. Access-Control-Allow-Credentials This header specifies if it can pass authorization details in cross domain request. for example: true/false. Access-Control-Max-Age We can use this header to specify how long we want to cache the preflight request details like allowed methods, allowed headers etc. We can specify value in seconds and we can cache them for a long time as such details are not change frequently. Access-Control-Allow-Methods Here we specify the methods we want to allow for request, for ex…

Spring boot retry tutorial

Spring Retry API Spring provides spring-retry API for running business logic with retry options and recovery method or operations. In this tutorial we will learn the usage of all these with example. We are using Spring boot application here for our example code.
Maven dependencies To use spring retry we need below dependencies.
spring-retry This API provides many annotations which we can use in a declarative manner to implement the same.
<dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> <version>1.2.5.RELEASE</version> </dependency> spring-boot-starter-aop Spring AOP is also required for retry implementation.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> Retry implementation To implement retry w…

XML Validation using XSD schema

We are going to validate XML using XSD schema in Java. We will create XML Schema using XSD and then use same schema to create the XML file. Then we will write our code to validate this XML against same schema.
XSD Schema creation Below is our schema where we are defining the Schema for XML elements. In this schema we creating two elements, one for request and another for response. We are publishing this schema using targetNamespace which we will use during XML creation.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://services.ttj.com/hello-service" targetNamespace="http://services.ttj.com/hello-service" elementFormDefault="qualified"> <xs:element name="sayHelloRequest"> <xs:complexType> <xs:sequence> <xs:element name="userName" type="xs:string"/> </xs:sequence> </xs:compl…

Setting up ReactJS for development and deployment

In this tutorial we will learn how to create a react application.
Softwares required for ReactJS We need to install below softwares for react development.
Visual studio code This software is free and can be downloaded from https://code.visualstudio.com/download.
Once downloaded, extract the zip  and place the binary under "Applications" and allow app access from System Preferences -> Security & privacy.
Node.JS and NPM Node.JS provides a java script enabled environment to run on a web server. It eases our development for UI based applications. NPM is a package manager which installs along with Node.jS and helpful in installing packages and libraries.
Install Node.JS and NPM using brew.
brew install node Check version of Node and NPM using below command.
node -v npm -v Create React application To create react application we will first install the required package and latter will use it to create our ReactJS application.
Install create-react-app package Execute below co…

Soap over JMS with Spring boot, CXF and Active MQ

Soap over JMS comes with several benefits like, asynchronous processing, one time delivery, assured delivery. This paradigm is mainly used internally in an organization (service providers and clients).
In this tutorial we are going to use Spring boot and Apache CXF to develop a Soap service and then use Active MQ to make it work as "Soap Over JMS".
Creating Soap service using Spring boot and Apache CXF It is very easy to develop a Soap service with Spring boot. We will follow contract first approach to develop the service. We will create a XML schema & use jaxb2 plugin to generate necessary schema classes and then implement the service using them. Please refer below post where it explains in detail, how to develop a Soap service using Spring boot and CXF.
https://www.thetechnojournals.com/2020/01/soap-services-with-spring-boot-and.html
Implementing Soap over JMS To implement the Soap over JMS we need to integrate JMS with soap service where our service listens to a reque…

SOAP service development using Spring boot and Apache CXF

In this tutorial we are going to learn how to develop a SOAP web service using Spring boot and Apache CXF. We will follow the contract first approach to develop our service where we will use jaxb2 maven plugin to generate the java classes which we will use for service implementation.
Why contract first With contract first our primary focus stays with the contract of service to be implemented. Also it is useful to match the input/output with business requirement. We can share the contract with other business units/ customers or users, so it helps them to start early without waiting for the complete implementation. Once our contract is ready we can generate the Java classes using jaxb plugin which generates the java objects using the schema for SOAP contract and we need to focus only on service implementation.
SOAP service development (Hello service) This service will have one operation where user can send their name and in response they will get a hello message with the passed name.
H…