Skip to content

Commit

Permalink
Add dropwizard-e2e module
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbabcock committed Oct 23, 2016
1 parent 5aec239 commit a5161f9
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
95 changes: 95 additions & 0 deletions dropwizard-e2e/pom.xml
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>

<artifactId>dropwizard-e2e</artifactId>
<version>1.1.0-SNAPSHOT</version>
<groupId>io.dropwizard</groupId>
<name>Dropwizard End-to-end Tests</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<!-- No need to deploy dropwizard-e2e -->
<maven.deploy.skip>true</maven.deploy.skip>
<maven.site.skip>true</maven.site.skip>
<maven.site.deploy.skip>true</maven.site.deploy.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-client</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
26 changes: 26 additions & 0 deletions dropwizard-e2e/src/main/java/com/example/app1/App1.java
@@ -0,0 +1,26 @@
package com.example.app1;

import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.jersey.optional.EmptyOptionalException;
import io.dropwizard.jersey.optional.EmptyOptionalExceptionMapper;
import io.dropwizard.setup.Environment;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

public class App1 extends Application<Configuration> {
@Override
public void run(Configuration config, Environment env) throws Exception {
// Ensure that we can override the default 404 response on an
// empty optional and return a 204 instead
env.jersey().register(new ExceptionMapper<EmptyOptionalException>() {
@Override
public Response toResponse(EmptyOptionalException exception) {
return Response.noContent().build();
}
});

env.jersey().register(new App1Resource());
}
}
14 changes: 14 additions & 0 deletions dropwizard-e2e/src/main/java/com/example/app1/App1Resource.java
@@ -0,0 +1,14 @@
package com.example.app1;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.OptionalInt;

@Path("/")
public class App1Resource {
@GET
@Path("empty-optional")
public OptionalInt emptyOptional() {
return OptionalInt.empty();
}
}
28 changes: 28 additions & 0 deletions dropwizard-e2e/src/test/java/com/example/app1/App1Test.java
@@ -0,0 +1,28 @@
package com.example.app1;

import io.dropwizard.Configuration;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit.DropwizardAppRule;
import org.junit.ClassRule;
import org.junit.Test;

import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;

import static org.assertj.core.api.Assertions.assertThat;

public class App1Test {
@ClassRule
public static final DropwizardAppRule<Configuration> RULE =
new DropwizardAppRule<>(App1.class, ResourceHelpers.resourceFilePath("app1/config.yml"));

@Test
public void custom204OnEmptyOptional() {
final Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test client");
final String url = String.format("http://localhost:%d/empty-optional", RULE.getLocalPort());

final Response response = client.target(url).request().get();
assertThat(response.getStatus()).isEqualTo(204);
}
}
7 changes: 7 additions & 0 deletions dropwizard-e2e/src/test/resources/app1/config.yml
@@ -0,0 +1,7 @@
server:
applicationConnectors:
- type: http
port: 0
adminConnectors:
- type: http
port: 0
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -50,6 +50,7 @@
<module>dropwizard-benchmarks</module>
<module>dropwizard-http2</module>
<module>dropwizard-request-logging</module>
<module>dropwizard-e2e</module>
</modules>

<properties>
Expand Down

0 comments on commit a5161f9

Please sign in to comment.