Tuesday, April 21, 2015

JUnit: Testing Exceptions with Java 8 and AssertJ 3.0.0

AssertJ 3.0.0 release for Java 8 makes testing exceptions much easier than before. In one of my previous blog post I described how to utilize plain Java 8 to achieve this, but with AssertJ 3.0.0 much of the code I created may be removed.

Warning: this blog post contains mostly the code examples.

JAX-RS 2.x vs Spring MVC: Returning an XML representation of a list of objects

JSON is King as it goes to all kinds of REST* APIs, but still you may need to expose multiple representations, including XML. With both JAX-RS and Spring MVC this is very simple. Actually, the only thing to do is to annotate POJOs returned from the API call with JAXB annotation and that’s it.

But when it goes to serializing a list of objects, JAX-RS will do a bit better than Spring MVC, in my opinion. Let’s see.

Monday, April 20, 2015

Jenkins HOW-TO: build a project from multiple (Git) repositories

Recently I have been working on a project that has two main modules: Backend and Frontend. The Backend is a Spring Boot application and the Frontend is an AngularJS 1.3 application. While preparing the build we are using Grunt for building AngularJS code and Gradle for building the Spring Boot application. Grunt is creating a JAR file containing all resources and copies it to Spring Boot application. Then Gradle takes the JAR and adds it to the resulting WAR. Long story made short.

Both Backend and Frontend are different Git repositories, initially managed by different teams. Both needs to be checked to the same root folder, so the building process will properly run. In order to do the it on Jenkins, Multiple SCMs Plugin Jenkins plugin can be used. The plugin simplifies the configuration of such a build.

Wednesday, March 11, 2015

Spring Boot Integration Testing with Selenium

Web integration tests allow integration testing of Spring Boot application without any mocking. By using @WebIntegrationTest and @SpringApplicationConfiguration we can create tests that loads the application and listen on normal ports. This small addition to Spring Boot makes much easier to create integration tests with Selenium WebDriver.

Saturday, February 21, 2015

Friday, February 20, 2015

Openshift: Build Spring Boot application on Wildfly 8.2.0 with Java 8


OpenShift DIY cartridge is a great way to test unsupported languages on OpenShift. But it is not scalable (you can vote for Scalable DIY cartridge here) which makes it hard to use with production grade Spring Boot applications. But what if we deployed Spring Boot application to WildFly Application Server? Spring Boot can run with embedded servlet container like Tomcat or much faster Undertow, but it also can be deployed to a standalone application server. This would mean that it can be also deployed to WildFly application server that is supported by OpenShift. Let’s see how easy is to get started with creating a Spring Boot application from scratch and deploy it to WildFly 8.2 on OpenShift.

Tuesday, February 10, 2015

OpenShift DIY: Build Spring Boot / Undertow application with Gradle


Gradle 1.6 was the last supported Gradle version to run on OpenShift due to this bug. But as of Gradle 2.2 this is no more an issue, so running newest Gradle on OpenShift should not be a problem anymore with Do It Yourself cartridge. DIY cartridge is an experimental cartridge that provides a way to test unsupported languages on OpenShift. It provides a minimal, free-form scaffolding which leaves all details of the cartridge to the application developer.

This blog post illustrates the use of Spring Boot 1.2 and Java 8 running on Undertow, that is supported as a lightweight alternative to Tomcat. It should not take more than 10 minutes to get up and running.