Java Code Examples for org.springframework.boot.test.context.runner.WebApplicationContextRunner

The following examples show how to use org.springframework.boot.test.context.runner.WebApplicationContextRunner. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
@SuppressWarnings("deprecation")
public void springVaultClientConfigurationIsAProxy() {
	new WebApplicationContextRunner()
			.withPropertyValues("spring.profiles.active=vault")
			.withConfiguration(UserConfigurations.of(ConfigServerConfiguration.class))
			.withConfiguration(
					AutoConfigurations.of(ConfigServerAutoConfiguration.class))
			.run(context -> {
				assertThat(context).getBean(SpringVaultClientConfiguration.class)
						.isNotNull()
						.matches(svcc -> ClassUtils
								.isCglibProxyClassName(svcc.getClass().getName()),
								"is a proxy");
			});
}
 
Example 2
Source Project: spring-cloud-config   Source File: CompositUtilsTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void getCompositeTypeListWorks() {
	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.config.name:compositeconfigserver",
					"spring.jmx.enabled=false",
					"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[0].type:git",
					"spring.cloud.config.server.composite[1].uri:file:///./target/repos/svn-config-repo",
					"spring.cloud.config.server.composite[1].type:svn")
			.run(context -> {
				List<String> types = CompositeUtils
						.getCompositeTypeList(context.getEnvironment());
				assertThat(types).containsExactly("git", "svn");
			});
}
 
Example 3
Source Project: spring-cloud-config   Source File: CompositUtilsTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void getCompositeTypeListFails() {
	this.thrown.expect(IllegalStateException.class);

	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.config.name:compositeconfigserver",
					"spring.jmx.enabled=false",
					"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[0].type:git",
					"spring.cloud.config.server.composite[2].uri:file:///./target/repos/svn-config-repo",
					"spring.cloud.config.server.composite[2].type:svn")
			.run(context -> {
				CompositeUtils.getCompositeTypeList(context.getEnvironment());
			});
}
 
Example 4
private void testAutoRegistrationDisabled(String testName, String disableProperty) {
	new WebApplicationContextRunner().withUserConfiguration(TestConfig.class)
			.withPropertyValues("spring.application.name=" + testName,
					disableProperty + "=false", "server.port=0")
			.run(context -> {

				assertThat(context)
						.doesNotHaveBean(ConsulAutoServiceRegistration.class);
				assertThat(context)
						.doesNotHaveBean(ConsulAutoServiceRegistrationListener.class);
				assertThat(context).doesNotHaveBean(ConsulAutoRegistration.class);
				assertThat(context)
						.doesNotHaveBean(ConsulRegistrationCustomizer.class);

				ConsulClient consul = context.getBean(ConsulClient.class);

				Response<Map<String, Service>> response = consul.getAgentServices();
				Map<String, Service> services = response.getValue();
				Service service = services.get(testName);
				assertThat(service).as("service was registered").isNull();

			});
}
 
Example 5
private void testAutoRegistrationDisabled(String testName, String disableProperty) {
	new WebApplicationContextRunner().withUserConfiguration(TestConfig.class)
			.withPropertyValues("spring.application.name=" + testName,
					disableProperty + "=false", "server.port=0")
			.run(context -> {
				assertThat(context).doesNotHaveBean(ConsulServiceRegistry.class);
				assertThat(context).doesNotHaveBean(HeartbeatProperties.class);

				ConsulClient consul = context.getBean(ConsulClient.class);

				Response<Map<String, Service>> response = consul.getAgentServices();
				Map<String, Service> services = response.getValue();
				Service service = services.get(testName);
				assertThat(service).as("service was registered").isNull();
			});
}
 
Example 6
@Before
public void setUp() {
	contextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class,
					HttpMessageConvertersAutoConfiguration.class,
					HypermediaAutoConfiguration.class,
					RepositoryRestMvcAutoConfiguration.class,
					FeignHalAutoConfiguration.class))
			.withPropertyValues("debug=true");
}
 
