MicroProfile REST Client for System Testing

MicroProfile REST client provides an alternative to plain JAX-RS client for writing System Tests. A given HTTP endpoint (it doesn't have to be a JAX-RS resource) has to be defined as a Java interface first:


@Path("/")
public interface AirhacksWorkshop {
    @GET
    String websiteContent();
}

The URI of the service is passed to the RestClientBuilder as parameter, as well as the (AirhacksWorkshop) interface:

package com.airhacks;

import org.eclipse.microprofile.rest.client.RestClientBuilder;
import (...)
public class WorkshopsTests {

    private AirhacksWorkshop workshop;

    @Before
    public void init() throws MalformedURLException {
        URL apiUrl = new URL("http://airhacks.com");
        this.workshop
                = RestClientBuilder
                        .newBuilder()
                        .baseUrl(apiUrl)
                        .build(AirhacksWorkshop.class);
    }

    @Test
    public void content() {
        String content = this.workshop.websiteContent();
        assertNotNull(content);
        assertThat(content, containsString("java"));
    }
}

A System Test is executed within a JUnit runtime and needs the implementation of the MicroProfile REST Client API:


<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client-microprofile</artifactId>
    <version>4.3.0.Final</version>
</dependency>

Currently there are Apache CXF, OpenLiberty, Thorntail and RESTEasy (used above) implementations available.

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License