JAX-RS resource Integration test with Arquillian fails

78 views
Skip to first unread message

Captain

unread,
Jun 8, 2019, 5:36:27 AM6/8/19
to Payara Forum
I want to perform an Integration test on a working JAX-RS resource class with Arquillian. I am using payara server 5.192 and its embedded H2 database.

Below is my pom.xml

...

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.4.1.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies> 
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency> 
        
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>  
        <dependency>
            <groupId>fish.payara.arquillian</groupId>
            <artifactId>arquillian-payara-server-4-embedded</artifactId>
            <version>1.0.Beta3</version>
        </dependency>      
        <dependency>
            <groupId>fish.payara.extras</groupId>
            <artifactId>payara-embedded-all</artifactId>
            <version>5.192</version>
            <scope>test</scope>
        </dependency>
                
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.20</version>
            <type>jar</type>
        </dependency>
        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        
      </dependencies>
    
    <build>
        <finalName>app</finalName>        
        
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
        <testSourceDirectory>src/test</testSourceDirectory>
        
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
            </plugin>
        </plugins>
    </build>
    
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    <name>app</name>
...

My Test class has the following 

@RunWith(Arquillian.class)
public class AppITest {

    @Deployment(testable = false)
    public static JavaArchive createDeployment() {
        return ShrinkWrap.create(JavaArchive.class)
                .addClasses(JAXRSConfiguration.class, AppResource.class, appService.class, AppEntity.class)
                .addAsResource("META-INF/persistence.xml")
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    }

    .... 

        @RunAsClient
    @Test
    public void testApp(@ArquillianResource URL baseURL) throws URISyntaxException {
        int status = ClientBuilder.newClient().target(baseURL.toURI()).path("rest/users").request(MediaType.APPLICATION_JSON).get().getStatus();
        assertEquals(200, status);
    }

    

When deployed the app successfully runs on http://localhost:8080/app/

I have an endpoint at http://localhost:8080/app/rest/users that returns the list of users from the H2 database. 

- Now when i run the test, it fails as status = 404
  System.out.println(baseURL.toURI()); returns "http://localhost:8181" instead of "http://localhost:8080"

- When I set the baseURL to "http://localhost:8080" I get a ConnectionException 

How do i make a GET to  http://localhost:8080/app/rest/users  using @ArquillianResource ?
Thanks in advance

Message has been deleted

Philip Riecks

unread,
Jun 10, 2019, 2:46:27 PM6/10/19
to Payara Forum
The main issue was within the Arquillian setup as the beans.xml is not added as a WebInfResource.

The following setup should work:

@Deployment
public static WebArchive createDeployment() {
 
return ShrinkWrap.create(WebArchive.class)
 
.addClass(JAXRSConfiguration.class)
 
.addClass(UsersResource.class)
 
.addClass(UsersService.class)
 
.addClass(User.class)
 
.addAsResource("META-INF/persistence.xml")
 
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}




Kind regards,
Phil 
Reply all
Reply to author
Forward
0 new messages