Search code examples
javadropwizardmaven-failsafe-plugin

DropwizardAppRule and maven-failsafe-plugin


This is my DropwizardAppRule in MyAppIT.java class:

@ClassRule
public static final DropwizardAppRule<MyConfiguration> RULE =
        new DropwizardAppRule<>(MyApplication.class, YAML_PATH);

This would return the LocalPort my local Dropwizard App is running on:

RULE.getLocalPort()

When running in IntelliJ, it returns 9998 and all tests pass but when I do mvn clean install or mvn verify from the command line, it throws a NullPointerException and I see a bunch of Connection refused errors.

ERROR! javax.ws.rs.ProcessingException: java.net.ConnectException: Connection refused

Here is my maven-failsafe-plugin config:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <includes>
            <include>MyAppIT.java</include>
        </includes>
        <systemProperties>
            <property>
                <name>test.environment</name>
                <value>${test.environment}</value>
            </property>
        </systemProperties>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

It seems as if the DropwizardAppRule isn't even starting (since the port is null). What am I missing?


Solution

  • I included MyAppIT.java to the maven-surefire-plugin and it worked:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
            <includes>
                <include>MyAppIT.java</include>
            </includes>
        </configuration>
    </plugin>