use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class WebFluxAutoConfigurationTests method whenAcceptHeaderLocaleContextResolverIsUsedAndHeaderIsAbsentThenConfiguredLocaleIsUsed.
@Test
void whenAcceptHeaderLocaleContextResolverIsUsedAndHeaderIsAbsentThenConfiguredLocaleIsUsed() {
this.contextRunner.withPropertyValues("spring.web.locale:en_UK").run((context) -> {
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
LocaleContextResolver localeContextResolver = context.getBean(LocaleContextResolver.class);
assertThat(localeContextResolver).isInstanceOf(AcceptHeaderLocaleContextResolver.class);
LocaleContext localeContext = localeContextResolver.resolveLocaleContext(exchange);
assertThat(localeContext.getLocale()).isEqualTo(StringUtils.parseLocaleString("en_UK"));
});
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ApplicationContextServerWebExchangeMatcherTests method matchesWhenContextIsNull.
@Test
void matchesWhenContextIsNull() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
assertThatIllegalStateException().isThrownBy(() -> new TestApplicationContextServerWebExchangeMatcher<>(ExistingBean.class).callMatchesAndReturnProvidedContext(exchange)).withMessageContaining("No ApplicationContext found on ServerWebExchange.");
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenCloudFoundrySecurityServiceIsNullShouldReturnError.
@Test
void preHandleWhenCloudFoundrySecurityServiceIsNullShouldReturnError() {
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, null, "my-app-id");
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeErrorWith((ex) -> assertThat(((CloudFoundryAuthorizationException) ex).getReason()).isEqualTo(Reason.SERVICE_UNAVAILABLE)).verify();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenTokenIsNotBearerShouldReturnMissingAuthorization.
@Test
void preHandleWhenTokenIsNotBearerShouldReturnMissingAuthorization() {
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeNextWith((response) -> assertThat(response.getStatus()).isEqualTo(Reason.MISSING_AUTHORIZATION.getStatus())).verifyComplete();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleSuccessfulWithRestrictedAccess.
@Test
void preHandleSuccessfulWithRestrictedAccess() {
String accessToken = mockAccessToken();
given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(Mono.just(AccessLevel.RESTRICTED));
given(this.tokenValidator.validate(any())).willReturn(Mono.empty());
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/info").header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(exchange, "info")).consumeNextWith((response) -> {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
assertThat((AccessLevel) exchange.getAttribute("cloudFoundryAccessLevel")).isEqualTo(AccessLevel.RESTRICTED);
}).verifyComplete();
}
Aggregations