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

The following examples show how to use org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner. 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
public void gatewayRSocketConfigured() {
	new ReactiveWebApplicationContextRunner().withUserConfiguration(MyConfig.class)
			.withSystemProperties("spring.cloud.gateway.rsocket.route-id=11")
			.withConfiguration(
					AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class,
							RSocketMessagingAutoConfiguration.class,
							GatewayRSocketCommonAutoConfiguration.class,
							GatewayRSocketAutoConfiguration.class,
							CompositeMeterRegistryAutoConfiguration.class,
							MetricsAutoConfiguration.class))
			.run(context -> assertThat(context).hasSingleBean(RoutingTable.class)
					.hasSingleBean(RoutingTableRoutes.class)
					.hasSingleBean(RoutingTableSocketAcceptorFilter.class)
					.hasSingleBean(GatewayServerRSocketFactoryProcessor.class)
					.hasSingleBean(BrokerProperties.class)
					.hasSingleBean(GatewaySocketAcceptor.class)
					.hasSingleBean(SocketAcceptorPredicateFilter.class)
					.hasSingleBean(RSocketServerBootstrap.class)
					.doesNotHaveBean(SocketAcceptorPredicate.class));
}
 
Example 2
@Test
public void nettyHttpClientDefaults() {
	new ReactiveWebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class,
					MetricsAutoConfiguration.class,
					SimpleMetricsExportAutoConfiguration.class,
					GatewayAutoConfiguration.class))
			.withPropertyValues("debug=true").run(context -> {
				assertThat(context).hasSingleBean(HttpClient.class);
				assertThat(context).hasBean("gatewayHttpClient");
				HttpClient httpClient = context.getBean(HttpClient.class);
				/*
				 * FIXME: 2.1.0 HttpClientOptions options = httpClient.options();
				 *
				 * PoolResources poolResources = options.getPoolResources();
				 * assertThat(poolResources).isNotNull(); //TODO: howto test
				 * PoolResources
				 *
				 * ClientProxyOptions proxyOptions = options.getProxyOptions();
				 * assertThat(proxyOptions).isNull();
				 *
				 * SslContext sslContext = options.sslContext();
				 * assertThat(sslContext).isNull();
				 */
			});
}
 
Example 3
@Test
public void autoConfigurationDisabledWhenSpringReactorIsActive() {
	ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(XsuaaResourceServerJwkAutoConfiguration.class,
							XsuaaAutoConfiguration.class));

	contextRunner.run((context) -> {
		assertThat(context.containsBean("xsuaaJwtDecoder"), is(false));
	});
}
 
Example 4
@Test
public void oauth2ContextConfiguredWithReactiveWebApp() {
	new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(this.configurations))
			.withPropertyValues(this.oAuth2ClientProperties).run((context) -> {
				assertServletOAuth2ContextConfigured(context);
				assertReactiveOAuth2ContextConfigured(context);
			});
}
 
Example 5
@Test
public void oauth2ContextConfiguredWithReactiveWebAppNoServlet() {
	new ReactiveWebApplicationContextRunner().withClassLoader(new FilteredClassLoader("javax.servlet"))
			.withConfiguration(AutoConfigurations.of(this.configurations))
			.withPropertyValues(this.oAuth2ClientProperties).run((context) -> {
				assertServletOAuth2ContextNotConfigured(context);
				assertReactiveOAuth2ContextConfigured(context);
			});
}
 
Example 6
@Test
public void testNonServletConfiguration() {
	new ReactiveWebApplicationContextRunner().withConfiguration(
			AutoConfigurations.of(
					StackdriverLoggingAutoConfiguration.class,
					GcpContextAutoConfiguration.class))
			.run((context) -> assertThat(context
					.getBeansOfType(TraceIdLoggingWebMvcInterceptor.class).size())
							.isEqualTo(0));
}
 
Example 7
@Test
public void reactiveEnvironment() {
	ReactiveWebApplicationContextRunner reactiveContextRunner = new ReactiveWebApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class,
							WebClientAutoConfiguration.class, SpringBootAdminClientAutoConfiguration.class));
	reactiveContextRunner.withPropertyValues("spring.boot.admin.client.url:http://localhost:8081")
			.run((context) -> assertThat(context).hasSingleBean(ApplicationRegistrator.class));
}
 
Example 8
@Test
public void nettyHttpClientConfigured() {
	new ReactiveWebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class,
					MetricsAutoConfiguration.class,
					SimpleMetricsExportAutoConfiguration.class,
					GatewayAutoConfiguration.class, HttpClientCustomizedConfig.class))
			.withPropertyValues(
					"spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager=true",
					"spring.cloud.gateway.httpclient.connect-timeout=10",
					"spring.cloud.gateway.httpclient.response-timeout=10s",
					"spring.cloud.gateway.httpclient.pool.type=fixed",
					// greather than integer max value
					"spring.cloud.gateway.httpclient.max-initial-line-length=2147483647",
					"spring.cloud.gateway.httpclient.proxy.host=myhost",
					"spring.cloud.gateway.httpclient.websocket.max-frame-payload-length=1024")
			.run(context -> {
				assertThat(context).hasSingleBean(HttpClient.class);
				HttpClient httpClient = context.getBean(HttpClient.class);
				HttpClientProperties properties = context
						.getBean(HttpClientProperties.class);
				assertThat(properties.getMaxInitialLineLength().toBytes())
						.isLessThanOrEqualTo(Integer.MAX_VALUE);
				/*
				 * FIXME: 2.1.0 HttpClientOptions options = httpClient.options();
				 *
				 * PoolResources poolResources = options.getPoolResources();
				 * assertThat(poolResources).isNotNull(); //TODO: howto test
				 * PoolResources
				 *
				 * ClientProxyOptions proxyOptions = options.getProxyOptions();
				 * assertThat(proxyOptions).isNotNull();
				 * assertThat(proxyOptions.getAddress().get().getHostName()).isEqualTo
				 * ("myhost");
				 *
				 * SslContext sslContext = options.sslContext();
				 * assertThat(sslContext).isNotNull();
				 */
				// TODO: howto test SslContext
				assertThat(context)
						.hasSingleBean(ReactorNettyRequestUpgradeStrategy.class);
				ReactorNettyRequestUpgradeStrategy upgradeStrategy = context
						.getBean(ReactorNettyRequestUpgradeStrategy.class);
				assertThat(upgradeStrategy.getMaxFramePayloadLength())
						.isEqualTo(1024);
				assertThat(upgradeStrategy.getHandlePing()).isTrue();
				assertThat(context).hasSingleBean(ReactorNettyWebSocketClient.class);
				ReactorNettyWebSocketClient webSocketClient = context
						.getBean(ReactorNettyWebSocketClient.class);
				assertThat(webSocketClient.getMaxFramePayloadLength())
						.isEqualTo(1024);
				HttpClientCustomizedConfig config = context
						.getBean(HttpClientCustomizedConfig.class);
				assertThat(config.called.get()).isTrue();
			});
}
 
Example 9
private ReactiveWebApplicationContextRunner webApplicationContextRunner() {
	return new ReactiveWebApplicationContextRunner().withConfiguration(
			AutoConfigurations.of(ApiVersionWebFluxAutoConfiguration.class,
					ApiVersionWebMvcAutoConfiguration.class));
}
 
Example 10
private ReactiveWebApplicationContextRunner webApplicationContextRunner() {
	return new ReactiveWebApplicationContextRunner().withConfiguration(autoConfigurations());
}