|
|
|
@ -16,6 +16,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.mock.web.server; |
|
|
|
package org.springframework.mock.web.server; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.security.Principal; |
|
|
|
|
|
|
|
|
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
@ -39,16 +41,19 @@ import org.springframework.web.server.session.WebSessionManager; |
|
|
|
* @since 5.0 |
|
|
|
* @since 5.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class MockServerWebExchange extends DefaultServerWebExchange { |
|
|
|
public final class MockServerWebExchange extends DefaultServerWebExchange { |
|
|
|
|
|
|
|
private final Mono<Principal> principalMono; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MockServerWebExchange( |
|
|
|
private MockServerWebExchange( |
|
|
|
MockServerHttpRequest request, @Nullable WebSessionManager sessionManager, |
|
|
|
MockServerHttpRequest request, @Nullable WebSessionManager sessionManager, |
|
|
|
@Nullable ApplicationContext applicationContext) { |
|
|
|
@Nullable ApplicationContext applicationContext, Mono<Principal> principalMono) { |
|
|
|
|
|
|
|
|
|
|
|
super(request, new MockServerHttpResponse(), |
|
|
|
super(request, new MockServerHttpResponse(), |
|
|
|
sessionManager != null ? sessionManager : new DefaultWebSessionManager(), |
|
|
|
sessionManager != null ? sessionManager : new DefaultWebSessionManager(), |
|
|
|
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver(), |
|
|
|
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver(), |
|
|
|
applicationContext); |
|
|
|
applicationContext); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.principalMono = principalMono; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,6 +62,12 @@ public final class MockServerWebExchange extends DefaultServerWebExchange { |
|
|
|
return (MockServerHttpResponse) super.getResponse(); |
|
|
|
return (MockServerHttpResponse) super.getResponse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public <T extends Principal> Mono<T> getPrincipal() { |
|
|
|
|
|
|
|
return (Mono<T>)this.principalMono; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a {@link MockServerWebExchange} from the given mock request. |
|
|
|
* Create a {@link MockServerWebExchange} from the given mock request. |
|
|
|
@ -111,6 +122,8 @@ public final class MockServerWebExchange extends DefaultServerWebExchange { |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private ApplicationContext applicationContext; |
|
|
|
private ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Mono<Principal> principalMono = Mono.empty(); |
|
|
|
|
|
|
|
|
|
|
|
public Builder(MockServerHttpRequest request) { |
|
|
|
public Builder(MockServerHttpRequest request) { |
|
|
|
this.request = request; |
|
|
|
this.request = request; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -147,11 +160,16 @@ public final class MockServerWebExchange extends DefaultServerWebExchange { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Builder principal(@Nullable Principal principal) { |
|
|
|
|
|
|
|
this.principalMono = (principal == null) ? Mono.empty() : Mono.just(principal); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Build the {@code MockServerWebExchange} instance. |
|
|
|
* Build the {@code MockServerWebExchange} instance. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MockServerWebExchange build() { |
|
|
|
public MockServerWebExchange build() { |
|
|
|
return new MockServerWebExchange(this.request, this.sessionManager, this.applicationContext); |
|
|
|
return new MockServerWebExchange(this.request, this.sessionManager, this.applicationContext, this.principalMono); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|