Skip to content

Commit

Permalink
test fixes #355
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmlet committed May 15, 2023
1 parent 2bf8d12 commit aa27f6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import org.lognet.springboot.grpc.recovery.GRpcExceptionScope;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Optional;
import java.util.stream.IntStream;


Expand All @@ -31,6 +33,8 @@ public ReactiveGreeterGrpcService(ReactiveGreeterService reactiveGreeterService)
@Override
@Secured({})
public Mono<ReactiveHelloResponse> greet(Mono<ReactiveHelloRequest> request) {
Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
.orElseThrow();
return reactiveGreeterService.greet(request);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.lognet.springboot.grpc.auth.JwtAuthBaseTest;
import org.lognet.springboot.grpc.auth.JwtRoleTest;
import org.lognet.springboot.grpc.demo.DemoApp;
import org.lognet.springboot.grpc.security.GrpcSecurity;
import org.lognet.springboot.grpc.security.GrpcSecurityConfigurerAdapter;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -34,27 +36,15 @@

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApp.class, webEnvironment = NONE)
@SpringBootTest(classes = DemoApp.class)
@ActiveProfiles({"keycloack-test", "r2dbc-test"})
@DirtiesContext
public class ReactiveDemoTest extends JwtAuthBaseTest {

@TestConfiguration
static class TestCfg {
private static class DemoGrpcSecurityAdapter extends GrpcSecurityConfigurerAdapter {
@Override
public void configure(GrpcSecurity builder) throws Exception {
builder.authorizeRequests()
.withSecuredAnnotation();

}
}
}

@Test
public void grpcGreetTest() {
String shrek = "Shrek";
String message = ReactiveGreeterGrpc.newBlockingStub(channel)
String message = ReactiveGreeterGrpc.newBlockingStub(getChannel())
.greet(ReactiveHelloRequest.newBuilder().setName(shrek).build())
.getMessage();
assertThat(message, containsString(shrek));
Expand All @@ -64,7 +54,7 @@ public void grpcGreetTest() {
@Test
public void reactorGreetTest() {
String shrek = "Shrek";
ReactiveHelloResponse helloResponse = ReactorReactiveGreeterGrpc.newReactorStub(channel)
ReactiveHelloResponse helloResponse = ReactorReactiveGreeterGrpc.newReactorStub(getChannel())
.greet(simpleRequest(shrek))
.block(Duration.ofSeconds(10));
assertThat(helloResponse, notNullValue());
Expand All @@ -78,7 +68,7 @@ public void reactorGreetFailureTest() {
String shrek = "Wolf";
StatusRuntimeException e = assertThrows(StatusRuntimeException.class, () -> {

ReactorReactiveGreeterGrpc.newReactorStub(channel)
ReactorReactiveGreeterGrpc.newReactorStub(getChannel())
.greet(simpleRequest(shrek))
.block(Duration.ofSeconds(10));
});
Expand All @@ -91,7 +81,7 @@ public void reactorGreetFailureTest() {
@Test
public void reactorMultiGreerTest() {
String shrek = "Shrek";
List<ReactiveHelloResponse> greets = ReactorReactiveGreeterGrpc.newReactorStub(channel)
List<ReactiveHelloResponse> greets = ReactorReactiveGreeterGrpc.newReactorStub(getChannel())
.multiGreet(simpleRequest(shrek))
.collectList()
.block(Duration.ofSeconds(10));
Expand All @@ -111,7 +101,7 @@ public void reactorBidiGreerTest() {
"Robin",
"Christopher"
};
List<ReactiveHelloResponse> greets = ReactorReactiveGreeterGrpc.newReactorStub(channel)
List<ReactiveHelloResponse> greets = ReactorReactiveGreeterGrpc.newReactorStub(getChannel())
.streamGreet(
Flux.fromStream(Arrays.stream(names).map(this::simpleRequest))
)
Expand Down

0 comments on commit aa27f6f

Please sign in to comment.