Remove blank lines from all tests
Remove all blank lines from test code so that test methods are visually grouped together. This generally helps to make the test classes easer to scan, however, the "given" / "when" / "then" blocks used by some tests are now not as easy to discern. Issue gh-8945
This commit is contained in:
-6
@@ -81,11 +81,8 @@ public class AnonymousPayloadInterceptorTests {
|
||||
@Test
|
||||
public void interceptWhenNoAuthenticationThenAnonymousAuthentication() {
|
||||
AuthenticationPayloadInterceptorChain chain = new AuthenticationPayloadInterceptorChain();
|
||||
|
||||
this.interceptor.intercept(this.exchange, chain).block();
|
||||
|
||||
Authentication authentication = chain.getAuthentication();
|
||||
|
||||
assertThat(authentication).isInstanceOf(AnonymousAuthenticationToken.class);
|
||||
}
|
||||
|
||||
@@ -93,12 +90,9 @@ public class AnonymousPayloadInterceptorTests {
|
||||
public void interceptWhenAuthenticationThenOriginalAuthentication() {
|
||||
AuthenticationPayloadInterceptorChain chain = new AuthenticationPayloadInterceptorChain();
|
||||
TestingAuthenticationToken expected = new TestingAuthenticationToken("test", "password");
|
||||
|
||||
this.interceptor.intercept(this.exchange, chain)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(expected)).block();
|
||||
|
||||
Authentication authentication = chain.getAuthentication();
|
||||
|
||||
assertThat(authentication).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
-9
@@ -85,12 +85,9 @@ public class AuthenticationPayloadInterceptorTests {
|
||||
PayloadExchange exchange = createExchange();
|
||||
TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.authenticationManager.authenticate(any())).willReturn(Mono.just(expectedAuthentication));
|
||||
|
||||
AuthenticationPayloadInterceptorChain authenticationPayloadChain = new AuthenticationPayloadInterceptorChain();
|
||||
interceptor.intercept(exchange, authenticationPayloadChain).block();
|
||||
|
||||
Authentication authentication = authenticationPayloadChain.getAuthentication();
|
||||
|
||||
verify(this.authenticationManager).authenticate(this.authenticationArg.capture());
|
||||
assertThat(this.authenticationArg.getValue())
|
||||
.isEqualToComparingFieldByField(new UsernamePasswordAuthenticationToken("user", "password"));
|
||||
@@ -100,21 +97,17 @@ public class AuthenticationPayloadInterceptorTests {
|
||||
@Test
|
||||
public void interceptWhenAuthenticationSuccessThenChainSubscribedOnce() {
|
||||
AuthenticationPayloadInterceptor interceptor = new AuthenticationPayloadInterceptor(this.authenticationManager);
|
||||
|
||||
PayloadExchange exchange = createExchange();
|
||||
TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.authenticationManager.authenticate(any())).willReturn(Mono.just(expectedAuthentication));
|
||||
|
||||
PublisherProbe<Void> voidResult = PublisherProbe.empty();
|
||||
PayloadInterceptorChain chain = mock(PayloadInterceptorChain.class);
|
||||
given(chain.next(any())).willReturn(voidResult.mono());
|
||||
|
||||
StepVerifier.create(interceptor.intercept(exchange, chain))
|
||||
.then(() -> assertThat(voidResult.subscribeCount()).isEqualTo(1)).verifyComplete();
|
||||
}
|
||||
|
||||
private Payload createRequestPayload() {
|
||||
|
||||
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
|
||||
BasicAuthenticationEncoder encoder = new BasicAuthenticationEncoder();
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
@@ -122,12 +115,10 @@ public class AuthenticationPayloadInterceptorTests {
|
||||
MimeType mimeType = UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE;
|
||||
Map<String, Object> hints = null;
|
||||
DataBuffer dataBuffer = encoder.encodeValue(credentials, factory, elementType, mimeType, hints);
|
||||
|
||||
ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
|
||||
CompositeByteBuf metadata = allocator.compositeBuffer();
|
||||
CompositeMetadataCodec.encodeAndAddMetadata(metadata, allocator, mimeType.toString(),
|
||||
NettyDataBufferFactory.toByteBuf(dataBuffer));
|
||||
|
||||
return DefaultPayload.create(allocator.buffer(), metadata);
|
||||
}
|
||||
|
||||
|
||||
-10
@@ -60,10 +60,8 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
@Test
|
||||
public void interceptWhenAuthenticationEmptyAndSubscribedThenException() {
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(
|
||||
AuthenticatedReactiveAuthorizationManager.authenticated());
|
||||
|
||||
StepVerifier.create(interceptor.intercept(this.exchange, this.chain))
|
||||
.then(() -> this.chainResult.assertWasNotSubscribed())
|
||||
.verifyError(AuthenticationCredentialsNotFoundException.class);
|
||||
@@ -73,9 +71,7 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
public void interceptWhenAuthenticationNotSubscribedAndEmptyThenCompletes() {
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
given(this.authorizationManager.verify(any(), any())).willReturn(this.managerResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(this.authorizationManager);
|
||||
|
||||
StepVerifier.create(interceptor.intercept(this.exchange, this.chain))
|
||||
.then(() -> this.chainResult.assertWasSubscribed()).verifyComplete();
|
||||
}
|
||||
@@ -83,14 +79,11 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
@Test
|
||||
public void interceptWhenNotAuthorizedThenException() {
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(
|
||||
AuthorityReactiveAuthorizationManager.hasRole("USER"));
|
||||
Context userContext = ReactiveSecurityContextHolder
|
||||
.withAuthentication(new TestingAuthenticationToken("user", "password"));
|
||||
|
||||
Mono<Void> intercept = interceptor.intercept(this.exchange, this.chain).subscriberContext(userContext);
|
||||
|
||||
StepVerifier.create(intercept).then(() -> this.chainResult.assertWasNotSubscribed())
|
||||
.verifyError(AccessDeniedException.class);
|
||||
}
|
||||
@@ -98,14 +91,11 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
@Test
|
||||
public void interceptWhenAuthorizedThenContinues() {
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(
|
||||
AuthenticatedReactiveAuthorizationManager.authenticated());
|
||||
Context userContext = ReactiveSecurityContextHolder
|
||||
.withAuthentication(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
|
||||
|
||||
Mono<Void> intercept = interceptor.intercept(this.exchange, this.chain).subscriberContext(userContext);
|
||||
|
||||
StepVerifier.create(intercept).then(() -> this.chainResult.assertWasSubscribed()).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
-4
@@ -56,7 +56,6 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz))
|
||||
.build();
|
||||
|
||||
assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@@ -67,7 +66,6 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz))
|
||||
.build();
|
||||
|
||||
assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@@ -80,7 +78,6 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
.add(new PayloadExchangeMatcherEntry<>((e) -> PayloadExchangeMatcher.MatchResult.notMatch(),
|
||||
this.authz2))
|
||||
.build();
|
||||
|
||||
assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@@ -93,7 +90,6 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
.add(new PayloadExchangeMatcherEntry<>((e) -> PayloadExchangeMatcher.MatchResult.notMatch(),
|
||||
this.authz))
|
||||
.add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz2)).build();
|
||||
|
||||
assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
-59
@@ -113,18 +113,14 @@ public class PayloadInterceptorRSocketTests {
|
||||
}
|
||||
|
||||
// single interceptor
|
||||
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.delegate.fireAndForget(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.fireAndForget(this.payload)).then(() -> this.voidResult.assertWasSubscribed())
|
||||
.verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -133,14 +129,11 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void fireAndForgetWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.fireAndForget(this.payload))
|
||||
.then(() -> this.voidResult.assertWasNotSubscribed())
|
||||
.verifyErrorSatisfies((e) -> assertThat(e).isEqualTo(expected));
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -150,7 +143,6 @@ public class PayloadInterceptorRSocketTests {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.fireAndForget(any())).willReturn(Mono.empty());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
public Mono<Void> fireAndForget(Payload payload) {
|
||||
@@ -159,9 +151,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
};
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
interceptor.fireAndForget(this.payload).block();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).fireAndForget(this.payload);
|
||||
@@ -171,14 +161,11 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestResponseWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.requestResponse(any())).willReturn(this.payloadResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestResponse(this.payload))
|
||||
.then(() -> this.payloadResult.assertSubscribers()).then(() -> this.payloadResult.emit(this.payload))
|
||||
.expectNext(this.payload).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).requestResponse(this.payload);
|
||||
@@ -188,12 +175,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestResponseWhenInterceptorErrorsThenDelegateNotInvoked() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
assertThatCode(() -> interceptor.requestResponse(this.payload).block()).isEqualTo(expected);
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verifyZeroInteractions(this.delegate);
|
||||
@@ -204,7 +188,6 @@ public class PayloadInterceptorRSocketTests {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.requestResponse(any())).willReturn(this.payloadResult.mono());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
public Mono<Payload> requestResponse(Payload payload) {
|
||||
@@ -213,11 +196,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
};
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestResponse(this.payload))
|
||||
.then(() -> this.payloadResult.assertSubscribers()).then(() -> this.payloadResult.emit(this.payload))
|
||||
.expectNext(this.payload).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).requestResponse(this.payload);
|
||||
@@ -227,13 +208,10 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestStreamWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.requestStream(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestStream(this.payload)).then(() -> this.payloadResult.assertSubscribers())
|
||||
.then(() -> this.payloadResult.emit(this.payload)).expectNext(this.payload).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -242,14 +220,11 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestStreamWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestStream(this.payload))
|
||||
.then(() -> this.payloadResult.assertNoSubscribers())
|
||||
.verifyErrorSatisfies((e) -> assertThat(e).isEqualTo(expected));
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -259,7 +234,6 @@ public class PayloadInterceptorRSocketTests {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.requestStream(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
public Flux<Payload> requestStream(Payload payload) {
|
||||
@@ -268,10 +242,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
};
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestStream(this.payload)).then(() -> this.payloadResult.assertSubscribers())
|
||||
.then(() -> this.payloadResult.emit(this.payload)).expectNext(this.payload).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).requestStream(this.payload);
|
||||
@@ -281,14 +253,11 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestChannelWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.requestChannel(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestChannel(Flux.just(this.payload)))
|
||||
.then(() -> this.payloadResult.assertSubscribers()).then(() -> this.payloadResult.emit(this.payload))
|
||||
.expectNext(this.payload).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).requestChannel(any());
|
||||
@@ -298,14 +267,11 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestChannelWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestChannel(Flux.just(this.payload)))
|
||||
.then(() -> this.payloadResult.assertNoSubscribers())
|
||||
.verifyErrorSatisfies((e) -> assertThat(e).isEqualTo(expected));
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -316,7 +282,6 @@ public class PayloadInterceptorRSocketTests {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.requestChannel(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
public Flux<Payload> requestChannel(Publisher<Payload> payload) {
|
||||
@@ -325,10 +290,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
};
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.requestChannel(payload)).then(() -> this.payloadResult.assertSubscribers())
|
||||
.then(() -> this.payloadResult.emit(this.payload)).expectNext(this.payload).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).requestChannel(any());
|
||||
@@ -338,13 +301,10 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void metadataPushWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.metadataPush(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.metadataPush(this.payload)).then(() -> this.voidResult.assertWasSubscribed())
|
||||
.verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -353,13 +313,10 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void metadataPushWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.metadataPush(this.payload)).then(() -> this.voidResult.assertWasNotSubscribed())
|
||||
.verifyErrorSatisfies((e) -> assertThat(e).isEqualTo(expected));
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
}
|
||||
@@ -369,7 +326,6 @@ public class PayloadInterceptorRSocketTests {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.metadataPush(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
public Mono<Void> metadataPush(Payload payload) {
|
||||
@@ -378,9 +334,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
};
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
StepVerifier.create(interceptor.metadataPush(this.payload)).verifyComplete();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.delegate).metadataPush(this.payload);
|
||||
@@ -388,18 +342,14 @@ public class PayloadInterceptorRSocketTests {
|
||||
}
|
||||
|
||||
// multiple interceptors
|
||||
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptorsCompleteThenDelegateInvoked() {
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.interceptor2.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.delegate.fireAndForget(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
interceptor.fireAndForget(this.payload).block();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
this.voidResult.assertWasSubscribed();
|
||||
@@ -410,12 +360,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.interceptor2.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.delegate.fireAndForget(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
interceptor.fireAndForget(this.payload).block();
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.interceptor2).intercept(any(), any());
|
||||
@@ -427,12 +374,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void fireAndForgetWhenInterceptor1ErrorsThenInterceptor2AndDelegateNotInvoked() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
assertThatCode(() -> interceptor.fireAndForget(this.payload).block()).isEqualTo(expected);
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verifyZeroInteractions(this.interceptor2);
|
||||
@@ -444,12 +388,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.interceptor2.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
assertThatCode(() -> interceptor.fireAndForget(this.payload).block()).isEqualTo(expected);
|
||||
|
||||
verify(this.interceptor).intercept(this.exchange.capture(), any());
|
||||
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
|
||||
verify(this.interceptor2).intercept(any(), any());
|
||||
|
||||
-11
@@ -76,9 +76,7 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
@Test
|
||||
public void applyWhenDefaultMetadataMimeTypeThenDefaulted() {
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType().toString())
|
||||
.isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
@@ -88,9 +86,7 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
public void acceptWhenDefaultMetadataMimeTypeOverrideThenDefaulted() {
|
||||
this.acceptorInterceptor.setDefaultMetadataMimeType(MediaType.APPLICATION_JSON);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
@@ -98,9 +94,7 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
@Test
|
||||
public void acceptWhenDefaultDataMimeTypeThenDefaulted() {
|
||||
this.acceptorInterceptor.setDefaultDataMimeType(MediaType.APPLICATION_JSON);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType().toString())
|
||||
.isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
@@ -109,16 +103,11 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
private PayloadExchange captureExchange() {
|
||||
given(this.socketAcceptor.accept(any(), any())).willReturn(Mono.just(this.rSocket));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
|
||||
SocketAcceptor wrappedAcceptor = this.acceptorInterceptor.apply(this.socketAcceptor);
|
||||
RSocket result = wrappedAcceptor.accept(this.setupPayload, this.rSocket).block();
|
||||
|
||||
assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
|
||||
|
||||
given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
|
||||
|
||||
result.fireAndForget(this.payload).block();
|
||||
|
||||
ArgumentCaptor<PayloadExchange> exchangeArg = ArgumentCaptor.forClass(PayloadExchange.class);
|
||||
verify(this.interceptor, times(2)).intercept(exchangeArg.capture(), any());
|
||||
return exchangeArg.getValue();
|
||||
|
||||
-15
@@ -107,9 +107,7 @@ public class PayloadSocketAcceptorTests {
|
||||
@Test
|
||||
public void acceptWhenDefaultMetadataMimeTypeThenDefaulted() {
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType().toString())
|
||||
.isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
@@ -119,9 +117,7 @@ public class PayloadSocketAcceptorTests {
|
||||
public void acceptWhenDefaultMetadataMimeTypeOverrideThenDefaulted() {
|
||||
this.acceptor.setDefaultMetadataMimeType(MediaType.APPLICATION_JSON);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
@@ -129,9 +125,7 @@ public class PayloadSocketAcceptorTests {
|
||||
@Test
|
||||
public void acceptWhenDefaultDataMimeTypeThenDefaulted() {
|
||||
this.acceptor.setDefaultDataMimeType(MediaType.APPLICATION_JSON);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType().toString())
|
||||
.isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
@@ -141,9 +135,7 @@ public class PayloadSocketAcceptorTests {
|
||||
public void acceptWhenExplicitMimeTypeThenThenOverrideDefault() {
|
||||
given(this.setupPayload.metadataMimeType()).willReturn(MediaType.TEXT_PLAIN_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
assertThat(exchange.getMetadataMimeType()).isEqualTo(MediaType.TEXT_PLAIN);
|
||||
assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
@@ -164,24 +156,17 @@ public class PayloadSocketAcceptorTests {
|
||||
};
|
||||
List<PayloadInterceptor> interceptors = Arrays.asList(authenticateInterceptor);
|
||||
this.acceptor = new PayloadSocketAcceptor(captureSecurityContext, interceptors);
|
||||
|
||||
this.acceptor.accept(this.setupPayload, this.rSocket).block();
|
||||
|
||||
assertThat(captureSecurityContext.getSecurityContext()).isEqualTo(expectedSecurityContext);
|
||||
}
|
||||
|
||||
private PayloadExchange captureExchange() {
|
||||
given(this.delegate.accept(any(), any())).willReturn(Mono.just(this.rSocket));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
|
||||
RSocket result = this.acceptor.accept(this.setupPayload, this.rSocket).block();
|
||||
|
||||
assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
|
||||
|
||||
given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
|
||||
|
||||
result.fireAndForget(this.payload).block();
|
||||
|
||||
ArgumentCaptor<PayloadExchange> exchangeArg = ArgumentCaptor.forClass(PayloadExchange.class);
|
||||
verify(this.interceptor, times(2)).intercept(exchangeArg.capture(), any());
|
||||
return exchangeArg.getValue();
|
||||
|
||||
-2
@@ -42,11 +42,9 @@ public class BasicAuthenticationDecoderTests {
|
||||
ResolvableType elementType = ResolvableType.forClass(UsernamePasswordMetadata.class);
|
||||
MimeType mimeType = UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE;
|
||||
Map<String, Object> hints = null;
|
||||
|
||||
DataBuffer dataBuffer = encoder.encodeValue(expectedCredentials, factory, elementType, mimeType, hints);
|
||||
UsernamePasswordMetadata actualCredentials = decoder
|
||||
.decodeToMono(Mono.just(dataBuffer), elementType, mimeType, hints).block();
|
||||
|
||||
assertThat(actualCredentials).isEqualToComparingFieldByField(expectedCredentials);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user