spring-projects-experimental / spring-boot-testjars

67 stars 6 forks source link

CommonsExecWebServer with Testcontainers #40

Open rwinch opened 9 months ago

rwinch commented 9 months ago

We should demonstrate how CommonsExecWebServer can support Testcontainers.

There are a few ways that I can think of for this to work:

1) The project that wants to use CommonsExecWebServer can include Testcontainers in it, start the Testcontainer and then point the CommonsExecWebServer application to the Testcontainer using system properties to configure the Environment

2) Add Testcontainers & the test configuration to the classpath of the application started by CommonsExecWebServer.

return CommonsExecWebServerFactoryBean.builder()
    .classpath((classpath) -> classpath
        // ... etc
        // This is similar to Main in the oauth2-login-custom-config except it will have the Testcontainers config in it
        // See https://github.com/spring-projects-experimental/spring-boot-testjars/blob/5644aa84f0c74c374ce58aabb39c9f1ca9735414/samples/oauth2-login-custom-config/src/test/java/example/oauth2/login/TestOauth2LoginMain.java#L41
        .recursive(TestMessagesMain.class) 
    );

3) Users that want to make it easier to consume their application in this way can publish a variant of their application (with a classifier in Maven) and that would start up the application using Testcontainers. This idea probably needs to be flushed out more