0

I am using Arquillian for functional testing an application against a Jakarta EE application server.

I am running into an issue where I am unable to properly inject the servlet URL to test against.

public class SecurityTests extends ArquillianTests {
    @ArquillianResource(SecurityServlet.class)
    URL baseURL;

    @Deployment(testable=false)
    public static EnterpriseArchive createDeployment() {
        WebArchive war = ShrinkWrap.create(WebArchive.class)
                .addPackages(true, SecurityServlet.class.getPackage());
        
        JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
                .addClasses(SecurityTestRemote.class, SecurityTestEjb.class)
                .addAsManifestResource(ContextTests.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
        
        EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class)
                .addAsModules(war, jar)
                .addAsManifestResource(ContextTests.class.getPackage(), "sun-ejb-jar.xml", "sun-ejb-jar.xml");
        
        return ear;
    }
}
@WebServlet("/SecurityServlet")
public class SecurityServlet extends HttpServlet

When my Enterprise Archive is deployed, the archive and its' modules are all given random names, such as:

> 681737db-3621-4b1a-b77a-4f571b877126.ear
  > META-INF
  > 5f6d70e5-13f9-4d49-a32f-c7b3138da9fa.war
    > WEB-INF ...
  > 90772573-9202-4c77-b8b9-99b5869dd29f.jar
    > META-INF ...
  • If I just use @ArquillianResource URL baseURL;
  • Then baseURL will be set to http://localhost:8010/681737db-3621-4b1a-b77a-4f571b877126

The servlet, however, is deployed the endpoint that matches the modules name so I would expect to get http://localhost:8010/5f6d70e5-13f9-4d49-a32f-c7b3138da9fa

  • If I use @ArquillianResource(SecurityServlet.class) URL baseURL;
  • Then I get an exception
arquillianBeforeTest(jakarta.enterprise.concurrent.spec.ManagedScheduledExecutorService.security.SecurityTests)  Time elapsed: 4.134 sec  <<< FAILURE!
java.lang.RuntimeException: Could not lookup value for field java.net.URL jakarta.enterprise.concurrent.spec.ManagedScheduledExecutorService.security.SecurityTests.baseURL
    at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.enrich(ArquillianResourceTestEnricher.java:68)
    at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:51)
Caused by: java.lang.RuntimeException: All Providers for type class java.net.URL returned a null value: [org.jboss.arquillian.container.test.impl.enricher.resource.URLResourceProvider@9e28539]
    at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.lookup(ArquillianResourceTestEnricher.java:126)
    at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.enrich(ArquillianResourceTestEnricher.java:66)
    at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:51)
    at org.jboss.arquillian.container.test.impl.ClientTestInstanceEnricher.enrich(ClientTestInstanceEnricher.java:48)

Questions:

  1. Is my assumption correct that I need to use @ArquillianResource(SecurityServlet.class)?
  2. If yes, could the exception be caused by the container implementation I am using? (I am using OpenLiberty)
  3. If no, what is the correct way to get the module's URL?

Update:

Liberty features enabled

<featureManager>
  <!-- Features being tested -->
  <feature>jakartaee-9.1</feature>
  <!-- Supporting features -->
  <feature>jndi-1.0</feature> 
  <!-- Features needed for arquillan support -->
  <feature>localConnector-1.0</feature>
  <feature>restConnector-2.0</feature>
  <feature>arquillian-support-jakarta-2.0</feature>
</featureManager>

Dependencies

<dependency>
  <groupId>io.openliberty.arquillian</groupId>
  <artifactId>arquillian-liberty-remote-jakarta-testng</artifactId>
  <version>2.0.2</version>
  <type>pom</type>
  <scope>test</scope>
<dependency>
KyleAure
  • 465
  • 4
  • 15

1 Answers1

1

Edit note: I see from your update you're using the remote container so I'm adding a section about that.

Using the managed container

I think your test code is correct. The liberty arquillian container has a test here which is similar.

If you're using Java EE 7 or 8 features, make sure you have the j2eeManagement-1.1 feature enabled as the liberty arquillian container uses it to find the correct context root for the servlet. Docs here.

    <feature>j2eeManagement-1.1</feature> <!-- Optional, needed to allow injection on ArquillianResources related to servlets -->

If you're using Jakarta EE 9 features, it should work without this.

Using the remote container

It looks like the logic for finding servlets is missing from the remote container (as of the current version 2.0.1).

Please can you open an issue on the liberty-arquillian repository?

In the short term, if possible, you could try using the managed container instead.

Azquelt
  • 1,380
  • 10
  • 15
  • Thanks, I updated the issue to include the features I am using. I am using the `jakartaee-9.1` feature and am still seeing this behavior. – KyleAure Dec 01 '21 at 15:21