use of io.scalecube.services.auth.Authenticator.AUTH_CONTEXT_KEY in project scalecube by scalecube.
the class ServiceMethodInvokerTest method testInvokeOneWhenReturnNull.
@Test
@DisplayName("invokeOne should return empty response when service returns null")
void testInvokeOneWhenReturnNull() throws Exception {
final String methodName = "returnNull";
final Class<? extends StubService> serviceClass = stubService.getClass();
final Method method = serviceClass.getMethod(methodName);
final MethodInfo methodInfo = new MethodInfo(serviceClass.getName(), methodName, method.getReturnType(), IS_RETURN_TYPE_SERVICE_MESSAGE, CommunicationMode.REQUEST_RESPONSE, method.getParameterCount(), Void.TYPE, IS_REQUEST_TYPE_SERVICE_MESSAGE, AUTH);
serviceMethodInvoker = new ServiceMethodInvoker(method, stubService, methodInfo, DefaultErrorMapper.INSTANCE, dataDecoder, nullAuthenticator, nullPrincipalMapper);
ServiceMessage message = ServiceMessage.builder().qualifier(qualifierPrefix + methodName).build();
StepVerifier.create(Mono.deferContextual(context -> serviceMethodInvoker.invokeOne(message)).contextWrite(context -> context.put(AUTH_CONTEXT_KEY, AUTH_DATA))).verifyComplete();
}
use of io.scalecube.services.auth.Authenticator.AUTH_CONTEXT_KEY in project scalecube by scalecube.
the class ServiceMethodInvokerTest method testInvokeOneWhenThrowException.
@Test
@DisplayName("invokeOne should return error response when service throws exception")
void testInvokeOneWhenThrowException() throws Exception {
final String methodName = "throwException";
final Class<? extends StubService> serviceClass = stubService.getClass();
final Method method = serviceClass.getMethod(methodName);
final MethodInfo methodInfo = new MethodInfo(serviceClass.getName(), methodName, method.getReturnType(), IS_RETURN_TYPE_SERVICE_MESSAGE, CommunicationMode.REQUEST_RESPONSE, method.getParameterCount(), Void.TYPE, IS_REQUEST_TYPE_SERVICE_MESSAGE, AUTH);
serviceMethodInvoker = new ServiceMethodInvoker(method, stubService, methodInfo, DefaultErrorMapper.INSTANCE, dataDecoder, nullAuthenticator, nullPrincipalMapper);
ServiceMessage message = ServiceMessage.builder().qualifier(qualifierPrefix + methodName).build();
// invokeOne
final Mono<ServiceMessage> invokeOne = Mono.deferContextual(context -> serviceMethodInvoker.invokeOne(message)).contextWrite(context -> context.put(AUTH_CONTEXT_KEY, AUTH_DATA));
StepVerifier.create(invokeOne).assertNext(serviceMessage -> Assertions.assertTrue(serviceMessage.isError())).verifyComplete();
}
Aggregations