Wednesday, December 9, 2015

org.postgresql.util.PSQLException: This connection has been closed in Spring Boot

In Spring Boot data source connection pooling is auto-configured if a proper JDBC Driver is used (e.g. org.postgresql.Driver) and by default Tomcat pooling is used - although it can be easily changed). But the default configuration may not be enough in the production environment. One of the issues I had was org.postgresql.util.PSQLException: This connection has been closed exception after Postgres database was restarted while the application was running. In order to restore the connection application restart is needed.

Sunday, November 29, 2015

Learn REST with Spring

The popularity of REST-style APIs is not decreasing so a good knowledge in this architecture style becomes essential in many projects. In Java, there are many frameworks that you as a developer can utilize in order to build a REST-style API, with Spring MVC as one of the most popular. If you wish to learn how to work effectively with REST in Spring you definitely need some good learning materials.

Saturday, November 28, 2015

Wednesday, November 25, 2015

HOW-TO: Register components using @Conditional and Condition in Spring

@Profile annotation in Spring can be used on any Spring components (e.g. @Component, @Service, @Configuration etc.) that are candidates for auto-detection. @Profile annotation accepts a single profile or a set of profiles that must be active in order to make the annotated component eligible for auto-detection. For a given @Profile({"p1", "!p2"}), registration will occur if profile p1 is active or if profile p2 is not active. The or is crucial here.

But how to achieve this with @Profile: we want to activate a given component if profile p1 is active and if profiles p2 and p3 are both inactive?

Wednesday, November 11, 2015

Thursday, October 1, 2015

Different ways of testing exceptions in Java and JUnit [Link]

Exception testing with Java and JUnit is one of the topics that got quite some attention on my blog. Therefore I gathered some of my previous articles in this topic, revised them and created a new article on my company’s blog. It is a compilation of practices for testing exceptions with Java and JUnit. Find out how to use @Test annotation with expected attribute, JUnit ExpectedException rule and AssertJ 3+ in one extensive article with lots of examples

Please read the full article here: Different ways of testing exceptions in Java and JUnit.

Tuesday, September 29, 2015

${... } placeholders support in @Value annotations in Spring

${...} placeholders in @Value annotation are used to access properties registered with @PropertySource. This is extremely useful with @Configuration beans in Spring applications, but not only. To be sure that this is possible, PropertySourcesPlaceholderConfigurer must be present in all application contexts that placeholders resolution is required.

In this blog post you will learn how to configure placeholders resolution in Spring 4 applications and how to inject different types of objects using @Value annotation, including JSR-310 Date-Time, JSR-354 Money & Currency or java.util.Optional.

Wednesday, September 16, 2015

AssertJ's SoftAssertions - do we need them?

One of the rules of writing good unit test is that it should fail for one reason, so unit test should test one logical concept. Sometime it is quite tough to have a single assertion per test. To follow the rule, we may have having multiple assertions per object in a single test.

The problem with multiple assertions in a single test though, is that if the first one fails for any reason we actually don’t know about other assertions as they will not be executed. And you know the drill: you check assertion failure reason, you fix it and re-run the test. Maybe you are lucky and the test will pass. But maybe it will fail with another assertion. With really fast unit tests this is not a big issue but when it comes to, for example, Selenium tests analysis and failure detection can become cumbersome and for sure time consuming.

Fortunately, we can re-think the way we create assertions in our tests thanks to AssertJ’s SoftAssertions.

Monday, September 14, 2015

Override Spring Framework version in Spring Boot application built with Gradle

If you want to use or just check the newest version of Spring with Spring Boot but the current Spring Boot version depends on an older Spring version you need to adjust your Gradle build configuration slightly.

For example, as of time of writing this blog post, Spring 4.2.1 and Spring Boot 1.2.5 were current versions. Spring Boot 1.2.5 depends on Spring 4.1.7. So what to do to in order to use Spring 4.2.1 with Spring Boot 1.2.5? Have a look at two ways of achieving this: with and without Spring IO Platform.

Wednesday, September 9, 2015

Selenium + Firefox on Windows 10 - get rid of the Windows 10 intro URL being loaded

