org.springframework.test.context.MergedContextConfiguration

Here are the examples of the java api org.springframework.test.context.MergedContextConfiguration taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

178 Examples 7

/**
 * Tests for {@link TypeExcludeFiltersContextCustomizerFactory}.
 *
 * @author Phillip Webb
 */
public clreplaced TypeExcludeFiltersContextCustomizerFactoryTests {

    private TypeExcludeFiltersContextCustomizerFactory factory = new TypeExcludeFiltersContextCustomizerFactory();

    private MergedContextConfiguration mergedContextConfiguration = mock(MergedContextConfiguration.clreplaced);

    private ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();

    @Test
    public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
        ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.clreplaced, null);
        replacedertThat(customizer).isNull();
    }

    @Test
    public void getContextCustomizerWhenHasAnnotationShouldReturnCustomizer() {
        ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.clreplaced, null);
        replacedertThat(customizer).isNotNull();
    }

    @Test
    public void hashCodeAndEquals() {
        ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithExcludeFilters.clreplaced, null);
        ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameExcludeFilters.clreplaced, null);
        ContextCustomizer customizer3 = this.factory.createContextCustomizer(WithDifferentExcludeFilters.clreplaced, null);
        replacedertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
        replacedertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2).isNotEqualTo(customizer3);
    }

    @Test
    public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
        ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.clreplaced, null);
        customizer.customizeContext(this.context, this.mergedContextConfiguration);
        this.context.refresh();
        TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.clreplaced);
        MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
        MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NoAnnotation.clreplaced.getName());
        replacedertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
        metadataReader = metadataReaderFactory.getMetadataReader(SimpleExclude.clreplaced.getName());
        replacedertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
        metadataReader = metadataReaderFactory.getMetadataReader(TestClreplacedAwareExclude.clreplaced.getName());
        replacedertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
    }

    static clreplaced NoAnnotation {
    }

    @TypeExcludeFilters({ SimpleExclude.clreplaced, TestClreplacedAwareExclude.clreplaced })
    static clreplaced WithExcludeFilters {
    }

    @TypeExcludeFilters({ TestClreplacedAwareExclude.clreplaced, SimpleExclude.clreplaced })
    static clreplaced WithSameExcludeFilters {
    }

    @TypeExcludeFilters(SimpleExclude.clreplaced)
    static clreplaced WithDifferentExcludeFilters {
    }

    static clreplaced SimpleExclude extends TypeExcludeFilter {

        @Override
        public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
            return metadataReader.getClreplacedMetadata().getClreplacedName().equals(getClreplaced().getName());
        }

        @Override
        public boolean equals(Object obj) {
            return obj.getClreplaced() == getClreplaced();
        }

        @Override
        public int hashCode() {
            return SimpleExclude.clreplaced.hashCode();
        }
    }

    static clreplaced TestClreplacedAwareExclude extends SimpleExclude {

        TestClreplacedAwareExclude(Clreplaced<?> testClreplaced) {
            replacedertThat(testClreplaced).isNotNull();
        }
    }
}

19 View Source File : WebMvcTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
    return new WebMergedContextConfiguration(super.processMergedContextConfiguration(mergedConfig), "");
}

19 View Source File : WebFluxTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
    return new ReactiveWebMergedContextConfiguration(super.processMergedContextConfiguration(mergedConfig));
}

19 View Source File : PropertyMappingContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    if (!this.propertySource.isEmpty()) {
        context.getEnvironment().getPropertySources().addFirst(this.propertySource);
    }
    context.getBeanFactory().registerSingleton(PropertyMappingCheckBeanPostProcessor.clreplaced.getName(), new PropertyMappingCheckBeanPostProcessor());
}

19 View Source File : TypeExcludeFiltersContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    if (!this.filters.isEmpty()) {
        context.getBeanFactory().registerSingleton(EXCLUDE_FILTER_BEAN_NAME, createDelegatingTypeExcludeFilter());
    }
}

19 View Source File : MockitoContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    if (context instanceof BeanDefinitionRegistry) {
        MockitoPostProcessor.register((BeanDefinitionRegistry) context, this.definitions);
    }
}

19 View Source File : SpringBootTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

