From 6155882f39078b3c60edb55f84120b76dc6e61fe Mon Sep 17 00:00:00 2001 From: ggmaleva Date: Mon, 19 Apr 2021 17:35:18 +0300 Subject: [PATCH] bump tomcat core --- .../rbkmoney/orgmanager/exception/BouncerException.java | 3 +++ .../orgmanager/exception/RestExceptionHandler.java | 3 +++ .../rbkmoney/orgmanager/service/BouncerServiceImpl.java | 8 ++------ .../orgmanager/controller/OrgsControllerTest.java | 2 +- .../orgmanager/service/BouncerServiceImplTest.java | 5 +++++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rbkmoney/orgmanager/exception/BouncerException.java b/src/main/java/com/rbkmoney/orgmanager/exception/BouncerException.java index 07849d5..c911f24 100644 --- a/src/main/java/com/rbkmoney/orgmanager/exception/BouncerException.java +++ b/src/main/java/com/rbkmoney/orgmanager/exception/BouncerException.java @@ -2,4 +2,7 @@ package com.rbkmoney.orgmanager.exception; public class BouncerException extends RuntimeException { + public BouncerException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/rbkmoney/orgmanager/exception/RestExceptionHandler.java b/src/main/java/com/rbkmoney/orgmanager/exception/RestExceptionHandler.java index 600af46..589d5bd 100644 --- a/src/main/java/com/rbkmoney/orgmanager/exception/RestExceptionHandler.java +++ b/src/main/java/com/rbkmoney/orgmanager/exception/RestExceptionHandler.java @@ -1,5 +1,6 @@ package com.rbkmoney.orgmanager.exception; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -7,6 +8,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; +@Slf4j @ControllerAdvice public class RestExceptionHandler extends ResponseEntityExceptionHandler { @@ -26,6 +28,7 @@ public class RestExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler(value = {BouncerException.class}) protected ResponseEntity handleBouncerException(BouncerException ex, WebRequest request) { + log.error(ex.getMessage(), ex.getCause()); return ResponseEntity .status(HttpStatus.FAILED_DEPENDENCY) .build(); diff --git a/src/main/java/com/rbkmoney/orgmanager/service/BouncerServiceImpl.java b/src/main/java/com/rbkmoney/orgmanager/service/BouncerServiceImpl.java index 48248ff..50c281f 100644 --- a/src/main/java/com/rbkmoney/orgmanager/service/BouncerServiceImpl.java +++ b/src/main/java/com/rbkmoney/orgmanager/service/BouncerServiceImpl.java @@ -9,11 +9,9 @@ import com.rbkmoney.orgmanager.config.properties.BouncerProperties; import com.rbkmoney.orgmanager.exception.BouncerException; import com.rbkmoney.orgmanager.service.dto.BouncerContextDto; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.springframework.stereotype.Service; -@Slf4j @Service @RequiredArgsConstructor public class BouncerServiceImpl implements BouncerService { @@ -30,11 +28,9 @@ public class BouncerServiceImpl implements BouncerService { Resolution resolution = judge.getResolution(); return resolution.isSetAllowed(); } catch (UserNotFound e) { - log.error("Error while build bouncer context", e); - throw new BouncerException(); + throw new BouncerException("Error while build bouncer context", e); } catch (TException e) { - log.error("Error while call bouncer", e); - throw new BouncerException(); + throw new BouncerException("Error while call bouncer", e); } } } diff --git a/src/test/java/com/rbkmoney/orgmanager/controller/OrgsControllerTest.java b/src/test/java/com/rbkmoney/orgmanager/controller/OrgsControllerTest.java index 9cc7823..697870d 100644 --- a/src/test/java/com/rbkmoney/orgmanager/controller/OrgsControllerTest.java +++ b/src/test/java/com/rbkmoney/orgmanager/controller/OrgsControllerTest.java @@ -34,7 +34,7 @@ public class OrgsControllerTest extends AbstractControllerTest { @Test void expelOrgMemberWithErrorCallBouncer() throws Exception { - doThrow(new BouncerException()).when(resourceAccessService) + doThrow(new BouncerException("Error bouncer", new RuntimeException())).when(resourceAccessService) .checkMemberRights(ORGANIZATION_ID, MEMBER_ID); mockMvc.perform(delete(String.format("/orgs/%s/members/%s", ORGANIZATION_ID, MEMBER_ID)) diff --git a/src/test/java/com/rbkmoney/orgmanager/service/BouncerServiceImplTest.java b/src/test/java/com/rbkmoney/orgmanager/service/BouncerServiceImplTest.java index 72fac19..d0c98aa 100644 --- a/src/test/java/com/rbkmoney/orgmanager/service/BouncerServiceImplTest.java +++ b/src/test/java/com/rbkmoney/orgmanager/service/BouncerServiceImplTest.java @@ -13,6 +13,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.springframework.test.context.junit.jupiter.SpringExtension; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -44,6 +46,7 @@ class BouncerServiceImplTest { var exception = assertThrows(BouncerException.class, () -> bouncerService.havePrivileges(bouncerContext)); + assertThat(exception.getMessage(), containsString("Error while build bouncer context")); } @Test @@ -53,6 +56,8 @@ class BouncerServiceImplTest { when(bouncerClient.judge(anyString(), any(Context.class))).thenThrow(new RulesetNotFound()); var exception = assertThrows(BouncerException.class, () -> bouncerService.havePrivileges(bouncerContext)); + + assertThat(exception.getMessage(), containsString("Error while call bouncer")); } @Test