Recently I moved to Windows 10 and upgraded to the newest Firefox. When I executed my integration tests on my PC with Selenium and Firefox for the first time I saw an extra page was loaded: “Firefox + Windows 10. Perfect together.” Maybe for you - I said to myself - and I immediately looked how to disable it.

Tuesday, August 18, 2015

Parameterized integration tests with Spring JUnit Rules

Spring 4.2 comes with brand new JUnit rules: SpringClassRule and SpringMethodRule. The main advantage of using JUnit rules is to let developers get rid of SpringJUnit4ClassRunner and utilize different JUnit runners in Spring integration tests. I think the biggest opportunity with Spring JUnit Rules is the ease of creating parameterized integration tests.

Wednesday, July 1, 2015

Sahi Script Samples from my presentation at TrojQA

Sahi is an web automation tool that can be used to test modern web applications in a variety of browsers. Sahi comes in two flavors: open-source and commercial. Some of the key Sahi features include:

  • recording on most modern browsers - including Internet Explorer,
  • automatic AJAX waits
  • easy to learn and robust scripting - Sahi Script
  • built-in tools like reporting, logging etc.

This blog post contains some code snippets of Sahi Script that I presented during my talk at TrojQA in 2015. TrojQA is a Tricity (Poland) community focused on software testing and quality assurance.

If you are interested in learning more about Sahi, please visit its official website here: http://sahipro.com/.

Sahi Script

Sahi Script is a scripting language based on JavaScript. The main difference from JavaScript is that in Sahi Script variables must be prefixed with $.

_include("StringUtils.js")
var _system = (function () {
    var getenv = function ($name, $default) {
        var $env = java.lang.System.getenv($name);
        if ($env == null && $default) {
            return $default;
        }
        return $env;
    };
    var os = function () {
        var $os = java.lang.System.getProperty("os.name");
        return $os;
    };
    return {
        getenv: getenv,
        os: os
    }
})(); 

The snippet above creates a module that can be used in retrieving system properties (using Java code).

Sahi API

The power of Sahi Scripts is a Sahi API. Sahi API, among others, allows accessing elements on the browser and interact with them (Accessor API and Action API). To learn more about Sahi API please visit: http://sahipro.com/docs/sahi-apis/index.html.

Basics

Let’s have a look at a really basic script:

_navigateTo("http://themicon.co/theme/angle/v2.4/backend-angular/#/app/dashboard");
_assertEqual(1700, _getText(_div(0, _near(_div("Uploads")))));

The script is self exploratory and it instructs Sahi to do the following:

  • vavigate to a given URL
  • assert that the text in the first div that is located near div with the text Uploads is equal to 1700

Tables

While working with tables the Sahi API is really handy mostly due to well named methods and the relation API. The relation API allows matching elements that are related to each other. With tables this is extremely useful.


// find a table header with a given text
_highlight(_tableHeader("CSS grade"));

// find a table header with a given text within a concrete table
_highlight(_tableHeader("Platform(s)"), _in(_table("datatable1")));

// find a cell containing a text within a concrete table
_highlight(_cell("Gecko"), _in(_table("datatable1")));

// assert that table header's attribute is not empty
_assert(_tableHeader("Rendering engine").getAttribute("aria-sort") != "");

// compare text of the first row
_assertEqual("Gecko Firefox 1.0 Win 98+ / OSX.2+ 1.7 A", _getText(_row(1)));

// scrolling with JavaScript
_call(_div("Demo Table #2").scrollIntoView());

// fancy finding a checkbox within a table
_click(_span("fa fa-check", _near(_cell(/Holly Wallace/), _in(_table("table-ext-2")))));

Forms

Accessing and interacting with HTML form elements is


// click the link near a label containing a given text
_click(_link(0, _near(_label("Email:"))));
// set a value of email field
_setValue(_emailbox("Email:"), "john@doe.com");
// click submit button near email field
_click(_submit("btn btn-success btn-sm", _near(_emailbox("Email:"))));

// some other fields

_setValue(_telephonebox("Tel:"), "000-00-00");
_setValue(_numberbox("Number:"), "35");
_setValue(_rangebox("range"), "55");
_setValue(_urlbox("Url:"), "http://google.com");
_setValue(_datebox("Date:"), "2015-05-20");
_setValue(_timebox("Time:"), "01:00");