/**
 * Create a new {@link MergedContextConfiguration} with different clreplacedes and
 * properties.
 * @param mergedConfig the source config
 * @param clreplacedes the replacement clreplacedes
 * @param propertySourceProperties the replacement properties
 * @return a new {@link MergedContextConfiguration}
 */
protected final MergedContextConfiguration createModifiedConfig(MergedContextConfiguration mergedConfig, Clreplaced<?>[] clreplacedes, String[] propertySourceProperties) {
    return new MergedContextConfiguration(mergedConfig.getTestClreplaced(), mergedConfig.getLocations(), clreplacedes, mergedConfig.getContextInitializerClreplacedes(), mergedConfig.getActiveProfiles(), mergedConfig.getPropertySourceLocations(), propertySourceProperties, mergedConfig.getContextCustomizers(), mergedConfig.getContextLoader(), getCacheAwareContextLoaderDelegate(), mergedConfig.getParent());
}

19 View Source File : SpringBootTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

protected Clreplaced<?>[] getOrFindConfigurationClreplacedes(MergedContextConfiguration mergedConfig) {
    Clreplaced<?>[] clreplacedes = mergedConfig.getClreplacedes();
    if (containsNonTestComponent(clreplacedes) || mergedConfig.hasLocations()) {
        return clreplacedes;
    }
    Clreplaced<?> found = new AnnotatedClreplacedFinder(SpringBootConfiguration.clreplaced).findFromClreplaced(mergedConfig.getTestClreplaced());
    replacedert.state(found != null, "Unable to find a @SpringBootConfiguration, you need to use " + "@ContextConfiguration or @SpringBootTest(clreplacedes=...) " + "with your test");
    logger.info("Found @SpringBootConfiguration " + found.getName() + " for test " + mergedConfig.getTestClreplaced());
    return merge(found, clreplacedes);
}

19 View Source File : SpringBootTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

private boolean isFromConfiguration(MergedContextConfiguration candidateConfig, ContextConfiguration configuration) {
    ContextConfigurationAttributes attributes = new ContextConfigurationAttributes(candidateConfig.getTestClreplaced(), configuration);
    Set<Clreplaced<?>> configurationClreplacedes = new HashSet<>(Arrays.asList(attributes.getClreplacedes()));
    for (Clreplaced<?> candidate : candidateConfig.getClreplacedes()) {
        if (configurationClreplacedes.contains(candidate)) {
            return true;
        }
    }
    return false;
}

19 View Source File : SpringBootTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

private List<String> getAndProcessPropertySourceProperties(MergedContextConfiguration mergedConfig) {
    List<String> propertySourceProperties = new ArrayList<>(Arrays.asList(mergedConfig.getPropertySourceProperties()));
    String differentiator = getDifferentiatorPropertySourceProperty();
    if (differentiator != null) {
        propertySourceProperties.add(differentiator);
    }
    processPropertySourceProperties(mergedConfig, propertySourceProperties);
    return propertySourceProperties;
}

19 View Source File : SpringBootTestContextBootstrapper.java
License : Apache License 2.0
Project Creator : yuanmabiji

private boolean isWebEnvironmentSupported(MergedContextConfiguration mergedConfig) {
    Clreplaced<?> testClreplaced = mergedConfig.getTestClreplaced();
    ContextHierarchy hierarchy = AnnotationUtils.getAnnotation(testClreplaced, ContextHierarchy.clreplaced);
    if (hierarchy == null || hierarchy.value().length == 0) {
        return true;
    }
    ContextConfiguration[] configurations = hierarchy.value();
    return isFromConfiguration(mergedConfig, configurations[configurations.length - 1]);
}

19 View Source File : SpringBootContextLoader.java
License : Apache License 2.0
Project Creator : yuanmabiji

private boolean isEmbeddedWebEnvironment(MergedContextConfiguration config) {
    SpringBootTest annotation = AnnotatedElementUtils.findMergedAnnotation(config.getTestClreplaced(), SpringBootTest.clreplaced);
    if (annotation != null && annotation.webEnvironment().isEmbedded()) {
        return true;
    }
    return false;
}

19 View Source File : ExcludeFilterContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    context.getBeanFactory().registerSingleton(TestTypeExcludeFilter.clreplaced.getName(), new TestTypeExcludeFilter());
}