Example 7
@Before
public void setup() {
	contextRunner = new WebApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(XsuaaResourceServerJwkAutoConfiguration.class,
							XsuaaAutoConfiguration.class));
}
 
Example 8
@Test
public void oauth2ContextConfiguredWithWebApp() {
	new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(this.configurations))
			.withPropertyValues(this.oAuth2ClientProperties).run((context) -> {
				assertServletOAuth2ContextConfigured(context);
				assertReactiveOAuth2ContextConfigured(context);
			});
}
 
Example 9
@Before
public void setUp() {
	contextRunner = new WebApplicationContextRunner()
			.withPropertyValues("eureka.client.serviceUrl.defaultZone=" + ZONE_URI,
					"vcap.application.uris[0]=" + HOSTNAME, "vcap.application.instance_id=" + INSTANCE_ID,
					"vcap.application.application_id=" + INSTANCE_GUID, "cf.instance.index=" + INSTANCE_INDEX,
					"cf.instance.internal.ip=" + IP, "port=" + PORT)
			.withConfiguration(AutoConfigurations.of(EurekaInstanceAutoConfiguration.class));
}
 
Example 10
@Test
public void contextLoadsWithRestTemplate() {
	new WebApplicationContextRunner()
			.withUserConfiguration(EurekaSampleApplication.class)
			.withPropertyValues("eureka.client.webclient.enabled=false")
			.run(context -> {
				assertThat(context)
						.hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
				assertThat(context)
						.doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class);
			});
}
 
Example 11
@Test
public void contextLoadsWithWebClient() {
	new WebApplicationContextRunner()
			.withUserConfiguration(EurekaSampleApplication.class)
			.withPropertyValues("eureka.client.webclient.enabled=true")
			.run(context -> {
				assertThat(context).doesNotHaveBean(
						RestTemplateDiscoveryClientOptionalArgs.class);
				assertThat(context)
						.hasSingleBean(WebClientDiscoveryClientOptionalArgs.class);
			});
}
 
Example 12
@Test
public void contextLoadsWithRestTemplateAsDefault() {
	new WebApplicationContextRunner()
			.withUserConfiguration(EurekaSampleApplication.class).run(context -> {
				assertThat(context)
						.hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
				assertThat(context)
						.doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class);
			});
}
 
Example 13
@Test
public void contextLoads() {
	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.jmx.enabled=false",
					"spring.config.name:compositeconfigserver",
					"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[0].type:git",
					"spring.cloud.config.server.composite[1].uri:file:///./target/repos/svn-config-repo",
					"spring.cloud.config.server.composite[1].type:svn")
			.run(context -> {
				CompositeUtils.getCompositeTypeList(context.getEnvironment());
			});
}
 
Example 14
@Test
public void contextLoads() {
	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.jmx.enabled=false",
					"spring.config.name:compositeconfigserver",
					"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[0].type:git",
					"spring.cloud.config.server.composite[1].uri:file:///./target/repos/svn-config-repo",
					"spring.cloud.config.server.composite[1].type:svn")
			.run(context -> {
				CompositeUtils.getCompositeTypeList(context.getEnvironment());
			});
}
 
Example 15
@Test
public void contextLoads() {
	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.jmx.enabled=false",
					"spring.config.name:compositeconfigserver",
					"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[0].type:git",
					"spring.cloud.config.server.composite[1].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[1].type:native")
			.run(context -> {
				CompositeUtils.getCompositeTypeList(context.getEnvironment());
			});
}
 
Example 16
@Test
public void contextLoads() {
	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.jmx.enabled=false",
					"spring.config.name:compositeconfigserver",
					"spring.cloud.config.server.composite[0].uri:file:///./target/repos/svn-config-repo",
					"spring.cloud.config.server.composite[0].type:svn",
					"spring.cloud.config.server.composite[1].uri:file:./target/repos/config-repo",
					"spring.cloud.config.server.composite[1].type:native")
			.run(context -> {
				CompositeUtils.getCompositeTypeList(context.getEnvironment());
			});
}
 