Page Object Pattern with Sahi Script

As Sahi Script can be easily modularized (_include) applying Page Object Pattern is possible. For small and medium project this should work pretty fine.

The Test Script:


// arrange
var $dashboardPage = new DashboardPage();

// act
$dashboardPage.navigateTo();

// verify statistics
_assert($dashboardPage.isAt());
_assertEqual(1700, $dashboardPage.statistics().uploads);
_assertEqual("700 GB", $dashboardPage.statistics().quota);
_assertEqual(500, $dashboardPage.statistics().reviews);
_assertEqual(70, $dashboardPage.statistics().averageMonthlyUploads);

The Page:

var DashboardPage = function () {

    var $_inboundVisitorStatistics = _div("Inbound visitor statistics");
    var $_inboundVisitorStatisticsCanvas = _canvas(0, _in(_div("panelChart9")));

    this.navigateTo = function () {
        _navigateTo($BASE_URL + "dashboard");
    };

    this.isAt = function () {
        return "Angle - Dashboard" == _title();
    };

    this.statistics = function () {

        var valueOf = function (name) {
            return _getText(_div(0, _near(_div(name))))
        };

        var getAverageMonthlyUploads = function () {
            return _canvas(0, _near(_div("Average Monthly Uploads"))).getAttribute("data-percentage");
        };

        return {
            uploads: valueOf("Uploads"),
            quota:   valueOf("Quota"),
            reviews: valueOf("Reviews"),
            // fits in statistics
            averageMonthlyUploads: getAverageMonthlyUploads()
        }
    };

    this.isInboundVisitorStatisticsVisible = function () {
        _log("Calling isInboundVisitorStatisticsVisible");
        return _isVisible($_inboundVisitorStatisticsCanvas);
    };

    this.collapseInboundVisitorStatistics = function () {
        if (!this.isInboundVisitorStatisticsVisible()) {
            _fail("Inbound visitor statistics are not visible. Can't collapse.");
        }
        _click(_link(0, _near($_inboundVisitorStatistics)));
        // let the panel collapse, 2nd argument must be a Sahi expression
        _wait(2000, !_isVisible($_inboundVisitorStatisticsCanvas));
    };

    this.expandInboundVisitorStatistics = function () {
        if (this.isInboundVisitorStatisticsVisible()) {
            _fail("Inbound visitor statistics are already visible. Can't expand.");
        }
        _click(_link(0, _near($_inboundVisitorStatistics)));
        // let the panel collapse, 2nd argument must be a Sahi expression
        _wait(2000, _isVisible($_inboundVisitorStatisticsCanvas));
    };

};

Source code

A full list of examples can be found here: https://github.com/kolorobot/sahi-script-samples

Running the scripts

  • Download and install Sahi OS
  • Download the scripts, unpack it and move to userdata/sahi-demo directory
  • Add sahi-demo to scripts.dir property in userdata/config/userdata.properties
  • Run Sahi Dashboard
  • Run a selected browser and open Sahi Controller
  • Switch to Playback tab and select sahi-demo script directory
  • Select a file, click Set and then Play

Tuesday, June 23, 2015

[Angular2]="{{'Hello, World!'}}"

As I mentioned in my recent blog post Angular 2 is a complete rewrite. Many concepts that are known from Angular 1.x are gone or changed dramatically. Angular 2 looks like a completely different framework: no DDO, no $scope, no angular.module and completely rewritten binding and change detection (no ng-model).

Update (1/4/2016) - This blog post is not maintained. The concepts are still valid, but the code may be outdated. If you want to learn how to use up-to-date Angular2 with TypeScript and Gulp, please read this blog post (regularly updated): Quickstart: Angular2 with TypeScript and Gulp

Although Angular 2 is still work in progress many new features have already been revealed. In this blog post I will share some basic concepts of the framework via code samples that I presented during my lecture at InfoShare 2015.

Please note the code is created with Angular 2 Alpha 26.

Angular 2 is built with… TypeScript (1.5)

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

