Created
June 19, 2019 22:37
-
-
Save jakzal/ba936c67d9470adf4fe972a96a82961f to your computer and use it in GitHub Desktop.
Overriding Spring Boot test configuration on the CI server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
profiles: | |
active: local,ci | |
datasource: | |
url: jdbc:postgresql://my-ci-dot-com:5432/cidb | |
username: ci | |
password: ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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