Arquillian Container Undertow Embedded

Embedded Undertow container integration for the Arquillian project

License

License

Categories

Categories

JBoss Container Application Servers Undertow Net Networking
GroupId

GroupId

org.jboss.arquillian.container
ArtifactId

ArtifactId

undertow-embedded
Last Version

Last Version

1.0.0.Alpha2
Release Date

Release Date

Type

Type

jar
Description

Description

Arquillian Container Undertow Embedded
Embedded Undertow container integration for the Arquillian project
Project Organization

Project Organization

JBoss by Red Hat

Download undertow-embedded

How to add to project

<!-- https://jarcasting.com/artifacts/org.jboss.arquillian.container/undertow-embedded/ -->
<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>undertow-embedded</artifactId>
    <version>1.0.0.Alpha2</version>
</dependency>
// https://jarcasting.com/artifacts/org.jboss.arquillian.container/undertow-embedded/
implementation 'org.jboss.arquillian.container:undertow-embedded:1.0.0.Alpha2'
// https://jarcasting.com/artifacts/org.jboss.arquillian.container/undertow-embedded/
implementation ("org.jboss.arquillian.container:undertow-embedded:1.0.0.Alpha2")
'org.jboss.arquillian.container:undertow-embedded:jar:1.0.0.Alpha2'
<dependency org="org.jboss.arquillian.container" name="undertow-embedded" rev="1.0.0.Alpha2">
  <artifact name="undertow-embedded" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.jboss.arquillian.container', module='undertow-embedded', version='1.0.0.Alpha2')
)
libraryDependencies += "org.jboss.arquillian.container" % "undertow-embedded" % "1.0.0.Alpha2"
[org.jboss.arquillian.container/undertow-embedded "1.0.0.Alpha2"]

Dependencies

compile (4)

Group / Artifact Type Version
org.jboss.arquillian.container : shrinkwrap-container-undertow jar 1.0.0.Alpha2
org.jboss.arquillian.container : arquillian-container-spi jar
org.jboss.arquillian.container : arquillian-container-test-spi jar
org.jboss.arquillian.testenricher : arquillian-testenricher-initialcontext jar

test (3)

Group / Artifact Type Version
junit : junit jar 4.11
com.ning : async-http-client jar 1.8.2
org.jboss.arquillian.junit : arquillian-junit-container jar

Project Modules

There are no modules declared in this project.

Arquillian-Container-Undertow

Undertow

Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO.

Undertow has a composition based architecture that allows you to build a web server by combining small single purpose handlers. The gives you the flexibility to choose between a full Java EE servlet 3.1 container, or a low level non-blocking handler, to anything in between.

Undertow is sponsored by JBoss and is the default web server in the Wildfly Application Server.

Writing tests for Undertow

Arquillian-Container-Undertow as every Arquillian Container Extension it take cares of you of starting, stopping and deploying the application. Also provides an Shrinkwrap resolver for creating the Undertow deployment file.

To simplify the development of tests on Undertow we have created two Shrinkwrap resolvers:

  • Embedded Servlet Deployment

  • Non-blocking handler

Embedded Servlet Deployment

When you want to deploy a servlet/s inside Undertow, you must create a DeploymentInfo class and provide all the required information. For this reason Arquillian-Container-Undertow provides a Shrinkwrap resolver named UndertowWebArchive.

@Deployment(testable = false)
public static Archive<WebArchive> createDeployment() {
	return ShrinkWrap.create(UndertowWebArchive.class).from(
			deployment()
			.setContextPath("/myapp")
			.setDeploymentName("test.war")
			.setClassLoader(
					EmbeddedUndertowClientWebContainerTest.class
							.getClassLoader())
			.addServlet(
					servlet("MessageServlet", MessageServlet.class)
						.addInitParam("message", "Hello World")
						.addMapping(SERVLET_MAPPING)));
}

And then we can write our test:

@Test
public void shouldBeAbleToInvokeServletInDeployedWebApp(
		@ArquillianResource URL url) throws Exception {

	String body = readAllAndClose(new URL(url, "myservlet").openStream());

	assertThat(body, is("Hello World"));
}

Non-blocking handler

But with Undertow you can also write non-blocking handlers. For creating a non-blocking handler in Undertow you simply must create a class that implements HttpHandler interface and register it. For this reason Arquillian-Container-Undertow provides a Shrinkwrap resolver named UndertowHttpHandlerArchive.

@Deployment(testable = false)
public static Archive<JavaArchive> createDeployment() {
	return ShrinkWrap.create(UndertowHttpHandlerArchive.class).from(new HttpHandler() {
           @Override
           public void handleRequest(final HttpServerExchange exchange) throws Exception {
               exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
               exchange.getResponseSender().send("Hello World");
           }
       });
}

And then we can write our test:

@Test
public void shouldBeAbleToInvokeHandlers(@ArquillianResource URL url) throws Exception {

	String body = readAllAndClose(url.openStream());

	assertThat(body, is("Hello World"));

}

Configuration

You can configure the bind address and port of Undertow. By default Undertow is opened at localhost:8080.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://jboss.org/schema/arquillian"
    xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

    <container qualifier="undertow" default="true">
    </container>
</arquillian>

But you can also set the bind address and the listening port.

<container qualifier="undertow" default="true">
	<configuration>
		<property name="bindAddress">localhost</property>
		<property name="bindHttpPort">9090</property> <!-- <1> -->
	</configuration>
</container>
  1. If port is set to -1, a random port between 1024 and 49151 is used.

Maven

Arquillian-Container-Undertow is released on JBoss Maven Repositories so you need to set it on your pom file.

<repositories>
	<repository>
    	<id>jboss-public-repository-group</id>
        <name>JBoss Public Maven Repository Group</name>
        <url>https://repository.jboss.org/nexus/content/groups/public</url>
	</repository>
</repositories>

And add dependency as:

<dependency>
  <groupId>org.jboss.arquillian.container</groupId>
  <artifactId>undertow-embedded</artifactId>
  <version>1.0.0.Alpha1</version>
</dependency>
org.jboss.arquillian.container

An Innovative Testing Platform for the JVM

Versions

Version
1.0.0.Alpha2