Example 17
@Test
public void contextLoads() {
	new WebApplicationContextRunner()
			.withUserConfiguration(ConfigServerApplication.class)
			.withPropertyValues("spring.profiles.active:test,composite",
					"spring.jmx.enabled=false", "spring.config.name:configserver",
					"spring.cloud.config.server.composite[0].uri:https://source.developers.google.com",
					"spring.cloud.config.server.composite[0].type:git")
			.run(context -> {
				CompositeUtils.getCompositeTypeList(context.getEnvironment());
			});
}
 
Example 18
@Test
void webConfiguration() {
	WebApplicationContextRunner webContextRunner = new WebApplicationContextRunner()
			.withConfiguration(BASIC_AUTO_CONFIGURATIONS);
	webContextRunner.run((context) -> {
		assertThat(context).hasSingleBean(InitializrWebConfig.class);
		assertThat(context).hasSingleBean(ProjectGenerationController.class);
		assertThat(context).hasSingleBean(ProjectMetadataController.class);
		assertThat(context).hasSingleBean(CommandLineMetadataController.class);
		assertThat(context).hasSingleBean(SpringCliDistributionController.class);
	});
}
 
Example 19
@Test
void autoConfigWithCustomProjectGenerationController() {
	new WebApplicationContextRunner().withConfiguration(BASIC_AUTO_CONFIGURATIONS)
			.withUserConfiguration(CustomProjectGenerationController.class).run((context) -> {
				assertThat(context).hasSingleBean(ProjectGenerationController.class);
				assertThat(context.getBean(ProjectGenerationController.class))
						.isSameAs(context.getBean("testProjectGenerationController"));
			});

}
 
Example 20
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(AngularfacesAutoConfiguration.class, JavaxFacesAutoConfiguration.class));
}
 
Example 21
Source Project: joinfaces   Source File: RewriteAutoConfigurationTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(RewriteAutoConfiguration.class, FooConfiguration.class));
}
 
Example 22
@BeforeEach
void setup() {
	this.webApplicationContextRunner = new WebApplicationContextRunner().withConfiguration(
			AutoConfigurations.of(RewriteAutoConfiguration.class, FooConfiguration.class));
}
 
Example 23
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(FacesServletAutoConfiguration.class, JavaxFacesAutoConfiguration.class));
}
 
Example 24
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(JavaxFacesAutoConfiguration.class, ProjectStageAutoConfiguration.class));
}
 
Example 25
@BeforeEach
void setUp() {
	this.contextRunner = new WebApplicationContextRunner();
}
 
Example 26
Source Project: joinfaces   Source File: JpaWebAutoConfigurationTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(JpaWebAutoConfiguration.class, HibernateJpaAutoConfiguration.class));
}
 
Example 27
Source Project: joinfaces   Source File: AdminfacesAutoConfigurationTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
		.withConfiguration(AutoConfigurations.of(AdminfacesAutoConfiguration.class, PrimefacesAutoConfiguration.class));
}
 
Example 28
Source Project: joinfaces   Source File: JoinfacesAutoConfigurationTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(JoinfacesAutoConfiguration.class));
}
 
Example 29
Source Project: joinfaces   Source File: FileUploadFilterTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
	this.webApplicationContextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(PrimefacesFileUploadServletContextAutoConfiguration.class, MultipartAutoConfiguration.class));
}
 
Example 30
@Before
public void setUp() {
  AutoConfigurations autoConfigurationsUnderTest = AutoConfigurations.of(CamundaBpmAutoConfiguration.class, CamundaBpmWebappAutoConfiguration.class);
  AutoConfigurations additionalAutoConfigurations = AutoConfigurations.of(DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class);
  contextRunner = new WebApplicationContextRunner().withConfiguration(autoConfigurationsUnderTest).withConfiguration(additionalAutoConfigurations);
}