Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.test.context.ContextCustomizer;
|
||||
|
||||
@@ -27,30 +27,30 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class OverrideAutoConfigurationContextCustomizerFactoryTests {
|
||||
class OverrideAutoConfigurationContextCustomizerFactoryTests {
|
||||
|
||||
private OverrideAutoConfigurationContextCustomizerFactory factory = new OverrideAutoConfigurationContextCustomizerFactory();
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
|
||||
void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
|
||||
assertThat(customizer).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull() {
|
||||
void getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledTrue.class, null);
|
||||
assertThat(customizer).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer() {
|
||||
void getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeAndEquals() {
|
||||
void hashCodeAndEquals() {
|
||||
ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
|
||||
ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameAnnotation.class, null);
|
||||
assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
|
||||
|
||||
@@ -23,12 +23,10 @@ import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,9 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringBootDependencyInjectionTestExecutionListenerPostConstructIntegrationTests {
|
||||
class SpringBootDependencyInjectionTestExecutionListenerPostConstructIntegrationTests {
|
||||
|
||||
private List<String> calls = new ArrayList<>();
|
||||
|
||||
@@ -51,7 +48,7 @@ public class SpringBootDependencyInjectionTestExecutionListenerPostConstructInte
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postConstructShouldBeInvokedOnlyOnce() {
|
||||
void postConstructShouldBeInvokedOnlyOnce() {
|
||||
// gh-6874
|
||||
assertThat(this.calls).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -41,21 +41,19 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class SpringBootDependencyInjectionTestExecutionListenerTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule out = new OutputCaptureRule();
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SpringBootDependencyInjectionTestExecutionListenerTests {
|
||||
|
||||
private SpringBootDependencyInjectionTestExecutionListener reportListener = new SpringBootDependencyInjectionTestExecutionListener();
|
||||
|
||||
@Test
|
||||
public void orderShouldBeSameAsDependencyInjectionTestExecutionListener() {
|
||||
void orderShouldBeSameAsDependencyInjectionTestExecutionListener() {
|
||||
Ordered injectionListener = new DependencyInjectionTestExecutionListener();
|
||||
assertThat(this.reportListener.getOrder()).isEqualTo(injectionListener.getOrder());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFailingTestInstanceShouldPrintReport() throws Exception {
|
||||
void prepareFailingTestInstanceShouldPrintReport(CapturedOutput capturedOutput) throws Exception {
|
||||
TestContext testContext = mock(TestContext.class);
|
||||
given(testContext.getTestInstance()).willThrow(new IllegalStateException());
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
@@ -68,13 +66,12 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
|
||||
catch (IllegalStateException ex) {
|
||||
// Expected
|
||||
}
|
||||
this.out.expect(containsString("CONDITIONS EVALUATION REPORT"));
|
||||
this.out.expect(containsString("Positive matches"));
|
||||
this.out.expect(containsString("Negative matches"));
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT").contains("Positive matches")
|
||||
.contains("Negative matches");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void originalFailureIsThrownWhenReportGenerationFails() throws Exception {
|
||||
void originalFailureIsThrownWhenReportGenerationFails() throws Exception {
|
||||
TestContext testContext = mock(TestContext.class);
|
||||
IllegalStateException originalFailure = new IllegalStateException();
|
||||
given(testContext.getTestInstance()).willThrow(originalFailure);
|
||||
|
||||
@@ -19,8 +19,12 @@ package org.springframework.boot.test.autoconfigure.cache;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.launcher.Launcher;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
import org.junit.platform.launcher.core.LauncherFactory;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -32,7 +36,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleEntity;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -43,51 +46,55 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
|
||||
static ApplicationContext contextFromTest;
|
||||
|
||||
@Test
|
||||
public void testClassesThatHaveSameAnnotationsShareAContext() throws InitializationError {
|
||||
RunNotifier notifier = new RunNotifier();
|
||||
new SpringJUnit4ClassRunner(DataJpaTest1.class).run(notifier);
|
||||
void testClassesThatHaveSameAnnotationsShareAContext() throws InitializationError {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
new SpringJUnit4ClassRunner(DataJpaTest3.class).run(notifier);
|
||||
executeTests(DataJpaTest3.class);
|
||||
ApplicationContext test2Context = contextFromTest;
|
||||
assertThat(test1Context).isSameAs(test2Context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws InitializationError {
|
||||
RunNotifier notifier = new RunNotifier();
|
||||
new SpringJUnit4ClassRunner(DataJpaTest1.class).run(notifier);
|
||||
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws InitializationError {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
new SpringJUnit4ClassRunner(DataJpaTest2.class).run(notifier);
|
||||
executeTests(DataJpaTest2.class);
|
||||
ApplicationContext test2Context = contextFromTest;
|
||||
assertThat(test1Context).isSameAs(test2Context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext()
|
||||
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext()
|
||||
throws InitializationError {
|
||||
RunNotifier notifier = new RunNotifier();
|
||||
new SpringJUnit4ClassRunner(DataJpaTest1.class).run(notifier);
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
new SpringJUnit4ClassRunner(DataJpaTest4.class).run(notifier);
|
||||
executeTests(DataJpaTest4.class);
|
||||
ApplicationContext test2Context = contextFromTest;
|
||||
assertThat(test1Context).isNotSameAs(test2Context);
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) {
|
||||
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
|
||||
.selectors(DiscoverySelectors.selectClass(testClass)).build();
|
||||
Launcher launcher = LauncherFactory.create();
|
||||
launcher.execute(request);
|
||||
}
|
||||
|
||||
@DataJpaTest
|
||||
@ContextConfiguration(classes = EmptyConfig.class)
|
||||
@Unrelated1
|
||||
public static class DataJpaTest1 {
|
||||
static class DataJpaTest1 {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
contextFromTest = this.context;
|
||||
}
|
||||
|
||||
@@ -96,13 +103,13 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
@DataJpaTest
|
||||
@ContextConfiguration(classes = EmptyConfig.class)
|
||||
@Unrelated2
|
||||
public static class DataJpaTest2 {
|
||||
static class DataJpaTest2 {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
contextFromTest = this.context;
|
||||
}
|
||||
|
||||
@@ -111,13 +118,13 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
@DataJpaTest
|
||||
@ContextConfiguration(classes = EmptyConfig.class)
|
||||
@Unrelated1
|
||||
public static class DataJpaTest3 {
|
||||
static class DataJpaTest3 {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
contextFromTest = this.context;
|
||||
}
|
||||
|
||||
@@ -126,13 +133,13 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
@DataJpaTest(showSql = false)
|
||||
@ContextConfiguration(classes = EmptyConfig.class)
|
||||
@Unrelated1
|
||||
public static class DataJpaTest4 {
|
||||
static class DataJpaTest4 {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
contextFromTest = this.context;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -26,7 +25,6 @@ import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.support.NoOpCacheManager;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -35,16 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureCache
|
||||
public class AutoConfigureCacheIntegrationTests {
|
||||
class AutoConfigureCacheIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void shouldConfigureNoOpCacheManager() {
|
||||
void shouldConfigureNoOpCacheManager() {
|
||||
CacheManager bean = this.applicationContext.getBean(CacheManager.class);
|
||||
assertThat(bean).isInstanceOf(NoOpCacheManager.class);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -27,7 +26,6 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,16 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureCache
|
||||
public class AutoConfigureCacheWithExistingCacheManagerIntegrationTests {
|
||||
class AutoConfigureCacheWithExistingCacheManagerIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void shouldNotReplaceExistingCacheManager() {
|
||||
void shouldNotReplaceExistingCacheManager() {
|
||||
CacheManager bean = this.applicationContext.getBean(CacheManager.class);
|
||||
assertThat(bean).isInstanceOf(ConcurrentMapCacheManager.class);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.data.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurati
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -39,11 +37,10 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJdbcTest
|
||||
@TestPropertySource(
|
||||
properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql")
|
||||
public class DataJdbcTestIntegrationTests {
|
||||
class DataJdbcTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleRepository repository;
|
||||
@@ -58,31 +55,31 @@ public class DataJdbcTestIntegrationTests {
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
this.jdbcTemplate.update("INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (1, 'a', 'alpha')");
|
||||
this.jdbcTemplate.update("INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (2, 'b', 'bravo')");
|
||||
assertThat(this.repository.findAll()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
|
||||
void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).isEqualTo("H2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleComponent() {
|
||||
void didNotInjectExampleComponent() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleComponent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flywayAutoConfigurationWasImported() {
|
||||
void flywayAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liquibaseAutoConfigurationWasImported() {
|
||||
void liquibaseAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.jdbc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJdbcTest(properties = "spring.profiles.active=test")
|
||||
public class DataJdbcTestPropertiesIntegrationTests {
|
||||
class DataJdbcTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.data.ldap;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.ldap.query.LdapQuery;
|
||||
import org.springframework.ldap.query.LdapQueryBuilder;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -39,11 +37,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataLdapTest
|
||||
@TestPropertySource(properties = { "spring.ldap.embedded.base-dn=dc=spring,dc=org",
|
||||
"spring.ldap.embedded.ldif=classpath:org/springframework/boot/test/autoconfigure/data/ldap/schema.ldif" })
|
||||
public class DataLdapTestIntegrationTests {
|
||||
class DataLdapTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
@@ -55,7 +52,7 @@ public class DataLdapTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
LdapQuery ldapQuery = LdapQueryBuilder.query().where("cn").is("Bob Smith");
|
||||
Optional<ExampleEntry> entry = this.exampleRepository.findOne(ldapQuery);
|
||||
assertThat(entry.isPresent()).isTrue();
|
||||
@@ -66,7 +63,7 @@ public class DataLdapTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleService() {
|
||||
void didNotInjectExampleService() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.ldap;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataLdapTest(properties = "spring.profiles.active=test")
|
||||
public class DataLdapTestPropertiesIntegrationTests {
|
||||
class DataLdapTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.ldap;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
@@ -25,7 +24,6 @@ import org.springframework.ldap.query.LdapQuery;
|
||||
import org.springframework.ldap.query.LdapQueryBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,17 +32,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataLdapTest(includeFilters = @Filter(Service.class))
|
||||
@TestPropertySource(properties = { "spring.ldap.embedded.base-dn=dc=spring,dc=org",
|
||||
"spring.ldap.embedded.ldif=classpath:org/springframework/boot/test/autoconfigure/data/ldap/schema.ldif" })
|
||||
public class DataLdapTestWithIncludeFilterIntegrationTests {
|
||||
class DataLdapTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleService service;
|
||||
|
||||
@Test
|
||||
public void testService() {
|
||||
void testService() {
|
||||
LdapQuery ldapQuery = LdapQueryBuilder.query().where("cn").is("Will Smith");
|
||||
assertThat(this.service.hasEntry(ldapQuery)).isFalse();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.mongo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -33,9 +31,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest
|
||||
public class DataMongoTestIntegrationTests {
|
||||
class DataMongoTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
@@ -47,7 +44,7 @@ public class DataMongoTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
ExampleDocument exampleDocument = new ExampleDocument();
|
||||
exampleDocument.setText("Look, new @DataMongoTest!");
|
||||
exampleDocument = this.exampleRepository.save(exampleDocument);
|
||||
@@ -56,7 +53,7 @@ public class DataMongoTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleService() {
|
||||
void didNotInjectExampleService() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.mongo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest(properties = "spring.profiles.active=test")
|
||||
public class DataMongoTestPropertiesIntegrationTests {
|
||||
class DataMongoTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,10 @@ package org.springframework.boot.test.autoconfigure.data.mongo;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,9 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest
|
||||
public class DataMongoTestReactiveIntegrationTests {
|
||||
class DataMongoTestReactiveIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ReactiveMongoTemplate mongoTemplate;
|
||||
@@ -43,7 +40,7 @@ public class DataMongoTestReactiveIntegrationTests {
|
||||
private ExampleReactiveRepository exampleRepository;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
ExampleDocument exampleDocument = new ExampleDocument();
|
||||
exampleDocument.setText("Look, new @DataMongoTest!");
|
||||
exampleDocument = this.exampleRepository.save(exampleDocument).block(Duration.ofSeconds(30));
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.mongo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest(includeFilters = @Filter(Service.class))
|
||||
public class DataMongoTestWithIncludeFilterIntegrationTests {
|
||||
class DataMongoTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleService service;
|
||||
|
||||
@Test
|
||||
public void testService() {
|
||||
void testService() {
|
||||
assertThat(this.service.hasCollection("foobar")).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
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.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -43,12 +42,11 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
@ContextConfiguration(initializers = DataNeo4jTestIntegrationTests.Initializer.class)
|
||||
@DataNeo4jTest
|
||||
@Testcontainers
|
||||
public class DataNeo4jTestIntegrationTests {
|
||||
@DisabledWithoutDockerTestcontainers
|
||||
class DataNeo4jTestIntegrationTests {
|
||||
|
||||
@Container
|
||||
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
|
||||
() -> new Neo4jContainer<>().withAdminPassword(null));
|
||||
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>().withAdminPassword(null);
|
||||
|
||||
@Autowired
|
||||
private Session session;
|
||||
@@ -60,7 +58,7 @@ public class DataNeo4jTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
ExampleGraph exampleGraph = new ExampleGraph();
|
||||
exampleGraph.setDescription("Look, new @DataNeo4jTest!");
|
||||
assertThat(exampleGraph.getId()).isNull();
|
||||
@@ -70,7 +68,7 @@ public class DataNeo4jTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleService() {
|
||||
void didNotInjectExampleService() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
||||
}
|
||||
@@ -79,7 +77,7 @@ public class DataNeo4jTestIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getBoltUrl())
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,10 @@ 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.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.testsupport.testcontainers.SkippableContainer;
|
||||
import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -37,20 +36,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@Testcontainers
|
||||
@DisabledWithoutDockerTestcontainers
|
||||
@ContextConfiguration(initializers = DataNeo4jTestPropertiesIntegrationTests.Initializer.class)
|
||||
@DataNeo4jTest(properties = "spring.profiles.active=test")
|
||||
public class DataNeo4jTestPropertiesIntegrationTests {
|
||||
class DataNeo4jTestPropertiesIntegrationTests {
|
||||
|
||||
@Container
|
||||
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
|
||||
() -> new Neo4jContainer<>().withAdminPassword(null));
|
||||
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>().withAdminPassword(null);
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
@@ -58,7 +56,7 @@ public class DataNeo4jTestPropertiesIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getBoltUrl())
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,10 @@ 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.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.testsupport.testcontainers.SkippableContainer;
|
||||
import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
@@ -38,20 +37,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Eddú Meléndez
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@Testcontainers
|
||||
@DisabledWithoutDockerTestcontainers
|
||||
@ContextConfiguration(initializers = DataNeo4jTestWithIncludeFilterIntegrationTests.Initializer.class)
|
||||
@DataNeo4jTest(includeFilters = @Filter(Service.class))
|
||||
public class DataNeo4jTestWithIncludeFilterIntegrationTests {
|
||||
class DataNeo4jTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Container
|
||||
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
|
||||
() -> new Neo4jContainer<>().withAdminPassword(null));
|
||||
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>().withAdminPassword(null);
|
||||
|
||||
@Autowired
|
||||
private ExampleService service;
|
||||
|
||||
@Test
|
||||
public void testService() {
|
||||
void testService() {
|
||||
assertThat(this.service.hasNode(ExampleGraph.class)).isFalse();
|
||||
}
|
||||
|
||||
@@ -59,7 +57,7 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getBoltUrl())
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.DisabledWithoutDockerTestcontainers;
|
||||
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
@@ -42,10 +42,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Jayaram Pradhan
|
||||
*/
|
||||
@Testcontainers
|
||||
@DisabledWithoutDockerTestcontainers
|
||||
@ContextConfiguration(initializers = DataRedisTestIntegrationTests.Initializer.class)
|
||||
@DataRedisTest
|
||||
public class DataRedisTestIntegrationTests {
|
||||
class DataRedisTestIntegrationTests {
|
||||
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
@@ -62,7 +62,7 @@ public class DataRedisTestIntegrationTests {
|
||||
private static final Charset CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
PersonHash personHash = new PersonHash();
|
||||
personHash.setDescription("Look, new @DataRedisTest!");
|
||||
assertThat(personHash.getId()).isNull();
|
||||
@@ -74,7 +74,7 @@ public class DataRedisTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleService() {
|
||||
void didNotInjectExampleService() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class DataRedisTestIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort())
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.boot.test.autoconfigure.data.redis;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
|
||||
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -36,19 +36,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@Testcontainers
|
||||
@DisabledWithoutDockerTestcontainers
|
||||
@ContextConfiguration(initializers = DataRedisTestPropertiesIntegrationTests.Initializer.class)
|
||||
@DataRedisTest(properties = "spring.profiles.active=test")
|
||||
public class DataRedisTestPropertiesIntegrationTests {
|
||||
class DataRedisTestPropertiesIntegrationTests {
|
||||
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
static final RedisContainer redis = new RedisContainer();
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DataRedisTestPropertiesIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort())
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.boot.test.autoconfigure.data.redis;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
|
||||
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -36,13 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Jayaram Pradhan
|
||||
*/
|
||||
@Testcontainers
|
||||
@DisabledWithoutDockerTestcontainers
|
||||
@ContextConfiguration(initializers = DataRedisTestWithIncludeFilterIntegrationTests.Initializer.class)
|
||||
@DataRedisTest(includeFilters = @Filter(Service.class))
|
||||
public class DataRedisTestWithIncludeFilterIntegrationTests {
|
||||
class DataRedisTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
static final RedisContainer redis = new RedisContainer();
|
||||
|
||||
@Autowired
|
||||
private ExampleRepository exampleRepository;
|
||||
@@ -51,7 +51,7 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
|
||||
private ExampleService service;
|
||||
|
||||
@Test
|
||||
public void testService() {
|
||||
void testService() {
|
||||
PersonHash personHash = new PersonHash();
|
||||
personHash.setDescription("Look, new @DataRedisTest!");
|
||||
assertThat(personHash.getId()).isNull();
|
||||
@@ -63,7 +63,7 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort())
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
@@ -41,38 +41,38 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class FilterAnnotationsTests {
|
||||
class FilterAnnotationsTests {
|
||||
|
||||
@Test
|
||||
public void filterAnnotation() throws Exception {
|
||||
void filterAnnotation() throws Exception {
|
||||
FilterAnnotations filterAnnotations = get(FilterByAnnotation.class);
|
||||
assertThat(match(filterAnnotations, ExampleWithAnnotation.class)).isTrue();
|
||||
assertThat(match(filterAnnotations, ExampleWithoutAnnotation.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterAssignableType() throws Exception {
|
||||
void filterAssignableType() throws Exception {
|
||||
FilterAnnotations filterAnnotations = get(FilterByType.class);
|
||||
assertThat(match(filterAnnotations, ExampleWithAnnotation.class)).isFalse();
|
||||
assertThat(match(filterAnnotations, ExampleWithoutAnnotation.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterCustom() throws Exception {
|
||||
void filterCustom() throws Exception {
|
||||
FilterAnnotations filterAnnotations = get(FilterByCustom.class);
|
||||
assertThat(match(filterAnnotations, ExampleWithAnnotation.class)).isFalse();
|
||||
assertThat(match(filterAnnotations, ExampleWithoutAnnotation.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterAspectJ() throws Exception {
|
||||
void filterAspectJ() throws Exception {
|
||||
FilterAnnotations filterAnnotations = get(FilterByAspectJ.class);
|
||||
assertThat(match(filterAnnotations, ExampleWithAnnotation.class)).isFalse();
|
||||
assertThat(match(filterAnnotations, ExampleWithoutAnnotation.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterRegex() throws Exception {
|
||||
void filterRegex() throws Exception {
|
||||
FilterAnnotations filterAnnotations = get(FilterByRegex.class);
|
||||
assertThat(match(filterAnnotations, ExampleWithAnnotation.class)).isFalse();
|
||||
assertThat(match(filterAnnotations, ExampleWithoutAnnotation.class)).isTrue();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.filter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.context.TypeExcludeFilter;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -35,7 +35,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class TypeExcludeFiltersContextCustomizerFactoryTests {
|
||||
class TypeExcludeFiltersContextCustomizerFactoryTests {
|
||||
|
||||
private TypeExcludeFiltersContextCustomizerFactory factory = new TypeExcludeFiltersContextCustomizerFactory();
|
||||
|
||||
@@ -44,19 +44,19 @@ public class TypeExcludeFiltersContextCustomizerFactoryTests {
|
||||
private ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
|
||||
void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
|
||||
assertThat(customizer).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasAnnotationShouldReturnCustomizer() {
|
||||
void getContextCustomizerWhenHasAnnotationShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeAndEquals() {
|
||||
void hashCodeAndEquals() {
|
||||
ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
|
||||
ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameExcludeFilters.class, null);
|
||||
ContextCustomizer customizer3 = this.factory.createContextCustomizer(WithDifferentExcludeFilters.class, null);
|
||||
@@ -65,7 +65,7 @@ public class TypeExcludeFiltersContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
|
||||
void getContextCustomizerShouldAddExcludeFilters() throws Exception {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
|
||||
customizer.customizeContext(this.context, this.mergedContextConfiguration);
|
||||
this.context.refresh();
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -38,16 +36,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Greg Potter
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase
|
||||
public class AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests {
|
||||
class AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||
void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||
// Look that the datasource is replaced with an H2 DB.
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("H2");
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,15 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@AutoConfigureTestDatabase
|
||||
public class AutoConfigureTestDatabaseWithNoDatabaseIntegrationTests {
|
||||
class AutoConfigureTestDatabaseWithNoDatabaseIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testContextLoads() {
|
||||
void testContextLoads() {
|
||||
// gh-6897
|
||||
assertThat(this.context).isNotNull();
|
||||
assertThat(this.context.getBeanNamesForType(DataSource.class)).isNotEmpty();
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.util.Collection;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurati
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -41,11 +39,10 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@TestPropertySource(
|
||||
properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql")
|
||||
public class JdbcTestIntegrationTests {
|
||||
class JdbcTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
@@ -57,7 +54,7 @@ public class JdbcTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testJdbcTemplate() {
|
||||
void testJdbcTemplate() {
|
||||
ExampleRepository repository = new ExampleRepository(this.jdbcTemplate);
|
||||
repository.save(new ExampleEntity(1, "John"));
|
||||
Collection<ExampleEntity> entities = repository.findAll();
|
||||
@@ -68,24 +65,24 @@ public class JdbcTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
|
||||
void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).isEqualTo("H2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleRepository() {
|
||||
void didNotInjectExampleRepository() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flywayAutoConfigurationWasImported() {
|
||||
void flywayAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liquibaseAutoConfigurationWasImported() {
|
||||
void liquibaseAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest(properties = "spring.profiles.active=test")
|
||||
public class JdbcTestPropertiesIntegrationTests {
|
||||
class JdbcTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,12 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -35,17 +33,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.AUTO_CONFIGURED,
|
||||
connection = EmbeddedDatabaseConnection.HSQL)
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void replacesAutoConfiguredDataSource() throws Exception {
|
||||
void replacesAutoConfiguredDataSource() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,16 +30,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.AUTO_CONFIGURED)
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void usesDefaultEmbeddedDatabase() throws Exception {
|
||||
void usesDefaultEmbeddedDatabase() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
// @AutoConfigureTestDatabase would use H2 but HSQL is manually defined
|
||||
assertThat(product).startsWith("HSQL");
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -38,16 +36,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQL)
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||
void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||
// H2 is explicitly defined but HSQL is the override.
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
|
||||
@@ -18,11 +18,9 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,16 +30,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void usesDefaultEmbeddedDatabase() throws Exception {
|
||||
void usesDefaultEmbeddedDatabase() throws Exception {
|
||||
// HSQL is explicitly defined and should not be replaced
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -39,17 +37,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQL)
|
||||
@TestPropertySource(properties = "spring.test.database.replace=ANY")
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||
void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||
// H2 is explicitly defined but HSQL is the override.
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
|
||||
@@ -18,15 +18,13 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -36,17 +34,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQL)
|
||||
@TestPropertySource(properties = "spring.test.database.replace=AUTO_CONFIGURED")
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void replacesAutoConfiguredDataSource() throws Exception {
|
||||
void replacesAutoConfiguredDataSource() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
}
|
||||
|
||||
@@ -18,12 +18,10 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -33,16 +31,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest
|
||||
@TestPropertySource(properties = "spring.test.database.replace=NONE")
|
||||
public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyNoneIntegrationTests {
|
||||
class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyNoneIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void usesDefaultEmbeddedDatabase() throws Exception {
|
||||
void usesDefaultEmbeddedDatabase() throws Exception {
|
||||
// HSQL is explicitly defined and should not be replaced
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,17 +30,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JdbcTest(includeFilters = @Filter(Repository.class))
|
||||
@TestPropertySource(
|
||||
properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql")
|
||||
public class JdbcTestWithIncludeFilterIntegrationTests {
|
||||
class JdbcTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleRepository repository;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
this.repository.save(new ExampleEntity(42, "Smith"));
|
||||
ExampleEntity entity = this.repository.findById(42);
|
||||
assertThat(entity).isNotNull();
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.test.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
@@ -36,18 +36,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TestDatabaseAutoConfigurationTests {
|
||||
class TestDatabaseAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void replaceWithNoDataSourceAvailable() {
|
||||
void replaceWithNoDataSourceAvailable() {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(DataSource.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceWithUniqueDatabase() {
|
||||
void replaceWithUniqueDatabase() {
|
||||
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class).run((context) -> {
|
||||
DataSource datasource = context.getBean(DataSource.class);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
|
||||
|
||||
@@ -20,8 +20,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -40,9 +38,8 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
||||
*
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JooqTest
|
||||
public class JooqTestIntegrationTests {
|
||||
class JooqTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DSLContext dsl;
|
||||
@@ -54,31 +51,31 @@ public class JooqTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testDSLContext() {
|
||||
void testDSLContext() {
|
||||
assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES").fetchOne(0, Integer.class))
|
||||
.isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useDefinedDataSource() throws Exception {
|
||||
void useDefinedDataSource() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("HSQL");
|
||||
assertThat(this.dsl.configuration().dialect()).isEqualTo(SQLDialect.HSQLDB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleComponent() {
|
||||
void didNotInjectExampleComponent() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleComponent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flywayAutoConfigurationWasImported() {
|
||||
void flywayAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liquibaseAutoConfigurationWasImported() {
|
||||
void liquibaseAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.jooq;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JooqTest(properties = "spring.profiles.active=test")
|
||||
public class JooqTestPropertiesIntegrationTests {
|
||||
class JooqTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,11 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -35,10 +33,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JooqTest
|
||||
@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.H2)
|
||||
public class JooqTestWithAutoConfigureTestDatabaseIntegrationTests {
|
||||
class JooqTestWithAutoConfigureTestDatabaseIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DSLContext dsl;
|
||||
@@ -47,7 +44,7 @@ public class JooqTestWithAutoConfigureTestDatabaseIntegrationTests {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void replacesAutoConfiguredDataSource() throws Exception {
|
||||
void replacesAutoConfiguredDataSource() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).startsWith("H2");
|
||||
assertThat(this.dsl.configuration().dialect()).isEqualTo(SQLDialect.H2);
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.json;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.json.app.ExampleBasicObject;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.boot.test.json.JacksonTester;
|
||||
import org.springframework.boot.test.json.JsonContent;
|
||||
import org.springframework.boot.test.json.JsonbTester;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -41,10 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Madhura Bhave
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JsonTest
|
||||
@ContextConfiguration(classes = ExampleJsonApplication.class)
|
||||
public class JsonTestIntegrationTests {
|
||||
class JsonTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private BasicJsonTester basicJson;
|
||||
@@ -65,39 +62,39 @@ public class JsonTestIntegrationTests {
|
||||
private JsonbTester<ExampleBasicObject> jsonbJson;
|
||||
|
||||
@Test
|
||||
public void basicJson() {
|
||||
void basicJson() {
|
||||
assertThat(this.basicJson.from("{\"a\":\"b\"}")).hasJsonPathStringValue("@.a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jacksonBasic() throws Exception {
|
||||
void jacksonBasic() throws Exception {
|
||||
ExampleBasicObject object = new ExampleBasicObject();
|
||||
object.setValue("spring");
|
||||
assertThat(this.jacksonBasicJson.write(object)).isEqualToJson("example.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jacksonCustom() throws Exception {
|
||||
void jacksonCustom() throws Exception {
|
||||
ExampleCustomObject object = new ExampleCustomObject("spring");
|
||||
assertThat(this.jacksonCustomJson.write(object)).isEqualToJson("example.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gson() throws Exception {
|
||||
void gson() throws Exception {
|
||||
ExampleBasicObject object = new ExampleBasicObject();
|
||||
object.setValue("spring");
|
||||
assertThat(this.gsonJson.write(object)).isEqualToJson("example.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonb() throws Exception {
|
||||
void jsonb() throws Exception {
|
||||
ExampleBasicObject object = new ExampleBasicObject();
|
||||
object.setValue("spring");
|
||||
assertThat(this.jsonbJson.write(object)).isEqualToJson("example.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customView() throws Exception {
|
||||
void customView() throws Exception {
|
||||
ExampleJsonObjectWithView object = new ExampleJsonObjectWithView();
|
||||
object.setValue("spring");
|
||||
JsonContent<ExampleJsonObjectWithView> content = this.jacksonWithViewJson
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.json;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JsonTest(properties = "spring.profiles.active=test")
|
||||
public class JsonTestPropertiesIntegrationTests {
|
||||
class JsonTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.json;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.json.app.ExampleBasicObject;
|
||||
@@ -27,7 +26,6 @@ import org.springframework.boot.test.json.GsonTester;
|
||||
import org.springframework.boot.test.json.JacksonTester;
|
||||
import org.springframework.boot.test.json.JsonbTester;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,11 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@JsonTest
|
||||
@AutoConfigureJsonTesters(enabled = false)
|
||||
@ContextConfiguration(classes = ExampleJsonApplication.class)
|
||||
public class JsonTestWithAutoConfigureJsonTestersTests {
|
||||
class JsonTestWithAutoConfigureJsonTestersTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
private BasicJsonTester basicJson;
|
||||
@@ -56,22 +53,22 @@ public class JsonTestWithAutoConfigureJsonTestersTests {
|
||||
private JsonbTester<ExampleBasicObject> jsonbTester;
|
||||
|
||||
@Test
|
||||
public void basicJson() {
|
||||
void basicJson() {
|
||||
assertThat(this.basicJson).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jackson() {
|
||||
void jackson() {
|
||||
assertThat(this.jacksonTester).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gson() {
|
||||
void gson() {
|
||||
assertThat(this.gsonTester).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonb() {
|
||||
void jsonb() {
|
||||
assertThat(this.jsonbTester).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.json;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.json.app.ExampleBasicObject;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.boot.test.json.GsonTester;
|
||||
import org.springframework.boot.test.json.JacksonTester;
|
||||
import org.springframework.boot.test.json.JsonbTester;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -38,11 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureJsonTesters
|
||||
@ContextConfiguration(classes = ExampleJsonApplication.class)
|
||||
public class SpringBootTestWithAutoConfigureJsonTestersTests {
|
||||
class SpringBootTestWithAutoConfigureJsonTestersTests {
|
||||
|
||||
@Autowired
|
||||
private BasicJsonTester basicJson;
|
||||
@@ -57,7 +54,7 @@ public class SpringBootTestWithAutoConfigureJsonTestersTests {
|
||||
private JsonbTester<ExampleBasicObject> jsonbTester;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
void contextLoads() {
|
||||
assertThat(this.basicJson).isNotNull();
|
||||
assertThat(this.jacksonTester).isNotNull();
|
||||
assertThat(this.jsonbTester).isNotNull();
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.orm.jpa;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurati
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -40,10 +38,9 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJpaTest
|
||||
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
|
||||
public class DataJpaTestIntegrationTests {
|
||||
class DataJpaTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private TestEntityManager entities;
|
||||
@@ -61,7 +58,7 @@ public class DataJpaTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testEntityManager() {
|
||||
void testEntityManager() {
|
||||
ExampleEntity entity = this.entities.persist(new ExampleEntity("spring", "123"));
|
||||
this.entities.flush();
|
||||
Object id = this.entities.getId(entity);
|
||||
@@ -70,7 +67,7 @@ public class DataJpaTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityManagerPersistAndGetId() {
|
||||
void testEntityManagerPersistAndGetId() {
|
||||
Long id = this.entities.persistAndGetId(new ExampleEntity("spring", "123"), Long.class);
|
||||
assertThat(id).isNotNull();
|
||||
String reference = this.jdbcTemplate.queryForObject("SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?",
|
||||
@@ -79,7 +76,7 @@ public class DataJpaTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
void testRepository() {
|
||||
this.entities.persist(new ExampleEntity("spring", "123"));
|
||||
this.entities.persist(new ExampleEntity("boot", "124"));
|
||||
this.entities.flush();
|
||||
@@ -88,24 +85,24 @@ public class DataJpaTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
|
||||
void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
|
||||
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||
assertThat(product).isEqualTo("H2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didNotInjectExampleComponent() {
|
||||
void didNotInjectExampleComponent() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleComponent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flywayAutoConfigurationWasImported() {
|
||||
void flywayAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liquibaseAutoConfigurationWasImported() {
|
||||
void liquibaseAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.orm.jpa;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJpaTest(properties = "spring.profiles.active=test")
|
||||
public class DataJpaTestPropertiesIntegrationTests {
|
||||
class DataJpaTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnitUtil;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class TestEntityManagerTests {
|
||||
class TestEntityManagerTests {
|
||||
|
||||
@Mock
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
@@ -52,7 +52,7 @@ public class TestEntityManagerTests {
|
||||
|
||||
private TestEntityManager testEntityManager;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.testEntityManager = new TestEntityManager(this.entityManagerFactory);
|
||||
@@ -60,13 +60,13 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenEntityManagerIsNullShouldThrowException() {
|
||||
void createWhenEntityManagerIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new TestEntityManager(null))
|
||||
.withMessageContaining("EntityManagerFactory must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistAndGetIdShouldPersistAndGetId() {
|
||||
void persistAndGetIdShouldPersistAndGetId() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
||||
@@ -76,7 +76,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistAndGetIdForTypeShouldPersistAndGetId() {
|
||||
void persistAndGetIdForTypeShouldPersistAndGetId() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
||||
@@ -86,7 +86,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistShouldPersist() {
|
||||
void persistShouldPersist() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
TestEntity result = this.testEntityManager.persist(entity);
|
||||
@@ -95,7 +95,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistAndFlushShouldPersistAndFlush() {
|
||||
void persistAndFlushShouldPersistAndFlush() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
TestEntity result = this.testEntityManager.persistAndFlush(entity);
|
||||
@@ -105,7 +105,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistFlushFindShouldPersistAndFlushAndFind() {
|
||||
void persistFlushFindShouldPersistAndFlushAndFind() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
TestEntity found = new TestEntity();
|
||||
@@ -118,7 +118,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeShouldMerge() {
|
||||
void mergeShouldMerge() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.entityManager.merge(entity)).willReturn(entity);
|
||||
@@ -128,7 +128,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeShouldRemove() {
|
||||
void removeShouldRemove() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
this.testEntityManager.remove(entity);
|
||||
@@ -136,7 +136,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findShouldFind() {
|
||||
void findShouldFind() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.entityManager.find(TestEntity.class, 123)).willReturn(entity);
|
||||
@@ -145,14 +145,14 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flushShouldFlush() {
|
||||
void flushShouldFlush() {
|
||||
bindEntityManager();
|
||||
this.testEntityManager.flush();
|
||||
verify(this.entityManager).flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshShouldRefresh() {
|
||||
void refreshShouldRefresh() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
this.testEntityManager.refresh(entity);
|
||||
@@ -160,14 +160,14 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearShouldClear() {
|
||||
void clearShouldClear() {
|
||||
bindEntityManager();
|
||||
this.testEntityManager.clear();
|
||||
verify(this.entityManager).clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detachShouldDetach() {
|
||||
void detachShouldDetach() {
|
||||
bindEntityManager();
|
||||
TestEntity entity = new TestEntity();
|
||||
this.testEntityManager.detach(entity);
|
||||
@@ -175,7 +175,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdForTypeShouldGetId() {
|
||||
void getIdForTypeShouldGetId() {
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
||||
Integer result = this.testEntityManager.getId(entity, Integer.class);
|
||||
@@ -183,7 +183,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdForTypeWhenTypeIsWrongShouldThrowException() {
|
||||
void getIdForTypeWhenTypeIsWrongShouldThrowException() {
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.testEntityManager.getId(entity, Long.class))
|
||||
@@ -192,7 +192,7 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdShouldGetId() {
|
||||
void getIdShouldGetId() {
|
||||
TestEntity entity = new TestEntity();
|
||||
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
||||
Object result = this.testEntityManager.getId(entity);
|
||||
@@ -200,13 +200,13 @@ public class TestEntityManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntityManagerShouldGetEntityManager() {
|
||||
void getEntityManagerShouldGetEntityManager() {
|
||||
bindEntityManager();
|
||||
assertThat(this.testEntityManager.getEntityManager()).isEqualTo(this.entityManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntityManagerWhenNotSetShouldThrowException() {
|
||||
void getEntityManagerWhenNotSetShouldThrowException() {
|
||||
assertThatIllegalStateException().isThrownBy(this.testEntityManager::getEntityManager)
|
||||
.withMessageContaining("No transactional EntityManager found");
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.override;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,7 +28,7 @@ import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
|
||||
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 org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -39,17 +39,17 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@OverrideAutoConfiguration(enabled = false)
|
||||
@BootstrapWith(SpringBootTestContextBootstrapper.class)
|
||||
@ImportAutoConfiguration(ExampleTestConfig.class)
|
||||
public class OverrideAutoConfigurationEnabledFalseIntegrationTests {
|
||||
class OverrideAutoConfigurationEnabledFalseIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void disabledAutoConfiguration() {
|
||||
void disabledAutoConfiguration() {
|
||||
ApplicationContext context = this.context;
|
||||
assertThat(context.getBean(ExampleTestConfig.class)).isNotNull();
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.override;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -27,7 +27,7 @@ import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
|
||||
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 org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,17 +37,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@OverrideAutoConfiguration(enabled = true)
|
||||
@BootstrapWith(SpringBootTestContextBootstrapper.class)
|
||||
@ImportAutoConfiguration(ExampleTestConfig.class)
|
||||
public class OverrideAutoConfigurationEnabledTrueIntegrationTests {
|
||||
class OverrideAutoConfigurationEnabledTrueIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void autoConfiguredContext() {
|
||||
void autoConfiguredContext() {
|
||||
ApplicationContext context = this.context;
|
||||
assertThat(context.getBean(OverrideAutoConfigurationSpringBootApplication.class)).isNotNull();
|
||||
assertThat(context.getBean(ConfigurationPropertiesBindingPostProcessor.class)).isNotNull();
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.boot.test.autoconfigure.properties;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
@@ -32,65 +32,65 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class AnnotationsPropertySourceTests {
|
||||
class AnnotationsPropertySourceTests {
|
||||
|
||||
@Test
|
||||
public void createWhenSourceIsNullShouldThrowException() {
|
||||
void createWhenSourceIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new AnnotationsPropertySource(null))
|
||||
.withMessageContaining("Property source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenHasNoAnnotationShouldBeEmpty() {
|
||||
void propertiesWhenHasNoAnnotationShouldBeEmpty() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(NoAnnotation.class);
|
||||
assertThat(source.getPropertyNames()).isEmpty();
|
||||
assertThat(source.getProperty("value")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenHasTypeLevelAnnotationShouldUseAttributeName() {
|
||||
void propertiesWhenHasTypeLevelAnnotationShouldUseAttributeName() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(TypeLevel.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("value");
|
||||
assertThat(source.getProperty("value")).isEqualTo("abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenHasTypeLevelWithPrefixShouldUsePrefixedName() {
|
||||
void propertiesWhenHasTypeLevelWithPrefixShouldUsePrefixedName() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(TypeLevelWithPrefix.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("test.value");
|
||||
assertThat(source.getProperty("test.value")).isEqualTo("abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenHasAttributeLevelWithPrefixShouldUsePrefixedName() {
|
||||
void propertiesWhenHasAttributeLevelWithPrefixShouldUsePrefixedName() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(AttributeLevelWithPrefix.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("test");
|
||||
assertThat(source.getProperty("test")).isEqualTo("abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenHasTypeAndAttributeLevelWithPrefixShouldUsePrefixedName() {
|
||||
void propertiesWhenHasTypeAndAttributeLevelWithPrefixShouldUsePrefixedName() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(TypeAndAttributeLevelWithPrefix.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("test.example");
|
||||
assertThat(source.getProperty("test.example")).isEqualTo("abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenNotMappedAtTypeLevelShouldIgnoreAttributes() {
|
||||
void propertiesWhenNotMappedAtTypeLevelShouldIgnoreAttributes() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(NotMappedAtTypeLevel.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("value");
|
||||
assertThat(source.getProperty("ignore")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenNotMappedAtAttributeLevelShouldIgnoreAttributes() {
|
||||
void propertiesWhenNotMappedAtAttributeLevelShouldIgnoreAttributes() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(NotMappedAtAttributeLevel.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("value");
|
||||
assertThat(source.getProperty("ignore")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenContainsArraysShouldExpandNames() {
|
||||
void propertiesWhenContainsArraysShouldExpandNames() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(Arrays.class);
|
||||
assertThat(source.getPropertyNames()).contains("strings[0]", "strings[1]", "classes[0]", "classes[1]",
|
||||
"ints[0]", "ints[1]", "longs[0]", "longs[1]", "floats[0]", "floats[1]", "doubles[0]", "doubles[1]",
|
||||
@@ -112,20 +112,20 @@ public class AnnotationsPropertySourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWhenHasCamelCaseShouldConvertToKebabCase() {
|
||||
void propertiesWhenHasCamelCaseShouldConvertToKebabCase() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(CamelCaseToKebabCase.class);
|
||||
assertThat(source.getPropertyNames()).contains("camel-case-to-kebab-case");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesFromMetaAnnotationsAreMapped() {
|
||||
void propertiesFromMetaAnnotationsAreMapped() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertiesFromSingleMetaAnnotation.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("value");
|
||||
assertThat(source.getProperty("value")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesFromMultipleMetaAnnotationsAreMappedUsingTheirOwnPropertyMapping() {
|
||||
void propertiesFromMultipleMetaAnnotationsAreMappedUsingTheirOwnPropertyMapping() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertiesFromMultipleMetaAnnotations.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("value", "test.value", "test.example");
|
||||
assertThat(source.getProperty("value")).isEqualTo("alpha");
|
||||
@@ -134,26 +134,26 @@ public class AnnotationsPropertySourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyMappedAttributesCanBeAliased() {
|
||||
void propertyMappedAttributesCanBeAliased() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertyMappedAttributeWithAnAlias.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("aliasing.value");
|
||||
assertThat(source.getProperty("aliasing.value")).isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selfAnnotatingAnnotationDoesNotCauseStackOverflow() {
|
||||
void selfAnnotatingAnnotationDoesNotCauseStackOverflow() {
|
||||
new AnnotationsPropertySource(PropertyMappedWithSelfAnnotatingAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typeLevelAnnotationOnSuperClass() {
|
||||
void typeLevelAnnotationOnSuperClass() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertyMappedAnnotationOnSuperClass.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("value");
|
||||
assertThat(source.getProperty("value")).isEqualTo("abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aliasedPropertyMappedAttributeOnSuperClass() {
|
||||
void aliasedPropertyMappedAttributeOnSuperClass() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(
|
||||
AliasedPropertyMappedAnnotationOnSuperClass.class);
|
||||
assertThat(source.getPropertyNames()).containsExactly("aliasing.value");
|
||||
@@ -161,13 +161,13 @@ public class AnnotationsPropertySourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumValueMapped() {
|
||||
void enumValueMapped() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(EnumValueMapped.class);
|
||||
assertThat(source.getProperty("testenum.value")).isEqualTo(EnumItem.TWO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumValueNotMapped() {
|
||||
void enumValueNotMapped() {
|
||||
AnnotationsPropertySource source = new AnnotationsPropertySource(EnumValueNotMapped.class);
|
||||
assertThat(source.containsProperty("testenum.value")).isFalse();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.boot.test.autoconfigure.properties;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
@@ -40,12 +40,12 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class PropertyMappingContextCustomizerFactoryTests {
|
||||
class PropertyMappingContextCustomizerFactoryTests {
|
||||
|
||||
private PropertyMappingContextCustomizerFactory factory = new PropertyMappingContextCustomizerFactory();
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource() {
|
||||
void getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoMapping.class, null);
|
||||
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
|
||||
ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
|
||||
@@ -57,19 +57,19 @@ public class PropertyMappingContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasTypeMappingShouldReturnCustomizer() {
|
||||
void getContextCustomizerWhenHasTypeMappingShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(TypeMapping.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasAttributeMappingShouldReturnCustomizer() {
|
||||
void getContextCustomizerWhenHasAttributeMappingShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(AttributeMapping.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeAndEqualsShouldBeBasedOnPropertyValues() {
|
||||
void hashCodeAndEqualsShouldBeBasedOnPropertyValues() {
|
||||
ContextCustomizer customizer1 = this.factory.createContextCustomizer(TypeMapping.class, null);
|
||||
ContextCustomizer customizer2 = this.factory.createContextCustomizer(AttributeMapping.class, null);
|
||||
ContextCustomizer customizer3 = this.factory.createContextCustomizer(OtherMapping.class, null);
|
||||
@@ -78,7 +78,7 @@ public class PropertyMappingContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareContextShouldAddPropertySource() {
|
||||
void prepareContextShouldAddPropertySource() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(AttributeMapping.class, null);
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
customizer.customizeContext(context, null);
|
||||
@@ -86,7 +86,7 @@ public class PropertyMappingContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyMappingShouldNotBeUsedWithComponent() {
|
||||
void propertyMappingShouldNotBeUsedWithComponent() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(AttributeMapping.class, null);
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(ConfigMapping.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -30,15 +30,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ExampleMapping(exampleProperty = "abc")
|
||||
public class PropertyMappingTests {
|
||||
class PropertyMappingTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void hasProperty() {
|
||||
void hasProperty() {
|
||||
assertThat(this.environment.getProperty("example-property")).isEqualTo("abc");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,8 @@ package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
@@ -31,7 +30,6 @@ import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
||||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
@@ -50,11 +48,10 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
* @author Andy Wilkinson
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(controllers = RestDocsTestController.class)
|
||||
@WithMockUser
|
||||
@AutoConfigureRestDocs
|
||||
public class MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests {
|
||||
class MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
@@ -64,14 +61,14 @@ public class MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTes
|
||||
|
||||
private File generatedSnippets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void deleteSnippets() {
|
||||
this.generatedSnippets = new File(new BuildOutput(getClass()).getRootLocation(), "generated-snippets");
|
||||
FileSystemUtils.deleteRecursively(this.generatedSnippets);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snippetGeneration() throws Exception {
|
||||
void snippetGeneration() throws Exception {
|
||||
this.mvc.perform(get("/")).andDo(this.documentationHandler
|
||||
.document(links(linkWithRel("self").description("Canonical location of this resource"))));
|
||||
File defaultSnippetsDir = new File(this.generatedSnippets, "snippet-generation");
|
||||
|
||||
@@ -18,14 +18,12 @@ package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
@@ -39,24 +37,23 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@AutoConfigureRestDocs(uriScheme = "https", uriHost = "api.example.com", uriPort = 443)
|
||||
public class MockMvcRestDocsAutoConfigurationIntegrationTests {
|
||||
class MockMvcRestDocsAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
private File generatedSnippets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void deleteSnippets() {
|
||||
this.generatedSnippets = new File(new BuildOutput(getClass()).getRootLocation(), "generated-snippets");
|
||||
FileSystemUtils.deleteRecursively(this.generatedSnippets);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultSnippetsAreWritten() throws Exception {
|
||||
void defaultSnippetsAreWritten() throws Exception {
|
||||
this.mvc.perform(get("/")).andDo(document("default-snippets"));
|
||||
File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets");
|
||||
assertThat(defaultSnippetsDir).exists();
|
||||
|
||||
@@ -19,9 +19,8 @@ package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
import java.io.File;
|
||||
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -33,7 +32,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
||||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
@@ -52,10 +50,9 @@ import static org.springframework.restdocs.restassured3.RestAssuredRestDocumenta
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureRestDocs
|
||||
public class RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests {
|
||||
class RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@@ -65,14 +62,14 @@ public class RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegratio
|
||||
|
||||
private File generatedSnippets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void deleteSnippets() {
|
||||
this.generatedSnippets = new File(new BuildOutput(getClass()).getRootLocation(), "generated-snippets");
|
||||
FileSystemUtils.deleteRecursively(this.generatedSnippets);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snippetGeneration() {
|
||||
void snippetGeneration() {
|
||||
given(this.documentationSpec)
|
||||
.filter(document("default-snippets",
|
||||
preprocessRequest(modifyUris().scheme("https").host("api.example.com").removePort())))
|
||||
|
||||
@@ -19,16 +19,14 @@ package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
import java.io.File;
|
||||
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
@@ -44,10 +42,9 @@ import static org.springframework.restdocs.restassured3.RestAssuredRestDocumenta
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureRestDocs
|
||||
public class RestAssuredRestDocsAutoConfigurationIntegrationTests {
|
||||
class RestAssuredRestDocsAutoConfigurationIntegrationTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@@ -57,14 +54,14 @@ public class RestAssuredRestDocsAutoConfigurationIntegrationTests {
|
||||
|
||||
private File generatedSnippets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void deleteSnippets() {
|
||||
this.generatedSnippets = new File(new BuildOutput(getClass()).getRootLocation(), "generated-snippets");
|
||||
FileSystemUtils.deleteRecursively(this.generatedSnippets);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultSnippetsAreWritten() {
|
||||
void defaultSnippetsAreWritten() {
|
||||
given(this.documentationSpec)
|
||||
.filter(document("default-snippets",
|
||||
preprocessRequest(modifyUris().scheme("https").host("api.example.com").removePort())))
|
||||
|
||||
@@ -18,9 +18,8 @@ package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
@@ -31,7 +30,6 @@ import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
||||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
@@ -46,25 +44,24 @@ import static org.springframework.restdocs.webtestclient.WebTestClientRestDocume
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebFluxTest
|
||||
@WithMockUser
|
||||
@AutoConfigureRestDocs(uriScheme = "https", uriHost = "api.example.com", uriPort = 443)
|
||||
public class WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests {
|
||||
class WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
private File generatedSnippets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void deleteSnippets() {
|
||||
this.generatedSnippets = new File(new BuildOutput(getClass()).getRootLocation(), "generated-snippets");
|
||||
FileSystemUtils.deleteRecursively(this.generatedSnippets);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultSnippetsAreWritten() throws Exception {
|
||||
void defaultSnippetsAreWritten() throws Exception {
|
||||
this.webTestClient.get().uri("/").exchange().expectStatus().is2xxSuccessful().expectBody()
|
||||
.consumeWith(document("default-snippets"));
|
||||
File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets");
|
||||
|
||||
@@ -18,15 +18,13 @@ package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
@@ -39,25 +37,24 @@ import static org.springframework.restdocs.webtestclient.WebTestClientRestDocume
|
||||
*
|
||||
* @author Roman Zaynetdinov
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebFluxTest
|
||||
@WithMockUser
|
||||
@AutoConfigureRestDocs(uriScheme = "https", uriHost = "api.example.com", uriPort = 443)
|
||||
public class WebTestClientRestDocsAutoConfigurationIntegrationTests {
|
||||
class WebTestClientRestDocsAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
private File generatedSnippets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void deleteSnippets() {
|
||||
this.generatedSnippets = new File(new BuildOutput(getClass()).getRootLocation(), "generated-snippets");
|
||||
FileSystemUtils.deleteRecursively(this.generatedSnippets);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultSnippetsAreWritten() throws Exception {
|
||||
void defaultSnippetsAreWritten() throws Exception {
|
||||
this.webTestClient.get().uri("/").exchange().expectStatus().is2xxSuccessful().expectBody()
|
||||
.consumeWith(document("default-snippets"));
|
||||
File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets");
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.security;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
@@ -25,7 +24,6 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
@@ -38,26 +36,25 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@WebMvcTest
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(properties = { "debug=true" })
|
||||
public class MockMvcSecurityIntegrationTests {
|
||||
class MockMvcSecurityIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
@WithMockUser(username = "test", password = "test", roles = "USER")
|
||||
public void okResponseWithMockUser() throws Exception {
|
||||
void okResponseWithMockUser() throws Exception {
|
||||
this.mockMvc.perform(get("/")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unauthorizedResponseWithNoUser() throws Exception {
|
||||
void unauthorizedResponseWithNoUser() throws Exception {
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void okResponseWithBasicAuthCredentialsForKnownUser() throws Exception {
|
||||
void okResponseWithBasicAuthCredentialsForKnownUser() throws Exception {
|
||||
this.mockMvc.perform(get("/").header(HttpHeaders.AUTHORIZATION,
|
||||
"Basic " + Base64Utils.encodeToString("user:secret".getBytes()))).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@@ -34,16 +32,15 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@RestClientTest
|
||||
@AutoConfigureMockRestServiceServer(enabled = false)
|
||||
public class AutoConfigureMockRestServiceServerEnabledFalseIntegrationTests {
|
||||
class AutoConfigureMockRestServiceServerEnabledFalseIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void mockServerRestTemplateCustomizerShouldNotBeRegistered() {
|
||||
void mockServerRestTemplateCustomizerShouldNotBeRegistered() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(MockServerRestTemplateCustomizer.class));
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -26,7 +25,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -40,11 +38,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureWebClient(registerRestTemplate = true)
|
||||
@AutoConfigureMockRestServiceServer
|
||||
public class AutoConfigureWebClientWithRestTemplateIntegrationTests {
|
||||
class AutoConfigureWebClientWithRestTemplateIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@@ -53,7 +50,7 @@ public class AutoConfigureWebClientWithRestTemplateIntegrationTests {
|
||||
private MockRestServiceServer server;
|
||||
|
||||
@Test
|
||||
public void restTemplateTest() {
|
||||
void restTemplateTest() {
|
||||
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/test", String.class);
|
||||
assertThat(entity.getBody()).isEqualTo("hello");
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -34,9 +32,8 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@RestClientTest(ExampleRestClient.class)
|
||||
public class RestClientRestIntegrationTests {
|
||||
class RestClientRestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockRestServiceServer server;
|
||||
@@ -45,19 +42,19 @@ public class RestClientRestIntegrationTests {
|
||||
private ExampleRestClient client;
|
||||
|
||||
@Test
|
||||
public void mockServerCall1() {
|
||||
void mockServerCall1() {
|
||||
this.server.expect(requestTo("/test")).andRespond(withSuccess("1", MediaType.TEXT_HTML));
|
||||
assertThat(this.client.test()).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockServerCall2() {
|
||||
void mockServerCall2() {
|
||||
this.server.expect(requestTo("/test")).andRespond(withSuccess("2", MediaType.TEXT_HTML));
|
||||
assertThat(this.client.test()).isEqualTo("2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockServerCallWithContent() {
|
||||
void mockServerCallWithContent() {
|
||||
this.server.expect(requestTo("/test")).andExpect(content().string("test"))
|
||||
.andRespond(withSuccess("1", MediaType.TEXT_HTML));
|
||||
this.client.testPostWithBody("test");
|
||||
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -37,9 +35,8 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@RestClientTest
|
||||
public class RestClientTestNoComponentIntegrationTests {
|
||||
class RestClientTestNoComponentIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
@@ -51,13 +48,13 @@ public class RestClientTestNoComponentIntegrationTests {
|
||||
private MockRestServiceServer server;
|
||||
|
||||
@Test
|
||||
public void exampleRestClientIsNotInjected() {
|
||||
void exampleRestClientIsNotInjected() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleRestClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manuallyCreateBean() {
|
||||
void manuallyCreateBean() {
|
||||
ExampleRestClient client = new ExampleRestClient(this.restTemplateBuilder);
|
||||
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
|
||||
assertThat(client.test()).isEqualTo("hello");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@RestClientTest(properties = "spring.profiles.active=test")
|
||||
public class RestClientTestPropertiesIntegrationTests {
|
||||
class RestClientTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -35,9 +33,8 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@RestClientTest({ ExampleRestClient.class, AnotherExampleRestClient.class })
|
||||
public class RestClientTestTwoComponentsIntegrationTests {
|
||||
class RestClientTestTwoComponentsIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleRestClient client1;
|
||||
@@ -52,21 +49,21 @@ public class RestClientTestTwoComponentsIntegrationTests {
|
||||
private MockRestServiceServer server;
|
||||
|
||||
@Test
|
||||
public void serverShouldNotWork() {
|
||||
void serverShouldNotWork() {
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
() -> this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML)))
|
||||
.withMessageContaining("Unable to use auto-configured");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void client1RestCallViaCustomizer() {
|
||||
void client1RestCallViaCustomizer() {
|
||||
this.customizer.getServer(this.client1.getRestTemplate()).expect(requestTo("/test"))
|
||||
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
|
||||
assertThat(this.client1.test()).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void client2RestCallViaCustomizer() {
|
||||
void client2RestCallViaCustomizer() {
|
||||
this.customizer.getServer(this.client2.getRestTemplate()).expect(requestTo("/test"))
|
||||
.andRespond(withSuccess("there", MediaType.TEXT_HTML));
|
||||
assertThat(this.client2.test()).isEqualTo("there");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebFluxTest(properties = "spring.profiles.active=test")
|
||||
public class WebFluxTestPropertiesIntegrationTests {
|
||||
class WebFluxTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.test.autoconfigure.web.reactive;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
@@ -39,12 +39,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class WebFluxTypeExcludeFilterTests {
|
||||
class WebFluxTypeExcludeFilterTests {
|
||||
|
||||
private MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
|
||||
@Test
|
||||
public void matchWhenHasNoControllers() throws Exception {
|
||||
void matchWhenHasNoControllers() throws Exception {
|
||||
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithNoControllers.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isFalse();
|
||||
assertThat(excludes(filter, Controller2.class)).isFalse();
|
||||
@@ -55,7 +55,7 @@ public class WebFluxTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenHasController() throws Exception {
|
||||
void matchWhenHasController() throws Exception {
|
||||
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithController.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isFalse();
|
||||
assertThat(excludes(filter, Controller2.class)).isTrue();
|
||||
@@ -66,7 +66,7 @@ public class WebFluxTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchNotUsingDefaultFilters() throws Exception {
|
||||
void matchNotUsingDefaultFilters() throws Exception {
|
||||
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(NotUsingDefaultFilters.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isTrue();
|
||||
assertThat(excludes(filter, Controller2.class)).isTrue();
|
||||
@@ -77,7 +77,7 @@ public class WebFluxTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithIncludeFilter() throws Exception {
|
||||
void matchWithIncludeFilter() throws Exception {
|
||||
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithIncludeFilter.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isFalse();
|
||||
assertThat(excludes(filter, Controller2.class)).isFalse();
|
||||
@@ -88,7 +88,7 @@ public class WebFluxTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithExcludeFilter() throws Exception {
|
||||
void matchWithExcludeFilter() throws Exception {
|
||||
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithExcludeFilter.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isTrue();
|
||||
assertThat(excludes(filter, Controller2.class)).isFalse();
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
@@ -48,13 +48,13 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Brian Clozel
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class WebTestClientAutoConfigurationTests {
|
||||
class WebTestClientAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(WebTestClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void shouldNotBeConfiguredWithoutWebHandler() {
|
||||
void shouldNotBeConfiguredWithoutWebHandler() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context).doesNotHaveBean(WebTestClient.class);
|
||||
@@ -62,7 +62,7 @@ public class WebTestClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCustomizeClientCodecs() {
|
||||
void shouldCustomizeClientCodecs() {
|
||||
this.contextRunner.withUserConfiguration(CodecConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(WebTestClient.class);
|
||||
assertThat(context).hasSingleBean(CodecCustomizer.class);
|
||||
@@ -71,7 +71,7 @@ public class WebTestClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCustomizeTimeout() {
|
||||
void shouldCustomizeTimeout() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("spring.test.webtestclient.timeout=15m").run((context) -> {
|
||||
WebTestClient webTestClient = context.getBean(WebTestClient.class);
|
||||
@@ -82,7 +82,7 @@ public class WebTestClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldApplySpringSecurityConfigurer() {
|
||||
void shouldApplySpringSecurityConfigurer() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class).run((context) -> {
|
||||
WebTestClient webTestClient = context.getBean(WebTestClient.class);
|
||||
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient,
|
||||
@@ -97,7 +97,7 @@ public class WebTestClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath() {
|
||||
void shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath() {
|
||||
FilteredClassLoader classLoader = new FilteredClassLoader(SecurityMockServerConfigurers.class);
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class).withClassLoader(classLoader)
|
||||
.run((context) -> {
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
@@ -30,31 +28,30 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WithMockUser
|
||||
@WebFluxTest
|
||||
public class WebFluxTestAllControllersIntegrationTests {
|
||||
class WebFluxTestAllControllersIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void shouldFindController1() {
|
||||
void shouldFindController1() {
|
||||
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindController2() {
|
||||
void shouldFindController2() {
|
||||
this.webClient.get().uri("/two").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("two");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webExceptionHandling() {
|
||||
void webExceptionHandling() {
|
||||
this.webClient.get().uri("/one/error").exchange().expectStatus().isBadRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindJsonController() {
|
||||
void shouldFindJsonController() {
|
||||
this.webClient.get().uri("/json").exchange().expectStatus().isOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.boot.autoconfigure.validation.ValidationAutoConfigura
|
||||
import org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration;
|
||||
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.assertThat;
|
||||
import static org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.importedAutoConfiguration;
|
||||
@@ -40,40 +38,39 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
||||
* @author Artsiom Yudovin
|
||||
* @author Ali Dehghani
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebFluxTest
|
||||
public class WebFluxTestAutoConfigurationIntegrationTests {
|
||||
class WebFluxTestAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void messageSourceAutoConfigurationIsImported() {
|
||||
void messageSourceAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(MessageSourceAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validationAutoConfigurationIsImported() {
|
||||
void validationAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(ValidationAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustacheAutoConfigurationIsImported() {
|
||||
void mustacheAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(MustacheAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeMarkerAutoConfigurationIsImported() {
|
||||
void freeMarkerAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(FreeMarkerAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thymeleafAutoConfigurationIsImported() {
|
||||
void thymeleafAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorWebFluxAutoConfigurationIsImported() {
|
||||
void errorWebFluxAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(ErrorWebFluxAutoConfiguration.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,11 @@ package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
@@ -32,16 +30,15 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WithMockUser
|
||||
@WebFluxTest(controllers = ExampleController2.class)
|
||||
public class WebFluxTestConverterIntegrationTests {
|
||||
class WebFluxTestConverterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void shouldFindConverter() {
|
||||
void shouldFindConverter() {
|
||||
UUID id = UUID.randomUUID();
|
||||
this.webClient.get().uri("/two/" + id).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.isEqualTo(id + "two");
|
||||
|
||||
@@ -18,15 +18,13 @@ package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -36,16 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebFluxTest
|
||||
@TestPropertySource(properties = "spring.messages.basename=web-test-messages")
|
||||
public class WebFluxTestMessageSourceIntegrationTests {
|
||||
class WebFluxTestMessageSourceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void messageSourceHasBeenAutoConfigured() {
|
||||
void messageSourceHasBeenAutoConfigured() {
|
||||
assertThat(this.context.getMessage("a", null, Locale.ENGLISH)).isEqualTo("alpha");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
@@ -30,21 +28,20 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WithMockUser
|
||||
@WebFluxTest(controllers = ExampleController1.class)
|
||||
public class WebFluxTestOneControllerIntegrationTests {
|
||||
class WebFluxTestOneControllerIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void shouldFindController() {
|
||||
void shouldFindController() {
|
||||
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotScanOtherController() {
|
||||
void shouldNotScanOtherController() {
|
||||
this.webClient.get().uri("/two").exchange().expectStatus().isNotFound();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
@@ -31,16 +29,15 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WithMockUser
|
||||
@WebFluxTest(controllers = JsonController.class)
|
||||
public class WebFluxTestWebTestClientCodecCustomizationIntegrationTests {
|
||||
class WebFluxTestWebTestClientCodecCustomizationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void shouldBeAbleToCreatePojoViaParametersModule() {
|
||||
void shouldBeAbleToCreatePojoViaParametersModule() {
|
||||
this.webClient.get().uri("/json").exchange().expectStatus().isOk().expectBody(ExamplePojo.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
||||
@@ -27,7 +26,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -39,11 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = "spring.main.web-application-type=reactive", classes = {
|
||||
WebTestClientSpringBootTestIntegrationTests.TestConfiguration.class, ExampleWebFluxApplication.class })
|
||||
@AutoConfigureWebTestClient
|
||||
public class WebTestClientSpringBootTestIntegrationTests {
|
||||
class WebTestClientSpringBootTestIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
@@ -52,17 +49,17 @@ public class WebTestClientSpringBootTestIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void shouldFindController1() {
|
||||
void shouldFindController1() {
|
||||
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindController2() {
|
||||
void shouldFindController2() {
|
||||
this.webClient.get().uri("/two").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("two");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveRealService() {
|
||||
void shouldHaveRealService() {
|
||||
assertThat(this.applicationContext.getBeansOfType(ExampleRealService.class)).hasSize(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
@@ -29,13 +29,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
public class MockMvcAutoConfigurationTests {
|
||||
class MockMvcAutoConfigurationTests {
|
||||
|
||||
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(MockMvcAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void registersDispatcherServletFromMockMvc() {
|
||||
void registersDispatcherServletFromMockMvc() {
|
||||
this.contextRunner.run((context) -> {
|
||||
MockMvc mockMvc = context.getBean(MockMvc.class);
|
||||
assertThat(context).hasSingleBean(DispatcherServlet.class);
|
||||
|
||||
@@ -24,7 +24,7 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||
@@ -42,13 +42,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
public class SpringBootMockMvcBuilderCustomizerTests {
|
||||
class SpringBootMockMvcBuilderCustomizerTests {
|
||||
|
||||
private SpringBootMockMvcBuilderCustomizer customizer;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void customizeShouldAddFilters() {
|
||||
void customizeShouldAddFilters() {
|
||||
AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
context.setServletContext(servletContext);
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
|
||||
@@ -27,7 +26,6 @@ import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguratio
|
||||
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
@@ -40,40 +38,39 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
||||
* @author Andy Wilkinson
|
||||
* @author Levi Puot Paul
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
public class WebMvcTestAutoConfigurationIntegrationTests {
|
||||
class WebMvcTestAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void freemarkerAutoConfigurationWasImported() {
|
||||
void freemarkerAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(FreeMarkerAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groovyTemplatesAutoConfigurationWasImported() {
|
||||
void groovyTemplatesAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(GroovyTemplateAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustacheAutoConfigurationWasImported() {
|
||||
void mustacheAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(MustacheAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thymeleafAutoConfigurationWasImported() {
|
||||
void thymeleafAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExecutionAutoConfigurationWasImported() {
|
||||
void taskExecutionAutoConfigurationWasImported() {
|
||||
assertThat(this.applicationContext).has(importedAutoConfiguration(TaskExecutionAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncTaskExecutorWithApplicationTaskExecutor() {
|
||||
void asyncTaskExecutorWithApplicationTaskExecutor() {
|
||||
assertThat(this.applicationContext.getBeansOfType(AsyncTaskExecutor.class)).hasSize(1);
|
||||
assertThat(ReflectionTestUtils.getField(this.applicationContext.getBean(RequestMappingHandlerAdapter.class),
|
||||
"taskExecutor")).isSameAs(this.applicationContext.getBean("applicationTaskExecutor"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(properties = "spring.profiles.active=test")
|
||||
public class WebMvcTestPropertiesIntegrationTests {
|
||||
class WebMvcTestPropertiesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void environmentWithNewProfile() {
|
||||
void environmentWithNewProfile() {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.test.autoconfigure.web.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
@@ -40,12 +40,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebMvcTypeExcludeFilterTests {
|
||||
class WebMvcTypeExcludeFilterTests {
|
||||
|
||||
private MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
|
||||
@Test
|
||||
public void matchWhenHasNoControllers() throws Exception {
|
||||
void matchWhenHasNoControllers() throws Exception {
|
||||
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithNoControllers.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isFalse();
|
||||
assertThat(excludes(filter, Controller2.class)).isFalse();
|
||||
@@ -58,7 +58,7 @@ public class WebMvcTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenHasController() throws Exception {
|
||||
void matchWhenHasController() throws Exception {
|
||||
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithController.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isFalse();
|
||||
assertThat(excludes(filter, Controller2.class)).isTrue();
|
||||
@@ -71,7 +71,7 @@ public class WebMvcTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchNotUsingDefaultFilters() throws Exception {
|
||||
void matchNotUsingDefaultFilters() throws Exception {
|
||||
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(NotUsingDefaultFilters.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isTrue();
|
||||
assertThat(excludes(filter, Controller2.class)).isTrue();
|
||||
@@ -84,7 +84,7 @@ public class WebMvcTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithIncludeFilter() throws Exception {
|
||||
void matchWithIncludeFilter() throws Exception {
|
||||
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithIncludeFilter.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isFalse();
|
||||
assertThat(excludes(filter, Controller2.class)).isFalse();
|
||||
@@ -96,7 +96,7 @@ public class WebMvcTypeExcludeFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithExcludeFilter() throws Exception {
|
||||
void matchWithExcludeFilter() throws Exception {
|
||||
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithExcludeFilter.class);
|
||||
assertThat(excludes(filter, Controller1.class)).isTrue();
|
||||
assertThat(excludes(filter, Controller2.class)).isFalse();
|
||||
|
||||
@@ -16,19 +16,18 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrint;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -42,14 +41,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc(print = MockMvcPrint.SYSTEM_ERR, printOnlyOnFailure = false)
|
||||
@WithMockUser(username = "user", password = "secret")
|
||||
public class MockMvcSpringBootTestIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule output = new OutputCaptureRule();
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class MockMvcSpringBootTestIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleMockableService service;
|
||||
@@ -61,23 +57,23 @@ public class MockMvcSpringBootTestIntegrationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldFindController1() throws Exception {
|
||||
void shouldFindController1(CapturedOutput capturedOutput) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(this.output.toString()).contains("Request URI = /one");
|
||||
assertThat(capturedOutput).contains("Request URI = /one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindController2() throws Exception {
|
||||
void shouldFindController2() throws Exception {
|
||||
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindControllerAdvice() throws Exception {
|
||||
void shouldFindControllerAdvice() throws Exception {
|
||||
this.mvc.perform(get("/error")).andExpect(content().string("recovered")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveRealService() {
|
||||
void shouldHaveRealService() {
|
||||
assertThat(this.applicationContext.getBean(ExampleRealService.class)).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,12 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.util.NestedServletException;
|
||||
|
||||
@@ -41,10 +39,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
public class WebMvcTestAllControllersIntegrationTests {
|
||||
class WebMvcTestAllControllersIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
@@ -53,34 +50,34 @@ public class WebMvcTestAllControllersIntegrationTests {
|
||||
private ErrorAttributes errorAttributes;
|
||||
|
||||
@Test
|
||||
public void shouldFindController1() throws Exception {
|
||||
void shouldFindController1() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindController2() throws Exception {
|
||||
void shouldFindController2() throws Exception {
|
||||
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindControllerAdvice() throws Exception {
|
||||
void shouldFindControllerAdvice() throws Exception {
|
||||
this.mvc.perform(get("/error")).andExpect(content().string("recovered")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRunValidationSuccess() throws Exception {
|
||||
void shouldRunValidationSuccess() throws Exception {
|
||||
this.mvc.perform(get("/three/OK")).andExpect(status().isOk()).andExpect(content().string("Hello OK"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRunValidationFailure() throws Exception {
|
||||
void shouldRunValidationFailure() throws Exception {
|
||||
assertThatExceptionOfType(NestedServletException.class)
|
||||
.isThrownBy(() -> this.mvc.perform(get("/three/invalid")))
|
||||
.withCauseInstanceOf(ConstraintViolationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFilterErrorAttributes() {
|
||||
void shouldNotFilterErrorAttributes() {
|
||||
assertThat(this.errorAttributes).isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,11 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -36,16 +34,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(controllers = ExampleController2.class)
|
||||
@WithMockUser
|
||||
public class WebMvcTestConverterIntegrationTests {
|
||||
class WebMvcTestConverterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldFindConverter() throws Exception {
|
||||
void shouldFindConverter() throws Exception {
|
||||
String id = UUID.randomUUID().toString();
|
||||
this.mvc.perform(get("/two/" + id)).andExpect(content().string(id + "two")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
@@ -36,18 +34,17 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@TestPropertySource(properties = { "spring.mvc.throw-exception-if-no-handler-found=true",
|
||||
"spring.mvc.static-path-pattern=/static/**" })
|
||||
public class WebMvcTestCustomDispatcherServletIntegrationTests {
|
||||
class WebMvcTestCustomDispatcherServletIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void dispatcherServletIsCustomized() throws Exception {
|
||||
void dispatcherServletIsCustomized() throws Exception {
|
||||
this.mvc.perform(get("/does-not-exist")).andExpect(status().isBadRequest())
|
||||
.andExpect(content().string("Invalid request: /does-not-exist"));
|
||||
}
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -34,22 +32,21 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
public class WebMvcTestHateoasIntegrationTests {
|
||||
class WebMvcTestHateoasIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
public void plainResponse() throws Exception {
|
||||
void plainResponse() throws Exception {
|
||||
this.mockMvc.perform(get("/hateoas/plain"))
|
||||
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, "application/json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hateoasResponse() throws Exception {
|
||||
void hateoasResponse() throws Exception {
|
||||
this.mockMvc.perform(get("/hateoas/resource"))
|
||||
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, "application/hal+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
@@ -27,7 +26,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,17 +35,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@TestPropertySource(properties = "spring.messages.basename=web-test-messages")
|
||||
public class WebMvcTestMessageSourceIntegrationTests {
|
||||
class WebMvcTestMessageSourceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void messageSourceHasBeenAutoConfigured() {
|
||||
void messageSourceHasBeenAutoConfigured() {
|
||||
assertThat(this.context.getMessage("a", null, Locale.ENGLISH)).isEqualTo("alpha");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -34,21 +32,20 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(controllers = ExampleController2.class)
|
||||
@WithMockUser
|
||||
public class WebMvcTestOneControllerIntegrationTests {
|
||||
class WebMvcTestOneControllerIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldNotFindController1() throws Exception {
|
||||
void shouldNotFindController1() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindController2() throws Exception {
|
||||
void shouldFindController2() throws Exception {
|
||||
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -34,16 +32,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
public class WebMvcTestPageableIntegrationTests {
|
||||
class WebMvcTestPageableIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldSupportPageable() throws Exception {
|
||||
void shouldSupportPageable() throws Exception {
|
||||
this.mvc.perform(get("/paged").param("page", "2").param("size", "42")).andExpect(status().isOk())
|
||||
.andExpect(content().string("2:42"));
|
||||
}
|
||||
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -38,22 +37,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@AutoConfigureMockMvc(printOnlyOnFailure = false)
|
||||
public class WebMvcTestPrintAlwaysIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule output = new OutputCaptureRule();
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class WebMvcTestPrintAlwaysIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldPrint() throws Exception {
|
||||
void shouldPrint(CapturedOutput capturedOutput) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(this.output.toString()).contains("Request URI = /one");
|
||||
assertThat(capturedOutput).contains("Request URI = /one");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.launcher.Launcher;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
import org.junit.platform.launcher.core.LauncherFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -33,24 +41,58 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
* Tests for {@link WebMvcTest @WebMvcTest} default print output.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(WebMvcTestPrintDefaultRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@AutoConfigureMockMvc
|
||||
public class WebMvcTestPrintDefaultIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class WebMvcTestPrintDefaultIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void shouldNotPrint() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
void shouldNotPrint(CapturedOutput capturedOutput) {
|
||||
executeTests(ShouldNotPrint.class);
|
||||
assertThat(capturedOutput).doesNotContain("HTTP Method");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPrint() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("none")).andExpect(status().isOk());
|
||||
void shouldPrint(CapturedOutput capturedOutput) {
|
||||
executeTests(ShouldPrint.class);
|
||||
assertThat(capturedOutput).contains("HTTP Method");
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) {
|
||||
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
|
||||
.selectors(DiscoverySelectors.selectClass(testClass)).build();
|
||||
Launcher launcher = LauncherFactory.create();
|
||||
launcher.execute(request);
|
||||
}
|
||||
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@AutoConfigureMockMvc
|
||||
static class ShouldNotPrint {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void test() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@AutoConfigureMockMvc
|
||||
static class ShouldPrint {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void test() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("none")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -38,22 +37,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@TestPropertySource(properties = "spring.test.mockmvc.print=NONE")
|
||||
public class WebMvcTestPrintDefaultOverrideIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule output = new OutputCaptureRule();
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class WebMvcTestPrintDefaultOverrideIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldFindController1() throws Exception {
|
||||
void shouldFindController1(CapturedOutput capturedOutput) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(this.output.toString()).doesNotContain("Request URI = /one");
|
||||
assertThat(capturedOutput).doesNotContain("Request URI = /one");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* 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.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* Test runner used for {@link WebMvcTestPrintDefaultIntegrationTests}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebMvcTestPrintDefaultRunner extends SpringJUnit4ClassRunner {
|
||||
|
||||
public WebMvcTestPrintDefaultRunner(Class<?> clazz) throws InitializationError {
|
||||
super(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
|
||||
Statement statement = super.methodBlock(frameworkMethod);
|
||||
statement = new AlwaysPassStatement(statement);
|
||||
OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
if (frameworkMethod.getName().equals("shouldPrint")) {
|
||||
outputCapture.expect(containsString("HTTP Method"));
|
||||
}
|
||||
else if (frameworkMethod.getName().equals("shouldNotPrint")) {
|
||||
outputCapture.expect(not(containsString("HTTP Method")));
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unexpected test method");
|
||||
}
|
||||
System.err.println(frameworkMethod.getName());
|
||||
return outputCapture.apply(statement, null);
|
||||
}
|
||||
|
||||
private static class AlwaysPassStatement extends Statement {
|
||||
|
||||
private final Statement delegate;
|
||||
|
||||
AlwaysPassStatement(Statement delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
try {
|
||||
this.delegate.evaluate();
|
||||
}
|
||||
catch (AssertionError ex) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,17 +16,16 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrint;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -39,22 +38,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@AutoConfigureMockMvc(print = MockMvcPrint.NONE)
|
||||
public class WebMvcTestPrintOverrideIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture output = new OutputCapture();
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class WebMvcTestPrintOverrideIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldNotPrint() throws Exception {
|
||||
void shouldNotPrint(CapturedOutput capturedOutput) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(this.output.toString()).doesNotContain("Request URI = /one");
|
||||
assertThat(capturedOutput).doesNotContain("Request URI = /one");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -32,15 +30,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
public class WebMvcTestServletFilterIntegrationTests {
|
||||
class WebMvcTestServletFilterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldApplyFilter() throws Exception {
|
||||
void shouldApplyFilter() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(header().string("x-test", "abc"));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -35,15 +33,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
public class WebMvcTestServletFilterRegistrationDisabledIntegrationTests {
|
||||
class WebMvcTestServletFilterRegistrationDisabledIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldNotApplyFilter() throws Exception {
|
||||
void shouldNotApplyFilter() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(header().string("x-test", (String) null));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,11 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -33,16 +31,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
public class WebMvcTestWebClientIntegrationTests {
|
||||
class WebMvcTestWebClientIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private WebClient webClient;
|
||||
|
||||
@Test
|
||||
public void shouldAutoConfigureWebClient() throws Exception {
|
||||
void shouldAutoConfigureWebClient() throws Exception {
|
||||
HtmlPage page = this.webClient.getPage("/html");
|
||||
assertThat(page.getBody().getTextContent()).isEqualTo("Hello");
|
||||
}
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||
|
||||
@@ -29,7 +28,6 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
|
||||
|
||||
@@ -40,10 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class WebMvcTestWebDriverCustomScopeIntegrationTests {
|
||||
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
|
||||
class WebMvcTestWebDriverCustomScopeIntegrationTests {
|
||||
|
||||
// gh-7454
|
||||
|
||||
@@ -53,12 +50,12 @@ public class WebMvcTestWebDriverCustomScopeIntegrationTests {
|
||||
private WebDriver webDriver;
|
||||
|
||||
@Test
|
||||
public void shouldAutoConfigureWebClient() {
|
||||
void shouldAutoConfigureWebClient() {
|
||||
WebMvcTestWebDriverCustomScopeIntegrationTests.previousWebDriver = this.webDriver;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeTheSameWebClient() {
|
||||
void shouldBeTheSameWebClient() {
|
||||
assertThat(previousWebDriver).isNotNull().isSameAs(this.webDriver);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.NoSuchWindowException;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
@@ -28,7 +27,6 @@ import org.openqa.selenium.WebElement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -38,11 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@WithMockUser
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class WebMvcTestWebDriverIntegrationTests {
|
||||
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
|
||||
class WebMvcTestWebDriverIntegrationTests {
|
||||
|
||||
private static WebDriver previousWebDriver;
|
||||
|
||||
@@ -50,7 +47,7 @@ public class WebMvcTestWebDriverIntegrationTests {
|
||||
private WebDriver webDriver;
|
||||
|
||||
@Test
|
||||
public void shouldAutoConfigureWebClient() {
|
||||
void shouldAutoConfigureWebClient() {
|
||||
this.webDriver.get("/html");
|
||||
WebElement element = this.webDriver.findElement(By.tagName("body"));
|
||||
assertThat(element.getText()).isEqualTo("Hello");
|
||||
@@ -58,7 +55,7 @@ public class WebMvcTestWebDriverIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeADifferentWebClient() {
|
||||
void shouldBeADifferentWebClient() {
|
||||
this.webDriver.get("/html");
|
||||
WebElement element = this.webDriver.findElement(By.tagName("body"));
|
||||
assertThat(element.getText()).isEqualTo("Hello");
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
@@ -26,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -40,10 +38,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest
|
||||
@AutoConfigureMockMvc(addFilters = false, webClientEnabled = false, webDriverEnabled = false)
|
||||
public class WebMvcTestWithAutoConfigureMockMvcIntegrationTests {
|
||||
class WebMvcTestWithAutoConfigureMockMvcIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@@ -52,18 +49,18 @@ public class WebMvcTestWithAutoConfigureMockMvcIntegrationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void shouldNotAddFilters() throws Exception {
|
||||
void shouldNotAddFilters() throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(header().doesNotExist("x-test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveWebDriver() {
|
||||
void shouldNotHaveWebDriver() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(WebDriver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveWebClient() {
|
||||
void shouldNotHaveWebClient() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(WebClient.class));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user