Reputation: 3322
I'm writing dropwizard application and I stuck with integration testing. I was trying to launch server at pre-integration-test
phase in maven and than stop it at post-integration-test
phase but the problem is that I lose java thread while using maven-exec plugin.
Configuration looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>create-and-run-dropwizard-test-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>target/my-server.jar</argument>
<argument>server</argument>
<argument>test-config.yml</argument>
</arguments>
</configuration>
</plugin>
Using it maven runs until pre-integration-test
phase and than starts server in the same thread. Anyway I can run this as bash script and than stop it using kill -9
command but this solution isn't platform independent.
Is there any other way to do integration testing ? P.S. I'm using dropwizard v0.7.0-SNAPSHOT.
Upvotes: 5
Views: 6344
Reputation: 1403
It is old, but perhaps someone needs this information. For integrated testing here is an example code from this link
public class LoginAcceptanceTest {
@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<TestConfiguration>(MyApp.class, resourceFilePath("my-app-config.yaml"));
@Test
public void loginHandlerRedirectsAfterPost() {
Client client = new Client();
ClientResponse response = client.resource(
String.format("http://localhost:%d/login", RULE.getLocalPort()))
.post(ClientResponse.class, loginForm());
assertThat(response.getStatus()).isEqualTo(302);
}
}
For resource testing follow this link
Upvotes: 4