Move DefaultExceptionMapper to be used widely 76/131476/3
authorvasraz <vasyl.razinkov@est.tech>
Fri, 14 Oct 2022 10:44:03 +0000 (11:44 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Fri, 14 Oct 2022 15:25:20 +0000 (15:25 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I759b023cc37fa8c5eed8b01210bed4e91edb57cb
Issue-ID: SDC-4189

openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/DefaultExceptionMapper.java [moved from openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java with 92% similarity]
openecomp-be/lib/openecomp-common-lib/src/main/resources/errorCodesToResponseStatusMapping.json [moved from openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json with 100% similarity]
openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/errors/DefaultExceptionMapperTest.java [moved from openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java with 68% similarity]

index 8c005f0..9c2aa51 100644 (file)
@@ -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"/>
@@ -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;
 
  * 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
+}