Testing Java Applications for Resilience by Simulating Network Problems with Toxiproxy, JUnit and the Docker Maven Plugin

When implementing distributed systems, client-server architectures and simple applications with network related functionalities, everything is fine when we’re in the development or in the testing stage because the network is reliable and the communicating systems are not as stressed as they are in production. But to sleep well we want to validate how resilient we have implemented our systems, how they behave when the network fails, the latency rises, the bandwidth is limited, connections time out and so on. ...

July 29, 2018 · 9 min · 1836 words · Micha Kops

Setting up Kafka Brokers for Testing with Kafka-Unit

When writing test for applications that interact with Kafka brokers we often need to setup a decent environment including an instance of Kafka and ZooKeeper. Though Kafka ships with some classes for testing, setting up a simple testing environment is quite easier with the kafka-unit library that offers JUnit test rule support or a fast programmatic setup within no time. In the following short example, I’d like to show how create a simple setup using Maven, Surefire and kafka-unit. ...

March 28, 2018 · 4 min · 825 words · Micha Kops

Reactive Streams – Java 9 Flow API, RxJava, Akka and Reactor Examples

Reactive Streams is an initiative trying to standardize asynchronous stream processing with non-blocking back-pressure. With Java 9, new classes in the java.util.concurrent.flow package offer a semantically equivalent counterpart to this standard that may be adopted by other frameworks. In the following short tutorial we’re implementing examples for reactive streams with Java 9 and the Flow API, with RxJava2, with Akka, with Reactor and finally there is an example in RxJava1, too though it does not follow the standard. ...

January 14, 2018 · 8 min · 1550 words · Micha Kops

Identity Management, One-Time-Passwords and Two-Factor-Auth with Spring Boot and Keycloak

Communicating with identity and access management systems is a common task for many web-applications exposing secured resources. Keycloak is an open source software that provides not also such authorization services but also offers a lot of features from Single-Sign-On, Identity-Brokering, Social-Login, User-Federation, multiple client-adapters up to the administration console or support for protocols like OpenID, SAML, OAuth2, Kerberos and more. I will demonstrate how to integrate a Spring Boot web application with Keycloak and configure an authentication flow that requires a two-factor-authentication with user credentials and also one-time-passwords. ...

November 26, 2017 · 10 min · 1918 words · Micha Kops

Detecting Vulnerable Dependencies with Maven and the OWASP Dependency Check Plugin

On the one hand adding dependencies to a project is easy, on the other hand securing a project and checking for vulnerable dependencies is way harder. The OWASP dependency check plugin for Maven allows us to scan our project’s dependencies for know vulnerabilities. I will demonstrate its usage in the following short example. Figure 1. OWASP Vulnerability Report Dependencies We just need to add one plugin-dependency to our Mavenized project’s pom.xml. ...

October 3, 2017 · 3 min · 593 words · Micha Kops

Downloading Maven Artifacts from a POM file programmatically with Eclipse Aether

Sometimes I need to resolve Maven dependencies programmatically. Eclipse Aether is a library for working with artifact repositories and I’ll be using it in the following example to read dependency trees from a given POM descriptor file and download each dependency from a remote Maven repository to a local directory. Figure 1. Using Eclipse Aether. Dependencies We’re adding a bunch of dependencies to our project’s pom.xml: <properties> <aetherVersion>1.1.0</aetherVersion> <mavenVersion>3.2.1</mavenVersion> </properties> ...

September 8, 2017 · 5 min · 1006 words · Micha Kops

Assuring Architectural Rules with ArchUnit

Maintaining architecture rules and constraints for a specific software project or an application is not easy as textual documentation is easily forgotten after a while and hard to verify. ArchUnit is a testing library that allows developers and software architects to write down such rules as executable tests that may be run by the development teams and the integration servers. In the following article I will demonstrate the basic features of this library by applying rules and constraints to an existing application. ...

July 3, 2017 · 9 min · 1892 words · Micha Kops

Template Driven Test POJO Generation with Fixture Factory and Java

In our tests we often need to create a bunch of test-objects that are populated with random-data. This data needs to follow specific rules as identifiers need to be unique or must be incremented, string-properties must follow special conventions and so on. In the following short tutorial I will demonstrate how to generate such test data using the Fixture Factory library. Figure 1. Fixture Factory and JUnit...

June 20, 2017 · 8 min · 1689 words · Micha Kops

Handling System Properties, Environment Variables, STDOUT/STDERR in JUnit Tests with System Rules

When important data is written to STDIN/STDOUT and an application relies on specific system properties or environment variables, writing tests is getting more complicated. System Rules is a collection of JUnit rules that helps us writing Java tests for everything that deals with java.lang.System. In the following short examples I’d like to demonstrate how to deal with system properties, environment variables, STDOUT and STDERR and capturing both for testing e.g. for some golden master refactoring. ...

December 19, 2016 · 4 min · 718 words · Micha Kops

Creating Microservices with Bootique

When it comes to writing microservices in Java, plenty of tools and frameworks exist. In the following tutorial, I’d like to demonstrate another minimalistic framework called Bootique by implementing a simple microservice exposing its functions either as a RESTful web-service or as a runnable command executed using the command line. Bootique Command Line Dependencies Using Maven here, we’re adding the following elements to our project’s pom.xml: Bootiques Bill of Materials as dependency management: bootique-bom Bootique Jersey for our REST service: bootique-jersey Bootique Logback for logging: bootique-logback Maven Shade Plugin to assemble our fat-jar ...

September 18, 2016 · 6 min · 1070 words · Micha Kops