aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-10-14 11:44:03 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-10-14 15:25:20 +0000
commitb75fe3c7ce231c86cd4c6d052da453d02809c8f9 (patch)
tree726956d6771e12c1569979891098aab0c9ac910e /openecomp-be
parentfc768c6cea75cc8aba3233780b9f31c73e787c99 (diff)
Move DefaultExceptionMapper to be used widely
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I759b023cc37fa8c5eed8b01210bed4e91edb57cb Issue-ID: SDC-4189
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml2
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/DefaultExceptionMapper.java (renamed from openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java)9
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/resources/errorCodesToResponseStatusMapping.json (renamed from openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json)0
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/errors/DefaultExceptionMapperTest.java (renamed from openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java)52
4 files changed, 29 insertions, 34 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
index 8c005f0169..9c2aa51a28 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
@@ -90,7 +90,7 @@
<jaxrs:providers>
<ref bean="jsonProvider"/>
<bean class="org.openecomp.sdc.action.errors.ActionExceptionMapper"/>
- <bean class="org.openecomp.sdcrests.errors.DefaultExceptionMapper"/>
+ <bean class="org.openecomp.sdc.common.errors.DefaultExceptionMapper"/>
<bean class="org.openecomp.sdcrests.errors.ZusammenExceptionMapper"/>
<bean class="org.openecomp.sdc.logging.servlet.jaxrs.LoggingRequestFilter">
<property name="requestIdHeaders" value="X-ONAP-RequestID,X-RequestID,X-TransactionId,X-ECOMP-RequestID"/>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/DefaultExceptionMapper.java
index 22d6d90d8a..a059434709 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/DefaultExceptionMapper.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.openecomp.sdcrests.errors;
+package org.openecomp.sdc.common.errors;
import com.fasterxml.jackson.databind.JsonMappingException;
import java.util.ArrayList;
@@ -31,13 +31,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.hibernate.validator.internal.engine.path.PathImpl;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
-import org.openecomp.sdc.common.errors.GeneralErrorBuilder;
-import org.openecomp.sdc.common.errors.JsonMappingErrorBuilder;
-import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json b/openecomp-be/lib/openecomp-common-lib/src/main/resources/errorCodesToResponseStatusMapping.json
index 797609c8de..797609c8de 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/resources/errorCodesToResponseStatusMapping.json
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java b/openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/errors/DefaultExceptionMapperTest.java
index 680c3409ad..45c511706d 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/errors/DefaultExceptionMapperTest.java
@@ -17,69 +17,71 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdcrests.errors;
-import static org.junit.Assert.assertEquals;
+package org.openecomp.sdc.common.errors;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import com.fasterxml.jackson.databind.JsonMappingException;
import java.util.HashSet;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Response;
-import com.fasterxml.jackson.databind.JsonMappingException;
import org.hibernate.validator.internal.engine.path.PathImpl;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.common.errors.ErrorCode.ErrorCodeBuilder;
-@RunWith(MockitoJUnitRunner.class)
-public class DefaultExceptionMapperTest {
+@ExtendWith(MockitoExtension.class)
+class DefaultExceptionMapperTest {
private static final String TEST_MESSAGE = "Test message";
@Mock
private ConstraintViolation<String> constraintViolation;
- private PathImpl path = PathImpl.createRootPath();
+ private final PathImpl path = PathImpl.createRootPath();
@Test
- public void shouldMapCoreExceptionToResponse() {
+ void shouldMapCoreExceptionToResponse() {
DefaultExceptionMapper defaultExceptionMapper = new DefaultExceptionMapper();
ErrorCode errorCode = new ErrorCodeBuilder().withId("VSP_NOT_FOUND").withCategory(ErrorCategory.APPLICATION).build();
CoreException exception = new CoreException(errorCode);
- Response response = defaultExceptionMapper.toResponse(exception);
- assertEquals(response.getStatus(), 404);
+ try (final Response response = defaultExceptionMapper.toResponse(exception)) {
+ assertEquals(404, response.getStatus());
+ }
}
@Test
- public void shouldMapConstraintViolationExceptionToResponse() {
+ void shouldMapConstraintViolationExceptionToResponse() {
Mockito.when(constraintViolation.getPropertyPath()).thenReturn(path);
DefaultExceptionMapper defaultExceptionMapper = new DefaultExceptionMapper();
Set<ConstraintViolation<String>> violations = new HashSet<>();
violations.add(constraintViolation);
ConstraintViolationException exception = new ConstraintViolationException(TEST_MESSAGE, violations);
- Response response = defaultExceptionMapper.toResponse(exception);
- assertEquals(response.getStatus(), 417);
+ try (final Response response = defaultExceptionMapper.toResponse(exception)) {
+ assertEquals(417, response.getStatus());
+ }
}
@Test
- public void shouldMapJsonMappingExceptionToResponse() {
+ void shouldMapJsonMappingExceptionToResponse() {
DefaultExceptionMapper defaultExceptionMapper = new DefaultExceptionMapper();
JsonMappingException exception = new JsonMappingException(TEST_MESSAGE);
- Response response = defaultExceptionMapper.toResponse(exception);
- assertEquals(response.getStatus(), 417);
+ try (final Response response = defaultExceptionMapper.toResponse(exception)) {
+ assertEquals(417, response.getStatus());
+ }
}
@Test
- public void shouldMapOtherExceptionToResponse() {
+ void shouldMapOtherExceptionToResponse() {
DefaultExceptionMapper defaultExceptionMapper = new DefaultExceptionMapper();
Exception exception = new Exception(TEST_MESSAGE);
- Response response = defaultExceptionMapper.toResponse(exception);
- assertEquals(response.getStatus(), 500);
+ try (final Response response = defaultExceptionMapper.toResponse(exception)) {
+ assertEquals(500, response.getStatus());
+ }
}
-} \ No newline at end of file
+}