OpenLiberty / liberty-arquillian

Arquillian Liberty Managed and Remote containers
Apache License 2.0
11 stars 29 forks source link

Ensure consistant behavior between managed and remote containers #112

Open KyleAure opened 2 years ago

KyleAure commented 2 years ago

Issue Overview

I have noticed some inconsistencies in behavior between the managed and remote container implementations that result in failures when running tests between application servers. Since not all application servers offer a managed container, I would expect most developers to use the remote container by default. So we would want to make sure it performs as well as the managed container.

Below is likely just one example of unexpected behavior using the remote container.

Stackoverflow Issue: https://stackoverflow.com/questions/70177509/use-arquillianresource-to-inject-url-when-deploying-an-enterprisearchive

Expected Behaviour

When deploying an Enterprise Archive with an embedded servlet:

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

Each module of the archive is given a random name:

> 681737db-3621-4b1a-b77a-4f571b877126.ear
  > META-INF
  > 5f6d70e5-13f9-4d49-a32f-c7b3138da9fa.war
    > WEB-INF ...
  > 90772573-9202-4c77-b8b9-99b5869dd29f.jar
    > META-INF ...

I would expect the @ArquillianResource(SecurityServlet.class) to return:

http://localhost:8010/5f6d70e5-13f9-4d49-a32f-c7b3138da9fa

Current Behaviour

Instead, I get one of two results. If I use just @ArquillianResource I get in return http://localhost:8010/681737db-3621-4b1a-b77a-4f571b877126 which is the name of the EAR and not the web module.

If i use @ArquillianResource(SecurityServlet.class) 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)

Steps To Reproduce

  1. Run this test on a remote container

Additional Information

server.xml

<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>

pom.xml

<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>