Skip to content

Commit

Permalink
moves localstack to testcontainers dev mode (#77)
Browse files Browse the repository at this point in the history
* moving localstack to testcontainers dev mode

* adds missing bracket

* fixes issue with localstack in gradle project
  • Loading branch information
rajadilipkolli committed Jun 13, 2023
1 parent 485d4a3 commit c76aa2e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 46 deletions.
1 change: 0 additions & 1 deletion generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ module.exports = class extends BaseGenerator {
'TestApplication.java'
];
if(configOptions.features.includes("localstack")) {
testJavaTemplates.push('common/LocalStackConfig.java');
testJavaTemplates.push('SqsListenerIntegrationTest.java');
}
this.generateTestJavaCode(configOptions, testJavaTemplates);
Expand Down
24 changes: 21 additions & 3 deletions generators/server/templates/app/src/test/java/TestApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<%_ if (databaseType === 'mariadb') { _%>
import org.testcontainers.containers.MariaDBContainer;
<%_ } _%>
<%_ if (features.includes('localstack')) { _%>
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.localstack.LocalStackContainer;
<%_ } _%>
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestApplication {
Expand All @@ -21,17 +26,30 @@ public class TestApplication {
@ServiceConnection
<%_ if (databaseType === 'postgresql') { _%>
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>("<%= POSTGRESQL_IMAGE %>");
return new PostgreSQLContainer<>(DockerImageName.parse("<%= POSTGRESQL_IMAGE %>"));
}
<%_ } _%>
<%_ if (databaseType === 'mysql') { _%>
MySQLContainer<?> sqlContainer () {
return new MySQLContainer<>("<%= MYSQL_IMAGE %>");
return new MySQLContainer<>(DockerImageName.parse("<%= MYSQL_IMAGE %>"));
}
<%_ } _%>
<%_ if (databaseType === 'mariadb') { _%>
MariaDBContainer<?> sqlContainer () {
return new MariaDBContainer<>("<%= MARIADB_IMAGE %>");
return new MariaDBContainer<>(DockerImageName.parse("<%= MARIADB_IMAGE %>"));
}
<%_ } _%>

<%_ if (features.includes('localstack')) { _%>
@Bean
LocalStackContainer localStackContainer(DynamicPropertyRegistry propertyRegistry) {
LocalStackContainer localStackContainer =
new LocalStackContainer(DockerImageName.parse("<%= LOCALSTACK_IMAGE %>"));
propertyRegistry.add("spring.cloud.aws.endpoint", localStackContainer::getEndpoint);
propertyRegistry.add("spring.cloud.aws.region.static", localStackContainer::getRegion);
propertyRegistry.add("spring.cloud.aws.credentials.access-key", localStackContainer::getAccessKey);
propertyRegistry.add("spring.cloud.aws.credentials.secret-key", localStackContainer::getSecretKey);
return localStackContainer;
}
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
<%_ if (features.includes('localstack')) { _%>
import org.springframework.test.context.ContextConfiguration;
<%_ } _%>
import org.springframework.test.web.servlet.MockMvc;

@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(webEnvironment = RANDOM_PORT)
<%_ if (features.includes('localstack')) { _%>
@ContextConfiguration(initializers = {LocalStackConfig.class})
<%_ } _%>
@AutoConfigureMockMvc
@Import(TestApplication.class)
public abstract class AbstractIntegrationTest {
Expand Down

This file was deleted.

8 changes: 1 addition & 7 deletions generators/server/templates/gradle/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ spring_dependency_management_version=<%= SPRING_DEP_MNGMNT_VERSION %>
logstash_logback_encoder_version=<%= LOGSTASH_LOGBACK_ENCODER %>
commons_io_version=<%= COMMONS_IO_VERSION %>
springdoc_openapi_version=<%= SPRINGDOC_OPENAPI_VERSION %>
testcontainers_version=<%= TEST_CONTAINERS_VERSION %>

org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
testcontainers.version=<%= TEST_CONTAINERS_VERSION %>

0 comments on commit c76aa2e

Please sign in to comment.