19 View Source File : GenericXmlContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void configMustNotContainAnnotatedClreplacedes() throws Exception {
    GenericXmlContextLoader loader = new GenericXmlContextLoader();
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClreplaced(), EMPTY_STRING_ARRAY, new Clreplaced<?>[] { getClreplaced() }, EMPTY_STRING_ARRAY, loader);
    replacedertThatIllegalStateException().isThrownBy(() -> loader.loadContext(mergedConfig)).withMessageContaining("does not support annotated clreplacedes");
}

19 View Source File : GenericPropertiesContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void configMustNotContainAnnotatedClreplacedes() throws Exception {
    GenericPropertiesContextLoader loader = new GenericPropertiesContextLoader();
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClreplaced(), EMPTY_STRING_ARRAY, new Clreplaced<?>[] { getClreplaced() }, EMPTY_STRING_ARRAY, loader);
    replacedertThatIllegalStateException().isThrownBy(() -> loader.loadContext(mergedConfig)).withMessageContaining("does not support annotated clreplacedes");
}

19 View Source File : DelegatingSmartContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void loadContextWithoutLocationsAndConfigurationClreplacedes() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClreplaced(), EMPTY_STRING_ARRAY, EMPTY_CLreplaced_ARRAY, EMPTY_STRING_ARRAY, loader);
    replacedertThatIllegalStateException().isThrownBy(() -> loader.loadContext(mergedConfig)).withMessageStartingWith("Neither").withMessageContaining("was able to load an ApplicationContext from");
}

19 View Source File : DelegatingSmartContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void loadContextWithXmlConfig() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(XmlTestCase.clreplaced, new String[] { "clreplacedpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml" }, EMPTY_CLreplaced_ARRAY, EMPTY_STRING_ARRAY, loader);
    replacedertApplicationContextLoadsAndContainsFooString(mergedConfig);
}

19 View Source File : DelegatingSmartContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void loadContextWithConfigurationClreplaced() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClreplacedTestCase.clreplaced, EMPTY_STRING_ARRAY, new Clreplaced<?>[] { ConfigClreplacedTestCase.Config.clreplaced }, EMPTY_STRING_ARRAY, loader);
    replacedertApplicationContextLoadsAndContainsFooString(mergedConfig);
}

19 View Source File : DelegatingSmartContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

// --- SmartContextLoader - loadContext() ----------------------------------
@Test(expected = IllegalArgumentException.clreplaced)
public void loadContextWithNullConfig() throws Exception {
    MergedContextConfiguration mergedConfig = null;
    loader.loadContext(mergedConfig);
}

19 View Source File : DelegatingSmartContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

/**
 * @since 4.1
 */
