/** * 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"); } }
@Override public TestContext buildTestContext() { TestContext context = super.buildTestContext(); verifyConfiguration(context.getTestClass()); WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass()); if (webEnvironment == WebEnvironment.MOCK && deduceWebApplicationType() == WebApplicationType.SERVLET) { context.setAttribute(ACTIVATE_SERVLET_LISTENER, true); } else if (webEnvironment != null && webEnvironment.isEmbedded()) { context.setAttribute(ACTIVATE_SERVLET_LISTENER, false); } return context; }
@Override protected MergedContextConfiguration processMergedContextConfiguration( MergedContextConfiguration mergedConfig) { Class<?>[] classes = getOrFindConfigurationClasses(mergedConfig); List<String> propertySourceProperties = getAndProcessPropertySourceProperties( mergedConfig); mergedConfig = createModifiedConfig(mergedConfig, classes, StringUtils.toStringArray(propertySourceProperties)); WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass()); if (webEnvironment != null && isWebEnvironmentSupported(mergedConfig)) { WebApplicationType webApplicationType = getWebApplicationType(mergedConfig); if (webApplicationType == WebApplicationType.SERVLET && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) { WebAppConfiguration webAppConfiguration = AnnotatedElementUtils .findMergedAnnotation(mergedConfig.getTestClass(), WebAppConfiguration.class); String resourceBasePath = (webAppConfiguration != null) ? webAppConfiguration.value() : "src/main/webapp"; mergedConfig = new WebMergedContextConfiguration(mergedConfig, resourceBasePath); } else if (webApplicationType == WebApplicationType.REACTIVE && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) { return new ReactiveWebMergedContextConfiguration(mergedConfig); } } return mergedConfig; }