summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2019-04-04 04:19:54 -0400
committerTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2019-04-04 04:19:54 -0400
commitefbd6b79e61a62891f043926c7d3876ae945e50f (patch)
tree85d0e161a7bf9979d0f56b1e3fe1b0c1491f0788
parent13d5d23cf1e7fcd52244ef284019a0eb280bb14a (diff)
junits for ControllersUtils
-Added new test to check Exception handling Change-Id: I4e634157ad942118221c07d7fe21ee33af68a9ef Issue-ID: VID-449 Signed-off-by: Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
index f084b3dec..80836d155 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
@@ -21,16 +21,25 @@ package org.onap.vid.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Mockito.mock;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.model.ExceptionResponse;
import org.onap.vid.utils.SystemPropertiesWrapper;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
@RunWith(MockitoJUnitRunner.class)
public class ControllersUtilsTest {
@@ -110,4 +119,26 @@ public class ControllersUtilsTest {
// THEN
assertThat(loginId).isEmpty();
}
+
+ @Test
+ public void shouldCreateResponseEntity_fromGivenException() {
+ // GIVEN
+ EELFLoggerDelegate eelfLoggerDelegate = mock(EELFLoggerDelegate.class);
+ Response response = mock(Response.class);
+ given(response.getStatus()).willReturn(HttpStatus.OK.value());
+ WebApplicationException webApplicationException = new WebApplicationException("ErrorMessage", response);
+
+ // WHEN
+ ResponseEntity responseEntity = ControllersUtils
+ .handleWebApplicationException(webApplicationException, eelfLoggerDelegate);
+
+ // THEN
+ assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
+ assertThat(responseEntity.getBody())
+ .isInstanceOfSatisfying(ExceptionResponse.class,
+ er -> assertThat(er.getMessage()).isEqualTo("ErrorMessage (Request id: null)"));
+ then(eelfLoggerDelegate).should()
+ .error(EELFLoggerDelegate.errorLogger, "{}: {}", "handleWebApplicationException",
+ ExceptionUtils.getMessage(webApplicationException), webApplicationException);
+ }
} \ No newline at end of file