Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
213 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.app1; | ||
|
||
import io.dropwizard.Application; | ||
import io.dropwizard.Configuration; | ||
import io.dropwizard.jersey.optional.EmptyOptionalException; | ||
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
14
dropwizard-e2e/src/main/java/com/example/app1/App1Resource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
28
dropwizard-e2e/src/test/java/com/example/app1/App1Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
server: | ||
applicationConnectors: | ||
- type: http | ||
port: 0 | ||
adminConnectors: | ||
- type: http | ||
port: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
dropwizard-jersey/src/main/java/io/dropwizard/jersey/optional/EmptyOptionalException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.dropwizard.jersey.optional; | ||
|
||
/** | ||
* An exception thrown when a resource endpoint attempts to write out an | ||
* optional that is empty. | ||
*/ | ||
public class EmptyOptionalException extends RuntimeException { | ||
public static final EmptyOptionalException INSTANCE = new EmptyOptionalException(); | ||
|
||
private EmptyOptionalException() { } | ||
} |
15 changes: 15 additions & 0 deletions
15
...zard-jersey/src/main/java/io/dropwizard/jersey/optional/EmptyOptionalExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.dropwizard.jersey.optional; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
|
||
/** | ||
* The default response when an empty optional is returned, is to respond with | ||
* a 404 NOT FOUND response. | ||
*/ | ||
public class EmptyOptionalExceptionMapper implements ExceptionMapper<EmptyOptionalException> { | ||
@Override | ||
public Response toResponse(EmptyOptionalException exception) { | ||
return Response.status(Response.Status.NOT_FOUND).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters