Testing OpenAPI / Swagger Schema Compliance with Java, JUnit and assertj-swagger

The OpenAPI and Swagger API description format are becoming important standards to specify API contracts for RESTful web services and the Microservices trend pushes the need for such contracts even further. Therefore arises the need for software architects, testers and developers to write tests to verify if an exposed API follows such a specified contract. In the following tutorial I will demonstrate a setup with Java, Maven, JUnit and the designated contract-testing-library, assertj-swagger that verifies the validity of such a contract exposed by a Spring Boot application against a local stored definition. ...

August 31, 2018 · 5 min · 871 words · Micha Kops

Integrating Swagger into a Spring Boot RESTful Webservice with Springfox

Spring Boot allows us to create RESTful web-services with ease, Swagger specifies a format to describe the capabilities and operations of these services and with Swagger UI it is possible to explore our REST API with a nice graphical user interface in our browser. Springfox is a project that aims at creating automated JSON API documentation for API’s built with Spring and is used in the following tutorial to integrate Swagger into a sample application. ...

July 1, 2015 · 7 min · 1418 words · Micha Kops

Documenting RESTful Webservices in Swagger, AsciiDoc and Plain Text with Maven and the JAX-RS Analyzer

A variety of different tools exists to help us analyze RESTful web-services and create documentations for their APIs in different formats. In the following tutorial I’d like to demonstrate how to document an existing JAX-RS web-service in multiple formats like Swagger, AsciiDoc or Plain Text using Maven, the JAX-RS Analyzer and the JAX-RS Analyzer Maven Plugin. The JAX-RS Analyzer gathers its information not only by reflection like most other tools but also by bytecode analysis and therefore does not require us to add special annotations for documentation to our code. ...

June 16, 2015 · 6 min · 1119 words · Micha Kops

JAX-RS Server API Snippets

Because a lot of my current projects are using JAX-RS in different versions I’d like to write down and share some frequently used snippets for implementing RESTful web-services with the JAX-RS specification here. Using RegEx in Path Expressions Sometimes we need to extract multiple parameters from a path expression e.g. in the following example where year, month and day are fragments if the path. @GET @Path("/orders/{year:\\d{4}}-{month:\\d{2}}-{day:\\d{2}}") @Produces(MediaType.TEXT_PLAIN) public Response getOrders(@PathParam("year") final int year, @PathParam("month") final int month, @PathParam("day") final int day) { return Response.ok("Year: " + year + ", month: " + month + ", day: " + day).build(); } ...

September 28, 2014 · 5 min · 924 words · Micha Kops

Lucene Snippets: Faceting Search

The latest snippet from my Lucene examples demonstrates how to achieve a facet search using the Lucene 4.0 API and how easy it is to define multiple category paths to aggregate search results for different possible facets. In the following example we’re indexing some books as a classical example and create multiple category paths for author, publication date and category afterwards .. Lucene Dependencies We simply need two dependencies here .. lucene-core of course and in addition the lucene-facet library .. I’ve added the declarations needed for Maven and SBT here .. if you’re using Gradle or Buildr you should’t have a problem to transfer the information needed ;) ...

August 28, 2012 · 4 min · 837 words · Micha Kops

Using the Android Fragment API in a Tablet App

Since I got a new tablet running Android 4.0 aka ice cream sandwich I wanted to play around a bit with the fragments API and creating an application for a tablet. In the following tutorial, we’re going to build an application that renders several articles from a popular tech blog (just kidding) in a web view. What to build We’re going to build an application that is able to display web links in the left section of the screen and when clicked, displaying the corresponding website content in the right section of the application screen. ...

March 18, 2012 · 7 min · 1355 words · Micha Kops

Ordering your JUnit Rules using a RuleChain

JUnit Rules are a handy solution if one needs to alter test methods or wants to share common functionality between several test cases. JUnit 4.10 introduced a new class to order several rules according to our needs using a so called rule-chain. In the following example, we’re going to create a simple custom rule and afterwards bind several instances of it in a specified order to a test method. Adding JUnit Just one Maven dependency needed here – JUnit 4.10 ...

February 21, 2012 · 3 min · 560 words · Micha Kops

A look at Maven 3 alpha

We are all waiting for a stable release of Maven3 with following updates .. faster, more performant .. save us time building our software and some precious memory ;) improved artifact resolution api and plugin api better osgi integration a few bugfixes no mixing of application dependencies and tooling dependencies though it does not matter that much to me: polyglot features .. e.g.: “Writing your pom files in Groovy” version-less parent elements for multi-module or multi-pom projects, no need to define the parent version in every submodule better artifact resolution, which dependency or pom supplied which artifact to the outcome .. got that information from: “Splitter from the world of Java” ...

May 22, 2010 · 2 min · 219 words · Micha Kops

Snippets: Getting License Information from the Confluence API

Sometimes one needs to look up license details of a running Confluence system .. perhaps for creating a commercial plugin or to display recommendations dependant from the license used. For this reason there are a few possibilities for receiving some license information from the Confluence API or the velocity context. Note: This article is outdated since the Atlassian Marketplace was launched and a shiny new licensing API was added. Until this article is updated I strongly recommend to take a closer look at the detailed information that Atlassian is providing in the Developer Documentation. ...

May 6, 2010 · 3 min · 637 words · Micha Kops

Sensor Fun: Using the accelerometer on Android

Here is an example on how to use the accelerometer in your Android application. If you want to simulate the acceleration on the emulator I highly recommend the Sensor Simulator on the OpenIntents website. The following example app displays the coordinates received by the sensor. The Acceleration App The activity – AccelerationActivity.java package com.hascode.android; import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.widget.TextView; public class AccellerationActivity extends Activity { private TextView result; private SensorManager sensorManager; private Sensor sensor; private float x, y, z; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensor = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0); result = (TextView) findViewById(R.id.result); result.setText("No result yet"); } private void refreshDisplay() { String output = String .format("x is: %f / y is: %f / z is: %f", x, y, z); result.setText(output); } @Override protected void onResume() { super.onResume(); sensorManager.registerListener(accelerationListener, sensor, SensorManager.SENSOR_DELAY_GAME); } @Override protected void onStop() { sensorManager.unregisterListener(accelerationListener); super.onStop(); } private SensorEventListener accelerationListener = new SensorEventListener() { @Override public void onAccuracyChanged(Sensor sensor, int acc) { } @Override public void onSensorChanged(SensorEvent event) { x = event.values[0]; y = event.values[1]; z = event.values[2]; refreshDisplay(); } }; } ...

April 27, 2010 · 2 min · 280 words · Micha Kops