@Test
public void loadContextWithLocationsAndConfigurationClreplacedes() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClreplaced(), new String[] { "test.xml" }, new Clreplaced<?>[] { getClreplaced() }, EMPTY_STRING_ARRAY, loader);
    replacedertThatIllegalStateException().isThrownBy(() -> loader.loadContext(mergedConfig)).withMessageStartingWith("Neither").withMessageContaining("declare either 'locations' or 'clreplacedes' but not both.");
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithAnnotationsAndOverriddenLocations() {
    Clreplaced<?> testClreplaced = OverriddenLocationsBar.clreplaced;
    String[] expectedLocations = array("/bar.xml");
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, expectedLocations, EMPTY_CLreplaced_ARRAY, AnnotationConfigContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() {
    Clreplaced<?> testClreplaced = PropertiesLocationsFoo.clreplaced;
    Clreplaced<? extends ContextLoader> expectedContextLoaderClreplaced = GenericPropertiesContextLoader.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, array("clreplacedpath:/foo.properties"), EMPTY_CLreplaced_ARRAY, expectedContextLoaderClreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithMetaAnnotationAndLocations() {
    Clreplaced<?> testClreplaced = MetaLocationsFoo.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, array("clreplacedpath:/foo.xml"), EMPTY_CLreplaced_ARRAY, DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClreplacedes() {
    Clreplaced<?> testClreplaced = PropertiesClreplacedesFoo.clreplaced;
    Clreplaced<? extends ContextLoader> expectedContextLoaderClreplaced = GenericPropertiesContextLoader.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, array(FooConfig.clreplaced), expectedContextLoaderClreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithBareAnnotations() {
    Clreplaced<?> testClreplaced = BareAnnotations.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, array("clreplacedpath:org/springframework/test/context/support/AbstractContextConfigurationUtilsTests$BareAnnotations-context.xml"), EMPTY_CLreplaced_ARRAY, DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildImplicitMergedConfigWithoutAnnotation() {
    Clreplaced<?> testClreplaced = Enigma.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, EMPTY_CLreplaced_ARRAY, DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAndInheritedAnnotationsAndClreplacedes() {
    Clreplaced<?> testClreplaced = ClreplacedesBar.clreplaced;
    Clreplaced<?>[] expectedClreplacedes = array(FooConfig.clreplaced, BarConfig.clreplaced);
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, expectedClreplacedes, AnnotationConfigContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Introduced to investigate claims made in a discussion on
 * <a href="https://stackoverflow.com/questions/24725438/what-could-cause-a-clreplaced-implementing-applicationlistenercontextrefreshedevent">Stack Overflow</a>.
 */
@Test
public void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClreplacedesOnSuperclreplaced() {
    Clreplaced<?> webTestClreplaced = WebClreplacedesFoo.clreplaced;
    Clreplaced<?> standardTestClreplaced = ClreplacedesFoo.clreplaced;
    WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClreplaced);
    MergedContextConfiguration standardMergedConfig = buildMergedContextConfiguration(standardTestClreplaced);
    replacedertEquals(webMergedConfig, webMergedConfig);
    replacedertEquals(standardMergedConfig, standardMergedConfig);
    replacedertNotEquals(standardMergedConfig, webMergedConfig);
    replacedertNotEquals(webMergedConfig, standardMergedConfig);
    replacedertMergedConfig(webMergedConfig, webTestClreplaced, EMPTY_STRING_ARRAY, array(FooConfig.clreplaced), WebDelegatingSmartContextLoader.clreplaced);
    replacedertMergedConfig(standardMergedConfig, standardTestClreplaced, EMPTY_STRING_ARRAY, array(FooConfig.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

private void buildMergedConfigWithMetaAnnotationAndClreplacedes(Clreplaced<?> testClreplaced) {
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, array(FooConfig.clreplaced, BarConfig.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAnnotationAndClreplacedes() {
    Clreplaced<?> testClreplaced = ClreplacedesFoo.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, array(FooConfig.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAndInheritedAnnotationsAndLocations() {
    Clreplaced<?> testClreplaced = LocationsBar.clreplaced;
    String[] expectedLocations = array("/foo.xml", "/bar.xml");
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, expectedLocations, EMPTY_CLreplaced_ARRAY, AnnotationConfigContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAnnotationAndLocations() {
    Clreplaced<?> testClreplaced = LocationsFoo.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, array("clreplacedpath:/foo.xml"), EMPTY_CLreplaced_ARRAY, DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsMergedConfigTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithAnnotationsAndOverriddenClreplacedes() {
    Clreplaced<?> testClreplaced = OverriddenClreplacedesBar.clreplaced;
    Clreplaced<?>[] expectedClreplacedes = array(BarConfig.clreplaced);
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, expectedClreplacedes, AnnotationConfigContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsContextInitializerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithSingleLocalInitializer() {
    Clreplaced<?> testClreplaced = SingleInitializer.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, EMPTY_CLreplaced_ARRAY, initializers(FooInitializer.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsContextInitializerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalInitializerAndConfigClreplaced() {
    Clreplaced<?> testClreplaced = InitializersFoo.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, clreplacedes(FooConfig.clreplaced), initializers(FooInitializer.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsContextInitializerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithLocalAndInheritedInitializer() {
    Clreplaced<?> testClreplaced = InitializersBar.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, clreplacedes(FooConfig.clreplaced, BarConfig.clreplaced), initializers(FooInitializer.clreplaced, BarInitializer.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsContextInitializerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithOverriddenInitializers() {
    Clreplaced<?> testClreplaced = OverriddenInitializersBar.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, clreplacedes(FooConfig.clreplaced, BarConfig.clreplaced), initializers(BarInitializer.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : BootstrapTestUtilsContextInitializerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void buildMergedConfigWithOverriddenInitializersAndClreplacedes() {
    Clreplaced<?> testClreplaced = OverriddenInitializersAndClreplacedesBar.clreplaced;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClreplaced);
    replacedertMergedConfig(mergedConfig, testClreplaced, EMPTY_STRING_ARRAY, clreplacedes(BarConfig.clreplaced), initializers(BarInitializer.clreplaced), DelegatingSmartContextLoader.clreplaced);
}

19 View Source File : AnnotationConfigContextLoaderTests.java
License : MIT License
Project Creator : Vip-Augus

/**
 * @since 4.0.4
 */
@Test
public void configMustNotContainLocations() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClreplaced(), new String[] { "config.xml" }, EMPTY_CLreplaced_ARRAY, EMPTY_STRING_ARRAY, contextLoader);
    replacedertThatIllegalStateException().isThrownBy(() -> contextLoader.loadContext(mergedConfig)).withMessageContaining("does not support resource locations");
}

19 View Source File : AbstractContextConfigurationUtilsTests.java
License : MIT License
Project Creator : Vip-Augus

void replacedertMergedConfig(MergedContextConfiguration mergedConfig, Clreplaced<?> expectedTestClreplaced, String[] expectedLocations, Clreplaced<?>[] expectedClreplacedes, Clreplaced<? extends ContextLoader> expectedContextLoaderClreplaced) {
    replacedertMergedConfig(mergedConfig, expectedTestClreplaced, expectedLocations, expectedClreplacedes, EMPTY_INITIALIZER_CLreplacedES, expectedContextLoaderClreplaced);
}

19 View Source File : HybridContextLoader.java
License : MIT License
Project Creator : Vip-Augus

@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
    // Order doesn't matter: <bean> always wins over @Bean.
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
    new AnnotatedBeanDefinitionReader(context).register(mergedConfig.getClreplacedes());
}

19 View Source File : LruContextCacheTests.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Unit tests for the LRU eviction policy in {@link DefaultContextCache}.
 *
 * @author Sam Brannen
 * @since 4.3
 * @see ContextCacheTests
 */
public clreplaced LruContextCacheTests {

    private static final MergedContextConfiguration abcConfig = config(Abc.clreplaced);

    private static final MergedContextConfiguration fooConfig = config(Foo.clreplaced);

    private static final MergedContextConfiguration barConfig = config(Bar.clreplaced);

    private static final MergedContextConfiguration bazConfig = config(Baz.clreplaced);

    private final ConfigurableApplicationContext abcContext = mock(ConfigurableApplicationContext.clreplaced);

    private final ConfigurableApplicationContext fooContext = mock(ConfigurableApplicationContext.clreplaced);

    private final ConfigurableApplicationContext barContext = mock(ConfigurableApplicationContext.clreplaced);

    private final ConfigurableApplicationContext bazContext = mock(ConfigurableApplicationContext.clreplaced);

    @Test(expected = IllegalArgumentException.clreplaced)
    public void maxCacheSizeNegativeOne() {
        new DefaultContextCache(-1);
    }

    @Test(expected = IllegalArgumentException.clreplaced)
    public void maxCacheSizeZero() {
        new DefaultContextCache(0);
    }

    @Test
    public void maxCacheSizeOne() {
        DefaultContextCache cache = new DefaultContextCache(1);
        replacedertEquals(0, cache.size());
        replacedertEquals(1, cache.getMaxSize());
        cache.put(fooConfig, fooContext);
        replacedertCacheContents(cache, "Foo");
        cache.put(fooConfig, fooContext);
        replacedertCacheContents(cache, "Foo");
        cache.put(barConfig, barContext);
        replacedertCacheContents(cache, "Bar");
        cache.put(fooConfig, fooContext);
        replacedertCacheContents(cache, "Foo");
    }

    @Test
    public void maxCacheSizeThree() {
        DefaultContextCache cache = new DefaultContextCache(3);
        replacedertEquals(0, cache.size());
        replacedertEquals(3, cache.getMaxSize());
        cache.put(fooConfig, fooContext);
        replacedertCacheContents(cache, "Foo");
        cache.put(fooConfig, fooContext);
        replacedertCacheContents(cache, "Foo");
        cache.put(barConfig, barContext);
        replacedertCacheContents(cache, "Foo", "Bar");
        cache.put(bazConfig, bazContext);
        replacedertCacheContents(cache, "Foo", "Bar", "Baz");
        cache.put(abcConfig, abcContext);
        replacedertCacheContents(cache, "Bar", "Baz", "Abc");
    }

    @Test
    public void ensureLruOrderingIsUpdated() {
        DefaultContextCache cache = new DefaultContextCache(3);
        // Note: when a new entry is added it is considered the MRU entry and inserted at the tail.
        cache.put(fooConfig, fooContext);
        cache.put(barConfig, barContext);
        cache.put(bazConfig, bazContext);
        replacedertCacheContents(cache, "Foo", "Bar", "Baz");
        // Note: the MRU entry is moved to the tail when accessed.
        cache.get(fooConfig);
        replacedertCacheContents(cache, "Bar", "Baz", "Foo");
        cache.get(barConfig);
        replacedertCacheContents(cache, "Baz", "Foo", "Bar");
        cache.get(bazConfig);
        replacedertCacheContents(cache, "Foo", "Bar", "Baz");
        cache.get(barConfig);
        replacedertCacheContents(cache, "Foo", "Baz", "Bar");
    }

    @Test
    public void ensureEvictedContextsAreClosed() {
        DefaultContextCache cache = new DefaultContextCache(2);
        cache.put(fooConfig, fooContext);
        cache.put(barConfig, barContext);
        replacedertCacheContents(cache, "Foo", "Bar");
        cache.put(bazConfig, bazContext);
        replacedertCacheContents(cache, "Bar", "Baz");
        verify(fooContext, times(1)).close();
        cache.put(abcConfig, abcContext);
        replacedertCacheContents(cache, "Baz", "Abc");
        verify(barContext, times(1)).close();
        verify(abcContext, never()).close();
        verify(bazContext, never()).close();
    }

    private static MergedContextConfiguration config(Clreplaced<?> clazz) {
        return new MergedContextConfiguration(null, null, new Clreplaced<?>[] { clazz }, null, null);
    }

    @SuppressWarnings("unchecked")
    private static void replacedertCacheContents(DefaultContextCache cache, String... expectedNames) {
        Map<MergedContextConfiguration, ApplicationContext> contextMap = (Map<MergedContextConfiguration, ApplicationContext>) ReflectionTestUtils.getField(cache, "contextMap");
        // @formatter:off
        List<String> actualNames = contextMap.keySet().stream().map(cfg -> cfg.getClreplacedes()[0]).map(Clreplaced::getSimpleName).collect(toList());
        // @formatter:on
        replacedertEquals(asList(expectedNames), actualNames);
    }

    private static clreplaced Abc {
    }

    private static clreplaced Foo {
    }

    private static clreplaced Bar {
    }

    private static clreplaced Baz {
    }
}

19 View Source File : WebTestContextBootstrapper.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Returns a {@link WebMergedContextConfiguration} if the test clreplaced in the
 * supplied {@code MergedContextConfiguration} is annotated with
 * {@link WebAppConfiguration @WebAppConfiguration} and otherwise returns
 * the supplied instance unmodified.
 */
@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
    WebAppConfiguration webAppConfiguration = AnnotatedElementUtils.findMergedAnnotation(mergedConfig.getTestClreplaced(), WebAppConfiguration.clreplaced);
    if (webAppConfiguration != null) {
        return new WebMergedContextConfiguration(mergedConfig, webAppConfiguration.value());
    } else {
        return mergedConfig;
    }
}

19 View Source File : MockServerContainerContextCustomizer.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
    if (context instanceof WebApplicationContext) {
        WebApplicationContext wac = (WebApplicationContext) context;
        ServletContext sc = wac.getServletContext();
        if (sc != null) {
            sc.setAttribute("javax.websocket.server.ServerContainer", new MockServerContainer());
        }
    }
}

19 View Source File : GenericXmlContextLoader.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClreplacedes() clreplacedes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
    if (mergedConfig.hasClreplacedes()) {
        String msg = String.format("Test clreplaced [%s] has been configured with @ContextConfiguration's 'clreplacedes' attribute %s, " + "but %s does not support annotated clreplacedes.", mergedConfig.getTestClreplaced().getName(), ObjectUtils.nullSafeToString(mergedConfig.getClreplacedes()), getClreplaced().getSimpleName());
        logger.error(msg);
        throw new IllegalStateException(msg);
    }
}

19 View Source File : GenericGroovyXmlContextLoader.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Load bean definitions into the supplied {@link GenericApplicationContext context}
 * from the locations in the supplied {@code MergedContextConfiguration} using a
 * {@link GroovyBeanDefinitionReader}.
 * @param context the context into which the bean definitions should be loaded
 * @param mergedConfig the merged context configuration
 * @see org.springframework.test.context.support.AbstractGenericContextLoader#loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
    new GroovyBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
}

19 View Source File : DefaultTestContext.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Default implementation of the {@link TestContext} interface.
 *
 * @author Sam Brannen
 * @author Juergen Hoeller
 * @author Rob Harrop
 * @since 4.0
 */
public clreplaced DefaultTestContext implements TestContext {

    private static final long serialVersionUID = -5827157174866681233L;

    private final Map<String, Object> attributes = new ConcurrentHashMap<>(4);

    private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate;

    private final MergedContextConfiguration mergedContextConfiguration;

    private final Clreplaced<?> testClreplaced;

    @Nullable
    private volatile Object testInstance;

    @Nullable
    private volatile Method testMethod;

    @Nullable
    private volatile Throwable testException;

    /**
     * <em>Copy constructor</em> for creating a new {@code DefaultTestContext}
     * based on the <em>attributes</em> and immutable state of the supplied context.
     * <p><em>Immutable state</em> includes all arguments supplied to the
     * {@linkplain #DefaultTestContext(Clreplaced, MergedContextConfiguration,
     * CacheAwareContextLoaderDelegate) standard constructor}.
     * @throws NullPointerException if the supplied {@code DefaultTestContext}
     * is {@code null}
     */
    public DefaultTestContext(DefaultTestContext testContext) {
        this(testContext.testClreplaced, testContext.mergedContextConfiguration, testContext.cacheAwareContextLoaderDelegate);
        this.attributes.putAll(testContext.attributes);
    }

    /**
     * Construct a new {@code DefaultTestContext} from the supplied arguments.
     * @param testClreplaced the test clreplaced for this test context
     * @param mergedContextConfiguration the merged application context
     * configuration for this test context
     * @param cacheAwareContextLoaderDelegate the delegate to use for loading
     * and closing the application context for this test context
     */
    public DefaultTestContext(Clreplaced<?> testClreplaced, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {
        replacedert.notNull(testClreplaced, "Test Clreplaced must not be null");
        replacedert.notNull(mergedContextConfiguration, "MergedContextConfiguration must not be null");
        replacedert.notNull(cacheAwareContextLoaderDelegate, "CacheAwareContextLoaderDelegate must not be null");
        this.testClreplaced = testClreplaced;
        this.mergedContextConfiguration = mergedContextConfiguration;
        this.cacheAwareContextLoaderDelegate = cacheAwareContextLoaderDelegate;
    }

    /**
     * Determine if the {@linkplain ApplicationContext application context} for
     * this test context is present in the context cache.
     * @return {@code true} if the application context has already been loaded
     * and stored in the context cache
     * @since 5.2
     * @see #getApplicationContext()
     * @see CacheAwareContextLoaderDelegate#isContextLoaded
     */
    @Override
    public boolean hasApplicationContext() {
        return this.cacheAwareContextLoaderDelegate.isContextLoaded(this.mergedContextConfiguration);
    }

    /**
     * Get the {@linkplain ApplicationContext application context} for this
     * test context.
     * <p>The default implementation delegates to the {@link CacheAwareContextLoaderDelegate}
     * that was supplied when this {@code TestContext} was constructed.
     * @throws IllegalStateException if the context returned by the context
     * loader delegate is not <em>active</em> (i.e., has been closed)
     * @see CacheAwareContextLoaderDelegate#loadContext
     */
    public ApplicationContext getApplicationContext() {
        ApplicationContext context = this.cacheAwareContextLoaderDelegate.loadContext(this.mergedContextConfiguration);
        if (context instanceof ConfigurableApplicationContext) {
            @SuppressWarnings("resource")
            ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
            replacedert.state(cac.isActive(), () -> "The ApplicationContext loaded for [" + this.mergedContextConfiguration + "] is not active. This may be due to one of the following reasons: " + "1) the context was closed programmatically by user code; " + "2) the context was closed during parallel test execution either " + "according to @DirtiesContext semantics or due to automatic eviction " + "from the ContextCache due to a maximum cache size policy.");
        }
        return context;
    }

    /**
     * Mark the {@linkplain ApplicationContext application context} replacedociated
     * with this test context as <em>dirty</em> (i.e., by removing it from the
     * context cache and closing it).
     * <p>The default implementation delegates to the {@link CacheAwareContextLoaderDelegate}
     * that was supplied when this {@code TestContext} was constructed.
     * @see CacheAwareContextLoaderDelegate#closeContext
     */
    public void markApplicationContextDirty(@Nullable HierarchyMode hierarchyMode) {
        this.cacheAwareContextLoaderDelegate.closeContext(this.mergedContextConfiguration, hierarchyMode);
    }

    public final Clreplaced<?> getTestClreplaced() {
        return this.testClreplaced;
    }

    public final Object getTestInstance() {
        Object testInstance = this.testInstance;
        replacedert.state(testInstance != null, "No test instance");
        return testInstance;
    }

    public final Method getTestMethod() {
        Method testMethod = this.testMethod;
        replacedert.state(testMethod != null, "No test method");
        return testMethod;
    }

    @Override
    @Nullable
    public final Throwable getTestException() {
        return this.testException;
    }

    public void updateState(@Nullable Object testInstance, @Nullable Method testMethod, @Nullable Throwable testException) {
        this.testInstance = testInstance;
        this.testMethod = testMethod;
        this.testException = testException;
    }

    @Override
    public void setAttribute(String name, @Nullable Object value) {
        replacedert.notNull(name, "Name must not be null");
        synchronized (this.attributes) {
            if (value != null) {
                this.attributes.put(name, value);
            } else {
                this.attributes.remove(name);
            }
        }
    }

    @Override
    @Nullable
    public Object getAttribute(String name) {
        replacedert.notNull(name, "Name must not be null");
        return this.attributes.get(name);
    }

    @Override
    @Nullable
    public Object removeAttribute(String name) {
        replacedert.notNull(name, "Name must not be null");
        return this.attributes.remove(name);
    }

    @Override
    public boolean hasAttribute(String name) {
        replacedert.notNull(name, "Name must not be null");
        return this.attributes.containsKey(name);
    }

    @Override
    public String[] attributeNames() {
        synchronized (this.attributes) {
            return StringUtils.toStringArray(this.attributes.keySet());
        }
    }

    /**
     * Provide a String representation of this test context's state.
     */
    @Override
    public String toString() {
        return new ToStringCreator(this).append("testClreplaced", this.testClreplaced).append("testInstance", this.testInstance).append("testMethod", this.testMethod).append("testException", this.testException).append("mergedContextConfiguration", this.mergedContextConfiguration).append("attributes", this.attributes).toString();
    }
}

19 View Source File : AbstractTestContextBootstrapper.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Process the supplied, newly instantiated {@link MergedContextConfiguration} instance.
 * <p>The returned {@link MergedContextConfiguration} instance may be a wrapper
 * around or a replacement for the original.
 * <p>The default implementation simply returns the supplied instance unmodified.
 * <p>Concrete subclreplacedes may choose to return a specialized subclreplaced of
 * {@link MergedContextConfiguration} based on properties in the supplied instance.
 * @param mergedConfig the {@code MergedContextConfiguration} to process; never {@code null}
 * @return a fully initialized {@code MergedContextConfiguration}; never {@code null}
 */
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
    return mergedConfig;
}

19 View Source File : AbstractGenericContextLoader.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Validate the supplied {@link MergedContextConfiguration} with respect to
 * what this context loader supports.
 * <p>The default implementation is a <em>no-op</em> but can be overridden by
 * subclreplacedes as appropriate.
 * @param mergedConfig the merged configuration to validate
 * @throws IllegalStateException if the supplied configuration is not valid
 * for this context loader
 * @since 4.0.4
 */
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
// no-op
}

19 View Source File : AbstractDelegatingSmartContextLoader.java
License : MIT License
Project Creator : Vip-Augus

private boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) {
    if (loader == getAnnotationConfigLoader()) {
        return (mergedConfig.hasClreplacedes() && !mergedConfig.hasLocations());
    } else {
        return (mergedConfig.hasLocations() && !mergedConfig.hasClreplacedes());
    }
}

See More Examples