I wrote a simple test, like the code here, that alone runs correctly.
But if I try to write a second test using the same annotation @MeecrowaveConfig I have an error.
In other words I cannot have two class with the @MeecrowaveConfig annotation, because when the second Meecrowave instance starts the test fail with:
SEVERE: An error occurred while starting application context path : []
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.558 s <<< FAILURE! - in it.freedev.Test1
[ERROR] it.freedev.Test1 Time elapsed: 1.558 s <<< ERROR!
java.lang.IllegalStateException: Error starting child
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].[]]
Caused by: org.apache.webbeans.exception.DuplicateDefinitionException: PassivationCapable bean id is not unique: SERVLET_CONTEXT#interface javax.servlet.ServletContext#@javax.enterprise.inject.Default(),@javax.enterprise.inject.Any(), bean:ServletContext, WebBeansType:SERVLET_CONTEXT, Name:null, API Types:[java.lang.Object,javax.servlet.ServletContext], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any], existing: ServletContext, WebBeansType:SERVLET_CONTEXT, Name:null, API Types:[java.lang.Object,javax.servlet.ServletContext], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]
As said if I copy this class into a new class Test2, when I try to run all the tests the second fails with the error reported above.
@MeecrowaveConfig(scanningPackageIncludes="it.lux.ml4c.catalog")
public class Test1 {
@ConfigurationInject
public Meecrowave.Builder config;
private static HttpClient client;
@BeforeAll
public static void init() {
client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2) // this is the default
.build();
}
@Test
public void whenOpenApiCalls_thenIsAvailable() throws IOException, InterruptedException {
final HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:" + config.getHttpPort() + "/api/v1/openapi"))
.GET().build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode());
}
}
After many tries I find out that
tomcatWrapLoaderannotation parameter helps to avoid the problem.