Disable ConfigurationProperties scanning for slice tests

Closes gh-16659
This commit is contained in:
Madhura Bhave
2019-05-10 08:38:10 -07:00
parent 930186e505
commit 3b4ff7d746
48 changed files with 1454 additions and 3 deletions

View File

@@ -0,0 +1,90 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure;
import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextCustomizer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Madhura Bhave
*/
public class OverrideConfigurationPropertiesScanContextCustomizerFactoryTests {
private OverrideConfigurationPropertiesScanContextCustomizerFactory factory = new OverrideConfigurationPropertiesScanContextCustomizerFactory();
@Test
public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(NoAnnotation.class, null);
assertThat(customizer).isNull();
}
@Test
public void getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithAnnotationEnabledTrue.class, null);
assertThat(customizer).isNull();
}
@Test
public void getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
assertThat(customizer).isNotNull();
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
customizer.customizeContext(context, null);
String property = context.getEnvironment().getProperty(
ConfigurationPropertiesScan.CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY);
assertThat(property).isEqualTo("false");
}
@Test
public void hashCodeAndEquals() {
ContextCustomizer customizer1 = this.factory
.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
ContextCustomizer customizer2 = this.factory
.createContextCustomizer(WithSameAnnotation.class, null);
assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2);
}
static class NoAnnotation {
}
@OverrideConfigurationPropertiesScan(enabled = true)
static class WithAnnotationEnabledTrue {
}
@OverrideConfigurationPropertiesScan(enabled = false)
static class WithAnnotationEnabledFalse {
}
@OverrideConfigurationPropertiesScan(enabled = false)
static class WithSameAnnotation {
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.jdbc;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataJdbcTest @DataJdbcTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@DataJdbcTest
public class DataJdbcTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.jdbc;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataJdbcTest @DataJdbcTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.ldap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataLdapTest @DataLdapTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@DataLdapTest
public class DataLdapTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.ldap;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataLdapTest @DataLdapTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.mongo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataMongoTest @DataMongoTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@DataMongoTest
public class DataMongoTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.mongo;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataMongoTest @DataMongoTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.neo4j;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.Neo4jContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.testsupport.testcontainers.SkippableContainer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataNeo4jTest @DataNeo4jTest}.
*
* @author Madhura Bhave
*/
@ContextConfiguration(
initializers = DataNeo4jTestConfigurationPropertiesScanDisabledTests.Initializer.class)
@Testcontainers
@DataNeo4jTest
public class DataNeo4jTestConfigurationPropertiesScanDisabledTests {
@Container
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
() -> new Neo4jContainer<>().withAdminPassword(null));
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues
.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.neo4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataNeo4jTest @DataNeo4jTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.redis;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataRedisTest @DataRedisTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@DataRedisTest
public class DataRedisTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.data.redis;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataRedisTest @DataRedisTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.jdbc;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link JdbcTest @JdbcTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.jdbc;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link JdbcTest @JdbcTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@JdbcTest
public class JdbcTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.jooq;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link JooqTest @JooqTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.jooq;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link JooqTest @JooqTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@JooqTest
public class JooqTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.json;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.app.ExampleJsonApplication;
import org.springframework.boot.test.autoconfigure.json.app.ExampleProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link JsonTest @JsonTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@JsonTest
@ContextConfiguration(classes = ExampleJsonApplication.class)
public class JsonTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.json.app;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link JsonTest @JsonTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.orm.jpa;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataJpaTest @DataJpaTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@DataJpaTest
public class DataJpaTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.orm.jpa;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataJpaTest @DataJpaTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.override;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleTestProperties {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.override.scan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.override.scan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan;
/**
* Example {@link SpringBootApplication @SpringBootApplication} for use with
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} tests.
*
* @author Madhura Bhave
*/
@SpringBootApplication
public class OverrideConfigurationPropertiesScanApplication {
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.override.scan;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan;
import org.springframework.boot.test.autoconfigure.override.ExampleTestProperties;
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Integration tests for
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} when
* {@code enabled} is {@code false}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@BootstrapWith(SpringBootTestContextBootstrapper.class)
@OverrideConfigurationPropertiesScan(enabled = false)
@Import(OverrideConfigurationPropertiesScanEnabledFalseIntegrationTests.TestConfiguration.class)
public class OverrideConfigurationPropertiesScanEnabledFalseIntegrationTests {
@Autowired
private ApplicationContext context;
@Test
public void disabledConfigurationPropertiesScan() {
ApplicationContext context = this.context;
assertThat(context.getBean(ExampleTestProperties.class)).isNotNull();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBean(ExampleProperties.class));
}
@Configuration
@EnableConfigurationProperties(ExampleTestProperties.class)
static class TestConfiguration {
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.override.scan;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan;
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} when
* {@code enabled} is {@code true}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@OverrideConfigurationPropertiesScan(enabled = true)
@BootstrapWith(SpringBootTestContextBootstrapper.class)
public class OverrideConfigurationPropertiesScanEnabledTrueIntegrationTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationPropertiesScanEnabled() {
assertThat(this.context.getBean(ExampleProperties.class)).isNotNull();
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.client;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link RestClientTest @RestClientTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.client;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link RestClientTest @RestClientTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@RestClientTest
public class RestClientTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link WebFluxTest @WebFluxTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link WebFluxTest @WebFluxTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@WebFluxTest
public class WebFluxTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link WebMvcTest @WebMvcTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link WebMvcTest @WebMvcTest}.
*
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@WebMvcTest
public class WebMvcTestConfigurationPropertiesScanDisabledTests {
@Autowired
private ApplicationContext context;
@Test
public void configurationProperiesScanDisabled() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ExampleProperties.class));
}
}