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:
- Is my assumption correct that I need to use
@ArquillianResource(SecurityServlet.class)
? - If yes, could the exception be caused by the container implementation I am using? (I am using OpenLiberty)
- 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>