Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do integration testing of dropwizard server resources?

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.

like image 256
rand0m86 Avatar asked Oct 01 '22 15:10

rand0m86


1 Answers

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

like image 183
user3280180 Avatar answered Oct 05 '22 11:10

user3280180