We could say it is ECMAScript 6 on steroids, as it offers what ECMAScript 6 has to offer. But it adds many more features: type checking, interfaces, generics, enums or decorators to name just a few.

Let’s see some sample code created in TypeScript:

import {Greeter} from "greeter";

class HtmlGreeter implements Greeter {

    constructor(public greeting:string) {
    }

    greet() {
        return "<h1>" + this.greeting + "</h1>";
    }
}

var greeter = new HtmlGreeter("Hello, world!");
var greetings = greeter.greet();

TypeScript is optional for Angular 2 applications and although it is a recommended approach, developers have choice. They can choose from: ES5, ES6, CoffeScript or any other language that compiles to JavaScript.

Want to learn more about TypeScript? Visit http://www.typescriptlang.org/

Hello, World!

Let’s see two “Hello, World!” Angular 2 applications written in TypeScript and ECMAScript 5 accordingly.

TypeScript (1.5):

// TypeScript
import {Component, View, bootstrap} from 'angular2/angular2';

@Component({
    selector: 'hello-angular2'
})
@View({
    template: "<h1>Hello {{ name | lowercase }}</h1>"
})
class HelloAngular2Cmp {
    name:string = "Angular2";
}

bootstrap(HelloAngular2Cmp);

JavaScript (ES5):

// ES5
function HelloAngular2Cmp() {
    this.name = 'Angular2'
}

HelloAngular2Cmp.annotations = [
    new angular.ComponentAnnotation({
        selector: 'hello-angular2'
    }),
    new angular.ViewAnnotation({
        template: '<h1>Hello, {{ name }}!</h1>'
    })
];

document.addEventListener('DOMContentLoaded', function () {
    angular.bootstrap(HelloAngular2Cmp);
});

As you can see the TypeScript version is a bit less verbose and decorators (@) clearly separate the code from meta data information.

Angular 2 Building Blocks

As you could notice, the the above code did not contain much of what you learned about Angular 1.x: no angular.module, no Directive Definition Object (DDO), no $scope.

Component

A component is the main UI building block of Angular 2 app: Angular 2 is a tree of components. Every Angular 2 application must have at least one component. A component class is an execution context for the template or it is a component controller. A component requires a single @Component decorator and at least one @View decorator.

Let’s see a really basic component in Angular 2:

@Component({
    selector: 'hello-angular2'
})
@View({
    templateUrl: 'template.html',
    directives: [NgIf]
})
class HelloAngular2Cmp {

    private text:string;
    private clickCount:number = 0;

    onClick(input, $event) {
        this.text = input.value;
        if ($event instanceof MouseEvent) {
            this.clickCount++;
        }
    }
}

// let component be rendered on a page
bootstrap(HelloAngular2Cmp);

HelloAngular2Cmp has two properties: text and clickCount that are bound to a view defined by a template attribute of a @View decorator. Templates have access to any properties or functions of a component controller.

View

The template itself looks like this:


<!-- local variable input -->
<input type="text" #input>
<!-- event binding -->
<button (click)="onClick(input, $event)"
        [disabled]="text === 'Angular2'">Click me!</button>

<!-- property binding -->
<p>Angular2 says: {{ text }}</p>

<!-- Conditional -->
<div *ng-if="clickCount >= 5">Clicking too much, man!</div>

The syntax is very easy:

  • {{ expression | pipe }} - Angular 2 interpolation,
  • #variable – local variables available in the scope of the component. The variable can be later referred in the component’s template,
  • (event) - binding to events of element or directive,
  • [property] - binding to properties of element.

Bindings

Every time the text property of a component changes, the change is automatically reflected in the template. The properties of elements are accessed with square brackets ([property]) syntax. In the above example the button will be disabled once the text property of a component is equal to “Angular 2”. This is a property binding in Angular 2.

To propagate changes from DOM to a component event binding must be utilized. Event bindings in Angular 2 are represented by brackets syntax: (event). In the above example when a click event occurs on a button, onClick function of a component will be executed.

To sum up, in Angular 2:

Property bindings are executed automatically,
Event bindings allow propagation of DOM changes.

