Posts

Contract Tests with Spring Cloud Contract

Contract tests has a lot of significance and value in Micorservices world. You can keep fixing your end to end or integration tests, which runs very late in the build, are difficult to debug and cost lot of resources to maintain. Component tests are good for testing integration between the various components of an API. However, in microservices world there are a number of APIs that serves different/unique purposes and are part of an application/system. Component tests alone can’t assure that integration between micorservices is working fine. In case of Integration tests, testing  a change in one API can lead to horrible time consuming process of setting up all the APIs, databases, brokers etc. Using Docker instances and Docker compose for orchestration makes things a little easier, however, it comes with a cost of maintaining your docker images and docker-compose files. Contract tests not only ensures that two APIs will behave nicely with each other, they also fail fast.

Hibernate Difference between update() and merge()

Image
In order to explain the difference between update and merge, I have created an example, which you can execute or just read it to understand the difference. 1. First Create a database medireports: (DB=MySQL) CREATE DATABASE `medireports` 2. Now Create a 'reports' table: CREATE TABLE `reports` ( `reportid` varchar(20) NOT NULL, `report` mediumblob, `phonenumber` bigint(20) NOT NULL, `labid` varchar(45) DEFAULT NULL, `retainreport` varchar(45) DEFAULT NULL, `reportdate` date DEFAULT NULL, `filename` varchar(65) DEFAULT NULL, PRIMARY KEY (`reportid`) ) 3. Insert data into the reports table: INSERT INTO `medireports`.`reports`(`reportid`,`phonenumber`,`retainreport`,`reportdate`,`filename`) VALUES ('ZL1234', '9999666222', '0', '2014-03-13', 'jqModal.js'); INSERT INTO `medireports`.`reports`(`reportid`,`phonenumber`,`retainreport`,`reportdate`,`filename`) VALUES ('ZL123456&

Spring Security - Adding more information to the authenticated user.

I was using spring Security to perform authentication against the database and I needed to load the user information once the user gets authenticated. However, the spring org.springframework.security.core.userdetails.User object was not allowing me add more details to the logged in User object. In my case, I had to add phone number to the authenticated user. In the following section I'll show as to how to add additional information to the authenticated user. Create an object to contain the additional information. We will first create a MediUser object which will extend the Spring org.springframework.security.core.userdetails.User object. The MediUser object contains additional information like first name, middle name, last name, phone number and alternative phone number. Following is the code for MediUser : import java.util.Collection; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.

Running tomcat maven plugin in Debug mode (in STS, Eclipse and MyEclipse)

Image
Over here I'll explain, as to how to run a tomcat maven plugin in debug mode, in Eclipse and Spring Tool Source (STS). It will be a three step setup and once you are done with the setup, you can run the tomcat server in debug mode with just one click. Following are the setup steps: Step 1 : Entering maven dependency for tomcat in pom.xml file Step 2 : Creating debug configuration Step 3 : Running tomcat server in debug mode Step 1: Entering maven dependency for tomcat in pom.xml file Open your pom.xml file. Enter the tomcat plugin dependency, as shown in the following figure: Now right click on the pom.xml and select Run As à Maven Install . Step 2 :  Creating Debug Configuration Right click on pom.xml and select Debug As à Debug Configurations… A Debug Configurations window will open, as shown in the following figure: On the left hand window right click on Maven Build , as a result, following screen will get displayed:

Dynamic Dialog Boxes

Image
The Basic problem with Dialog Boxes Almost all the web applications use dialog boxes to popup a message to the user or confirm for an action taken by the user. Most of the time we end up using JavaScript for such kind of dialog boxes. And most of the time our purpose gets solved with JavaScript alerts/dialog boxes. However when we have a slightly different request, JavaScript fails to support those requests. For example, client might ask for a Yes/No dialog box instead of Ok/Cancel and JavaScript fails to support this. You can still achieve Yes/No in javascript, however it will have limitations, such as it will work with IE only and it will display VBscript at the title bar of the dialog box. Let’s take another example, where in the client wants to have three buttons on the dialog box. Again javascript fails to support this functionality.  Another example, where in the client wants to have dynamic look and feel , or a look and feel matching the application in context; again ja

Measuring Code Quality using IBM RAD's Software Analyzer

Image
In case you are using IBM RAD for your development. There is very good built in tool, which helps you to measure the quality of the code. It does a good analysis of the code and gives suggestions to improve it. It is a kind of static profiling, It can profile your code in lot many ways, however, one of the most important is or which I liked is Performance. You can profile your code for memory usage and speed, Interesting na...... It will let you know, as to what should be avoided in the code and how it should be coded properly. The good thing is that you can use it to profile a single java file, or a java package, or an entire project. I'm attaching a document specifying how to use it for Performance. There are plugins like PMD and Find Bug etc, which performs similar analysis. However, they are plugins not build in fuctionalities, and you are free to choose these plugins into your RAD. This document will help you to use Software Analyzer plug-in available in RAD