Last active
April 10, 2018 09:09
-
-
Save JorgenRingen/f38b7fb810606081df9842ba54c15943 to your computer and use it in GitHub Desktop.
Test configuration for different spring profiles
This file contains hidden or 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
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
import org.junit.jupiter.api.DisplayName; | |
import org.junit.jupiter.api.Nested; | |
import org.junit.jupiter.api.Tag; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.extension.ExtendWith; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.test.context.ActiveProfiles; | |
import org.springframework.test.context.TestPropertySource; | |
import org.springframework.test.context.junit.jupiter.SpringExtension; | |
import static org.assertj.core.api.Assertions.assertThat; | |
/** | |
* Loads the application context with different profiles to validate configuration. | |
* | |
* @see ProfileTest | |
*/ | |
@DisplayName("Loading application context with different profiles") | |
@Tag("profileTest") | |
class SpringProfilesTest { | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"local", "embedded", "default"}) | |
class Local { | |
/** | |
* Example for how to validate different properties related to the specific profile | |
*/ | |
@Value("${server.context-path}") | |
private String contextPath; | |
@Test | |
void load() { | |
assertThat(contextPath).startsWith("/"); | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"devstaging", "embedded", "default"}) | |
class DevStaging { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"um", "embedded", "default"}) | |
class Um { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"sis", "embedded", "default"}) | |
class Sis { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"sis-kunde", "embedded", "default"}) | |
class SisKunde { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"tek", "embedded", "default"}) | |
class Tek { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"stm", "embedded", "default"}) | |
class Stm { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"atm", "embedded", "default"}) | |
class Atm { | |
@Test | |
void load() { | |
} | |
} | |
@Nested | |
@ProfileTest | |
@ActiveProfiles(profiles = {"prod", "embedded", "default"}) | |
class Prod { | |
@Test | |
void load() { | |
} | |
} | |
} | |
@ExtendWith(SpringExtension.class) | |
@SpringBootTest | |
@TestPropertySource(properties = {"akr.common.sikkerhet.enabled=true", "spring.datasource.jndi-name=false"}) | |
@Target(ElementType.TYPE) | |
@Retention(RetentionPolicy.RUNTIME) | |
@interface ProfileTest { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment