aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml21
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java10
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java85
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapperTest.java67
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapperTest.java34
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/StringWrapperResponseTest.java32
6 files changed, 244 insertions, 5 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
index 71552b75c4..c9c70ab804 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
@@ -27,6 +27,10 @@
<version>1.5.1-SNAPSHOT</version>
</parent>
+ <properties>
+ <jersey-common.version>2.22.2</jersey-common.version>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.openecomp.sdc</groupId>
@@ -77,6 +81,23 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ <version>${jersey-common.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.bean-matchers</groupId>
+ <artifactId>bean-matchers</artifactId>
+ <version>${bean-matchers.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java
index 4100cc5bf7..abf6024701 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java
@@ -33,15 +33,15 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
public class ZusammenExceptionMapper implements ExceptionMapper<SdcRuntimeException> {
private static final String ZUSAMMEN_DB_PREFIX = Module.ZDB + "-";
- private static final String VLM_VSP_VERSION_ID_DOES_NOT_EXISTS =
+ static final String VLM_VSP_VERSION_ID_DOES_NOT_EXISTS =
ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_NOT_EXIST;
- private static final String VLM_VSP_ITEM_ID_DOES_NOT_EXISTS =
+ static final String VLM_VSP_ITEM_ID_DOES_NOT_EXISTS =
ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_DOES_NOT_EXIST;
- private static final String SUB_ENTITY_ID_DOES_NOT_EXISTS =
+ static final String SUB_ENTITY_ID_DOES_NOT_EXISTS =
ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ELEMENT_GET_INFO;
- private static final String FAILED_TO_SYNC =
+ static final String FAILED_TO_SYNC =
ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_SYNC;
- private static final String FAILED_TO_PUBLISH_OUT_OF_SYNC =
+ static final String FAILED_TO_PUBLISH_OUT_OF_SYNC =
ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode
.ZU_ITEM_VERSION_PUBLISH_NOT_ALLOWED;
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/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java
new file mode 100644
index 0000000000..8634cd3720
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/DefaultExceptionMapperTest.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.errors;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.ws.rs.core.Response;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.hibernate.validator.internal.engine.path.PathImpl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.openecomp.sdc.common.errors.ErrorCode.ErrorCodeBuilder;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DefaultExceptionMapperTest {
+
+ private static final String TEST_MESSAGE = "Test message";
+
+ @Mock
+ private ConstraintViolation<String> constraintViolation;
+ private PathImpl path = PathImpl.createRootPath();
+
+ @Test
+ public 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);
+ }
+
+ @Test
+ public 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);
+ }
+
+ @Test
+ public void shouldMapJsonMappingExceptionToResponse() {
+ DefaultExceptionMapper defaultExceptionMapper = new DefaultExceptionMapper();
+ JsonMappingException exception = new JsonMappingException(TEST_MESSAGE);
+ Response response = defaultExceptionMapper.toResponse(exception);
+ assertEquals(response.getStatus(), 417);
+ }
+
+ @Test
+ public void shouldMapOtherExceptionToResponse() {
+ DefaultExceptionMapper defaultExceptionMapper = new DefaultExceptionMapper();
+ Exception exception = new Exception(TEST_MESSAGE);
+ Response response = defaultExceptionMapper.toResponse(exception);
+ assertEquals(response.getStatus(), 500);
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapperTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapperTest.java
new file mode 100644
index 0000000000..9c3c4b2e72
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapperTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.errors;
+
+import static org.junit.Assert.assertEquals;
+import static org.openecomp.sdcrests.errors.ZusammenExceptionMapper.FAILED_TO_PUBLISH_OUT_OF_SYNC;
+import static org.openecomp.sdcrests.errors.ZusammenExceptionMapper.FAILED_TO_SYNC;
+import static org.openecomp.sdcrests.errors.ZusammenExceptionMapper.SUB_ENTITY_ID_DOES_NOT_EXISTS;
+import static org.openecomp.sdcrests.errors.ZusammenExceptionMapper.VLM_VSP_ITEM_ID_DOES_NOT_EXISTS;
+
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
+import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.common.errors.SdcRuntimeException;
+
+public class ZusammenExceptionMapperTest {
+
+ @Test
+ public void shouldTransformENTITY_NOT_FOUND() {
+ ZusammenExceptionMapper zusammenExceptionMapper = new ZusammenExceptionMapper();
+ Response response = zusammenExceptionMapper
+ .toResponse(new SdcRuntimeException(VLM_VSP_ITEM_ID_DOES_NOT_EXISTS));
+ assertEquals(((ErrorCodeAndMessage)response.getEntity()).getErrorCode(), Messages.ENTITY_NOT_FOUND.name());
+ }
+
+ @Test
+ public void shouldTransformSUB_ENTITY_ID_DOES_NOT_EXISTS() {
+ ZusammenExceptionMapper zusammenExceptionMapper = new ZusammenExceptionMapper();
+ Response response = zusammenExceptionMapper
+ .toResponse(new SdcRuntimeException(SUB_ENTITY_ID_DOES_NOT_EXISTS));
+ assertEquals(((ErrorCodeAndMessage)response.getEntity()).getErrorCode(), Messages.SUB_ENTITY_NOT_FOUND.name());
+ }
+
+ @Test
+ public void shouldTransformFAILED_TO_SYNC() {
+ ZusammenExceptionMapper zusammenExceptionMapper = new ZusammenExceptionMapper();
+ Response response = zusammenExceptionMapper
+ .toResponse(new SdcRuntimeException(FAILED_TO_SYNC));
+ assertEquals(((ErrorCodeAndMessage)response.getEntity()).getErrorCode(), Messages.FAILED_TO_SYNC.name());
+ }
+
+ @Test
+ public void shouldTransformFAILED_TO_PUBLISH_OUT_OF_SYNC() {
+ ZusammenExceptionMapper zusammenExceptionMapper = new ZusammenExceptionMapper();
+ Response response = zusammenExceptionMapper
+ .toResponse(new SdcRuntimeException(FAILED_TO_PUBLISH_OUT_OF_SYNC));
+ assertEquals(((ErrorCodeAndMessage)response.getEntity()).getErrorCode(), Messages.FAILED_TO_PUBLISH_OUT_OF_SYNC.name());
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapperTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapperTest.java
new file mode 100644
index 0000000000..86d0257eeb
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapperTest.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.wrappers;
+
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class GenericCollectionWrapperTest {
+
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(GenericCollectionWrapper.class, hasValidGettersAndSetters());
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/StringWrapperResponseTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/StringWrapperResponseTest.java
new file mode 100644
index 0000000000..9b33434328
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/test/java/org/openecomp/sdcrests/wrappers/StringWrapperResponseTest.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.wrappers;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class StringWrapperResponseTest {
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(GenericCollectionWrapper.class, hasValidGettersAndSetters());
+ }
+} \ No newline at end of file