Skip to content

Instantly share code, notes, and snippets.

@jakzal
Created June 19, 2019 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakzal/ba936c67d9470adf4fe972a96a82961f to your computer and use it in GitHub Desktop.
Save jakzal/ba936c67d9470adf4fe972a96a82961f to your computer and use it in GitHub Desktop.
Overriding Spring Boot test configuration on the CI server
spring:
profiles:
active: local,ci
datasource:
url: jdbc:postgresql://my-ci-dot-com:5432/cidb
username: ci
password: ci
spring:
jpa:
hibernate:
dialect: org.hibernate.dialect.Postgres95Dialect
ddl-auto: none
show-sql: true
datasource:
url: jdbc:postgresql://localhost:5432/testdb
username: test
password: test
schema: classpath:db/schema/schema-postgresql.sql
initialization-mode: always
liquibase:
drop-first: true
package acme.test;
import org.springframework.test.context.ActiveProfilesResolver;
public class EnvironmentActiveProfileResolver implements ActiveProfilesResolver {
@Override
public String[] resolve(Class<?> aClass) {
return new String[]{System.getenv("BUILD_ID") == null ? "test" : "test,ci"};
}
}
package acme.test;
import org.junit.jupiter.api.Tag;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import javax.validation.OverridesAttribute;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Tag("slow")
@ActiveProfiles(resolver = EnvironmentActiveProfileResolver.class)
public @interface RepositoryTest {
@OverridesAttribute(constraint = SpringBootTest.class, name = "properties")
String[] properties() default {"spring.main.banner-mode=off"};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment