反应堆BubblingException代替自定义异常

时间:2018-12-19 13:54:35

标签: spring spring-boot spring-webflux project-reactor junit5

我从订阅使用者中抛出了一个自定义异常,但是在测试案例中,我得到了react.core.Exceptions.BubblingException。

部分代码:

 return loginBOMonoValidated.map(this::checkAuth).map(login -> getUserContactsBOMono(login));

private LoginBO checkAuth(LoginBO loginBO) {

    if (!loginBO.getClientId().equals(loginBO.getLoginId())) {

      LoginDTO loginDTO = new LoginDTO(loginBO.getLoginId(), loginBO.getClientId());
      authorizationRemoteClient
          .validateManagerClientAccess(Mono.just(loginDTO))
          .subscribe(authClientConsumer);
      return new LoginBO(loginBO.getClientId(), loginBO.getClientId());
    } 
      else return loginBO;
  }

private Consumer<Boolean> authClientConsumer =
  bol -> {
    if (!bol) {
      logger.error(ErrorCodes.LOGIN_ID_VALIDATION_ERROR.getDescription());

      throw new AuthorizationException();
    }
  };

测试

Throwable exception =
        assertThrows(
            AuthorizationException.class,
            () -> {
              Mono<UserContactsBO> contact =contactInfoService.getUserContacts(Mono.just(new LoginBO("123456789", "1234")));
              contact.subscribe();
            });

预期:。**。AuthorizationException

Actual:reactor.core.Exceptions.BubblingException

0 个答案:

没有答案