Watch this video to better understand the data binding in Angular 2: https://angularu.com/Video/2015sf/misko-hevery-talks-about-databinding-in-angular-2

Forms

Property and event bindings makes two two-way data binding possiblebut an additional effort is required in order to achieve it. Fortunately, Angular 2 will be shipped with Angular 2 Forms module. This module will be used for handling user input, by defining and building a control objects and mapping them onto the DOM. Control objects can then be used to read information from the form elements.

Read more about Angular 2 Forms: http://angularjs.blogspot.com/2015/03/forms-in-angular-2.html

Directive

A component is not the only UI building block in Angular 2. There are also directives which allow you to attach behavior to elements in the DOM.

The difference between a component and a directive in Angular 2 is that a component is a directive with a view whereas a directive is a decorator with no view.

A directive requires a single @Directive decorator and a directive class:

import {Directive, ElementRef} from 'angular2/angular2';

@Directive({
    selector: "[highlight]",
    hostListeners: {
        'mouseenter': 'onMouseEnter()',
        'mouseleave': 'onMouseLeave()'
    }
})
class Highlight {

    constructor(private element:ElementRef) {

    }

    onMouseEnter() {
        this.outline('#f00 solid 1px');
    }

    onMouseLeave() {
        this.outline();
    }

    private outline(outline:string = "") {
        this.element.domElement.style.outline = outline;
    }
}

The above directive, when used on an element, adds an outline effect to the host element – the element it is used on. ElementRef is automatically provided by Angular 2 Dependency Injection module.

Usage example:

<div highlight>Lorem ipsum...</div>

Dependency Injection

In Angular 2 there is a single way to inject dependencies into a directive or a component. In the below example a user-defined service is injected into a component. MessageService declares some business logic:

// messageService.ts
export class MessageService {

    private messages:Array<string> = [
        "Hello, Angular2",
        "Angular2 is cool!",
        "Damn it! Stop doing this!"];

    public getMessage() {
        return this.messages[Math.floor(
            Math.random() * this.messages.length)];
    }
}

The component is requesting framework to provide a required dependency via its constructor:

import {Component, View, bootstrap} from 'angular2/angular2';
import {MessageService} from 'messageService'

@Component({
    selector: 'hello-angular2'
})
@View({
    template: '<h1 (click)="onClick()">{{message}}</h1>',
})
class HelloAngular2Cmp {

    private message:string;

    constructor(private messageService:MessageService) {

    }

    onClick() {
        this.message = this.messageService.getMessage();
    }
}

The MessageService is imported from an external module and later it must be made available to Angular 2. One way to make dependencies available is to register them globally with a bootstrap() function like the one below:

bootstrap(HelloAngular2Cmp, [MessageService]);

Please note that framework services, directives or components, an iterable live list of components (@Query) and attributes (@Attribute) can be injected in the same, uniform way. The new DI module is designed the way it supports easy extending (DependencyAnnotation) so even custom dependency injection annotation can be created. In addition, Angular 2 supports injecting promises (@InjectPromise), lazy dependencies (@InjectLazy) or optional dependencies (@Optional).

Read more about Angular 2 Dependency Injection in this great article: http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html

Summary

As you can see Angular 2 is much different from Angular 1.x. No DDO, no $scope, no angular.module, new change detection and binding, uniform template syntax, new dependency injection, new forms module, new router and much more.

The new version of the framework should also be much simpler to learn thanks to easier and more concise concepts like component-based architecture. Moreover, Angular 2 should be significantly faster than its ancestor thanks to completely rewritten data binding and change detection.

