Java 类org.springframework.boot.test.context.SpringBootTest.WebEnvironment 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootTestContextBootstrapper.java   
@Override
public TestContext buildTestContext() {
    TestContext context = super.buildTestContext();
    WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
    if (webEnvironment == WebEnvironment.MOCK && hasWebEnvironmentClasses()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
    }
    else if (webEnvironment != null && webEnvironment.isEmbedded()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, false);
    }
    return context;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootTestContextBootstrapper.java   
/**
 * Post process the property source properties, adding or removing elements as
 * required.
 * @param mergedConfig the merged context configuration
 * @param propertySourceProperties the property source properties to process
 */
protected void processPropertySourceProperties(
        MergedContextConfiguration mergedConfig,
        List<String> propertySourceProperties) {
    Class<?> testClass = mergedConfig.getTestClass();
    String[] properties = getProperties(testClass);
    if (!ObjectUtils.isEmpty(properties)) {
        // Added first so that inlined properties from @TestPropertySource take
        // precedence
        propertySourceProperties.addAll(0, Arrays.asList(properties));
    }
    if (getWebEnvironment(testClass) == WebEnvironment.RANDOM_PORT) {
        propertySourceProperties.add("server.port=0");
    }
}
项目:spring-boot-concourse    文件:SpringBootTestContextBootstrapper.java   
@Override
public TestContext buildTestContext() {
    TestContext context = super.buildTestContext();
    WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
    if (webEnvironment == WebEnvironment.MOCK && hasWebEnvironmentClasses()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
    }
    else if (webEnvironment != null && webEnvironment.isEmbedded()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, false);
    }
    return context;
}
项目:spring-boot-concourse    文件:SpringBootTestContextBootstrapper.java   
/**
 * Post process the property source properties, adding or removing elements as
 * required.
 * @param mergedConfig the merged context configuration
 * @param propertySourceProperties the property source properties to process
 */
protected void processPropertySourceProperties(
        MergedContextConfiguration mergedConfig,
        List<String> propertySourceProperties) {
    Class<?> testClass = mergedConfig.getTestClass();
    String[] properties = getProperties(testClass);
    if (!ObjectUtils.isEmpty(properties)) {
        // Added first so that inlined properties from @TestPropertySource take
        // precedence
        propertySourceProperties.addAll(0, Arrays.asList(properties));
    }
    if (getWebEnvironment(testClass) == WebEnvironment.RANDOM_PORT) {
        propertySourceProperties.add("server.port=0");
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootTestContextBootstrapper.java   
/**
 * 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 ? null : annotation.webEnvironment());
}
项目:spring-boot-concourse    文件:SpringBootTestContextBootstrapper.java   
/**
 * 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 ? null : annotation.webEnvironment());
}