/** * Return the {@link WebEnvironment} type for this test or null if undefined. * @param testClass the source test class * @return the {@link WebEnvironment} or {@code null} */ protected WebEnvironment getWebEnvironment(Class<?> testClass) { SpringBootTest annotation = getAnnotation(testClass); return (annotation != null) ? annotation.webEnvironment() : null; }
protected void verifyConfiguration(Class<?> testClass) { SpringBootTest springBootTest = getAnnotation(testClass); if (springBootTest != null && (springBootTest.webEnvironment() == WebEnvironment.DEFINED_PORT || springBootTest.webEnvironment() == WebEnvironment.RANDOM_PORT) && getAnnotation(WebAppConfiguration.class, testClass) != null) { throw new IllegalStateException("@WebAppConfiguration should only be used " + "with @SpringBootTest when @SpringBootTest is configured with a " + "mock web environment. Please remove @WebAppConfiguration or " + "reconfigure @SpringBootTest."); } }
private boolean isEmbeddedWebEnvironment(MergedContextConfiguration config) { SpringBootTest annotation = AnnotatedElementUtils .findMergedAnnotation(config.getTestClass(), SpringBootTest.class); if (annotation != null && annotation.webEnvironment().isEmbedded()) { return true; } return false; }
@Override public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) { SpringBootTest annotation = AnnotatedElementUtils.getMergedAnnotation( mergedContextConfiguration.getTestClass(), SpringBootTest.class); if (annotation.webEnvironment().isEmbedded()) { registerTestRestTemplate(context); } }
@Override public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { SpringBootTest annotation = AnnotatedElementUtils .getMergedAnnotation(mergedConfig.getTestClass(), SpringBootTest.class); if (annotation.webEnvironment().isEmbedded()) { registerWebTestClient(context); } }