Is there a way to migrate from Angular 1.x? In my opinion it will not be easy. But there are some tips out there that may help in migration:

  • Prefer one-way data-bindings to two-way data-bindings,
  • Use ControllerAs syntax for easier migration to components,
  • Do not update application state inside watch functions,
  • Follow the newest releases (1.4, 1.5) and upgrade,
  • Think of using New Router when available (https://angular.github.io/router/),
  • Think of using TypeScript in Angular 1.x applications.

References

Monday, June 8, 2015

Angular2 a gentle introduction

Angular 1.x

Angular 1.x is the most popular Front-end framework these days. Last year we decided to adopt it in some of Goyello new projects. Today we have some experience to share. At the same time we are closely looking at the next generation of the framework.

Update (1/4/2016) - If you want to learn how to use up-to-date Angular2 with TypeScript and Gulp, please read my this blog post (regularly updated): Quickstart: Angular2 with TypeScript and Gulp

Game changer

It is extremely easy to get started with Angular 1.x. It provides clear separation of presentation, data and application logic which is greatly appreciated especially by back-end developers as myself. Two-way data binding is one of the most appreciated features of the framework. The dependency injection makes it possible to modularize the code and test it in isolation. Directives are great way of creating reusable components and use them across the application with ease. As a result, people love and admire the framework since the very beginning.

All that glitters is not gold

There is no doubt Angular 1.x is a great framework. However it is incredibly difficult to master. The complex API and many concepts introduced since its launch make understanding the framework and thus using it effectively really hard.

Angular 1.x has started in 2009, so it is not so fresh anymore and it is criticized more and more, mostly for the features that made the framework so popular.

Two way data binding looks great at first sight, but it introduces coupling: everything can update everything. This makes debugging and tracking errors really difficult. In addition, the performance of the applications drops significantly with growing number of objects on the pages.

Directives are great, but have you tried to understand its API? How much time did you need to master directives? Restrict, isolating the scope, link (pre-link, post-link), compile, transclusion, directive communication (and more) makes developers really suffer.

The Angular team also noticed many issues with Angular 1.x. They decided to create the next version of the framework almost from scratch.

What’s new in Angular 2?

Angular 2 is built on top of modern web standards like Web Components or ECMAScript 6. Many of these standards are not yet natively supported by browsers but they can be used thanks to polyfills.

Angular 2 is a new opening: no controllers, no DDO, no $scope, no angular.module and no two-way data binding.

The new version of the framework should also be much simpler to learn thanks to easier and more concise concepts like component-based architecture. The built-in modularity will make it possible to create complex applications easier. Moreover, Angular 2 should be significantly faster than its ancestor thanks to completely rewritten data binding and change detection.

Wednesday, May 27, 2015

Groovier Spring Boot Integration Testing

Recently I had a chance to use Groovy’s groovy.json.JsonSlurper in a soapUI REST project. The usage scenario in soapUI (in particular, soapUI Open Source) was very simple: in a Groovy assertion, load the content of a response into a variable and than verify it like this:

import groovy.json.JsonSlurper;

def slurper = new JsonSlurper()
def result = slurper.parseText(messageExchange.responseContent)

assert result.incidentType == 'Lorem ipsum'

This works well in soapUI. But what about Spring Boot integration tests? Can I make integration testing of REST API groovier?

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.

Monday, January 12, 2015

Testing with files and directories in JUnit with @Rule

Testing with Files and directories in JUnit is easy thanks to TemporaryFolder @Rule.
In JUnit rules (@Rule) can be used as an alternative or an addition to fixture setup and
cleanup methods (org.junit.Before, org.junit.After, org.junit.BeforeClass, and org.junit.AfterClass), but they are more powerful, and can be more easily shared between projects and classes.

Tuesday, January 6, 2015

Building a HATEOAS API with JAX-RS and Spring

In my previous blog post I showed how easy Jersey can be configured with Spring Boot. My exploration on Spring Boot and Jersey did not end and I investigated the possibility of using Spring HATEOAS along with Jersey in Spring Boot application. Spring HATEOS allows creating REST representations that follow the HATEOAS principle and (as of writing this article) has basic JAX-RS support for working with links. In this blog post I will share some examples of how I integrated Spring HATEOAS with Jersey in a Spring Boot application.

Monday, January 5, 2015

Getting started with Jersey and Spring Boot

Along many new features, Spring Boot 1.2 brings Jersey support. This is great step to attract those developers who like the standard approach as they can now build RESTful APIs using JAX-RS specification and easily deploy it to Tomcat or any other Spring’s Boot supported container. Jersey with Spring platform can play an important role in the development of mico services. In this article I will demonstrate how one can quickly build an application using Spring Boot (including: Spring Data, Spring Test, Spring Security) and Jersey.