summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java217
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceCapabilityServletTest.java240
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java1
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverterTest.java1
4 files changed, 457 insertions, 2 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index 07fff19f0b..5c8b6ce6d2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -23,10 +23,12 @@ package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anySet;
@@ -79,12 +81,12 @@ import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.exception.BusinessException;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
@@ -111,6 +113,7 @@ import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
@@ -201,7 +204,7 @@ class ComponentInstanceBusinessLogicTest {
@BeforeEach
void init() {
- MockitoAnnotations.initMocks(this);
+ MockitoAnnotations.openMocks(this);
stubMethods();
createComponents();
}
@@ -1950,6 +1953,216 @@ class ComponentInstanceBusinessLogicTest {
}
+ @Test
+ void updateInstanceCapabilitySuccessTest() {
+ var containerComponentId = "containerComponentId";
+ var componentInstanceUniqueId = "componentInstanceUniqueId";
+ var capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setUniqueId("uniqueId");
+
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setLastUpdaterUserId(USER_ID);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ var componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(componentInstanceUniqueId);
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.left(component));
+ when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
+ .thenReturn(capabilityDefinition);
+ when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+
+ final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID);
+ assertTrue(resultEither.isLeft());
+ final CapabilityDefinition actualCapabilityDefinition = resultEither.left().value();
+ assertNotEquals(capabilityDefinition, actualCapabilityDefinition);
+ assertEquals(capabilityDefinition.getUniqueId(), actualCapabilityDefinition.getUniqueId());
+ }
+
+ @Test
+ void updateInstanceCapabilityNoContainerComponentTypeTest() {
+ var responseFormat = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED)).thenReturn(responseFormat);
+ final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
+ .updateInstanceCapability(null, "containerComponentId", "componentInstanceUniqueId", new CapabilityDefinition(), USER_ID);
+ assertTrue(resultEither.isRight(), "Either return should be right");
+ final ResponseFormat actualResponseFormat = resultEither.right().value();
+ assertEquals(responseFormat, actualResponseFormat);
+ }
+
+ @Test
+ void updateInstanceCapabilityContainerComponentNotFoundTest() {
+ var containerComponentId = "containerComponentId";
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(null));
+ var responseFormat = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND, containerComponentId)).thenReturn(responseFormat);
+ final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, "containerComponentId", "componentInstanceUniqueId", new CapabilityDefinition(), USER_ID);
+ assertTrue(resultEither.isRight(), "Either return should be right");
+ final ResponseFormat actualResponseFormat = resultEither.right().value();
+ assertEquals(responseFormat, actualResponseFormat);
+ }
+
+ @Test
+ void updateInstanceCapabilityCannotWorkOnComponentTest() {
+ var containerComponentId = "containerComponentId";
+ var componentInstanceUniqueId = "componentInstanceUniqueId";
+
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setLastUpdaterUserId("anotherUse");
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ var expectedResponseFormat = new ResponseFormat();
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.left(component));
+ when(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION))
+ .thenReturn(expectedResponseFormat);
+
+ final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, new CapabilityDefinition(), USER_ID);
+ assertTrue(resultEither.isRight(), "Either return should be right");
+ final ResponseFormat actualResponseFormat = resultEither.right().value();
+ assertEquals(expectedResponseFormat, actualResponseFormat);
+ }
+
+ @Test
+ void updateInstanceCapabilityResourceInstanceNotFoundTest() {
+ var containerComponentId = "containerComponentId";
+ var componentInstanceUniqueId = "componentInstanceUniqueId";
+
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setLastUpdaterUserId(USER_ID);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ var expectedResponseFormat = new ResponseFormat();
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.left(component));
+ when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId))
+ .thenReturn(expectedResponseFormat);
+
+ final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, new CapabilityDefinition(), USER_ID);
+ assertTrue(resultEither.isRight(), "Either return should be right");
+ final ResponseFormat actualResponseFormat = resultEither.right().value();
+ assertEquals(expectedResponseFormat, actualResponseFormat);
+ }
+
+ @Test
+ void updateInstanceCapabilityUpdateMetadataFailTest() {
+ var containerComponentId = "containerComponentId";
+ var componentInstanceUniqueId = "componentInstanceUniqueId";
+ var capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setUniqueId("uniqueId");
+
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setLastUpdaterUserId(USER_ID);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ var componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(componentInstanceUniqueId);
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ var expectedResponseFormat = new ResponseFormat();
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
+ .thenReturn(capabilityDefinition);
+ when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR, ComponentTypeEnum.SERVICE))
+ .thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
+ .thenReturn(expectedResponseFormat);
+
+ final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID);
+ assertTrue(resultEither.isRight(), "Either return should be right");
+ final ResponseFormat actualResponseFormat = resultEither.right().value();
+ assertEquals(expectedResponseFormat, actualResponseFormat);
+ }
+
+ @Test
+ void updateInstanceCapabilityBusinessExceptionHandlingTest() {
+ var containerComponentId = "containerComponentId";
+ var componentInstanceUniqueId = "componentInstanceUniqueId";
+ var capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setUniqueId("uniqueId");
+
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setLastUpdaterUserId(USER_ID);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ var componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(componentInstanceUniqueId);
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
+ .thenThrow(new OperationException(ActionStatus.GENERAL_ERROR));
+
+ final BusinessException businessException = assertThrows(BusinessException.class, () -> {
+ componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID);
+ });
+ assertTrue(businessException instanceof OperationException);
+ assertEquals(ActionStatus.GENERAL_ERROR, ((OperationException) businessException).getActionStatus());
+ }
+
+ @Test
+ void updateInstanceCapabilityUnknownExceptionHandlingTest() {
+ var containerComponentId = "containerComponentId";
+ var componentInstanceUniqueId = "componentInstanceUniqueId";
+ var capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setUniqueId("uniqueId");
+
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setLastUpdaterUserId(USER_ID);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ var componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(componentInstanceUniqueId);
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ var expectedResponseFormat = new ResponseFormat();
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
+ .thenThrow(new RuntimeException());
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
+ .thenReturn(expectedResponseFormat);
+
+ final Exception exception = assertThrows(BusinessException.class, () ->
+ componentInstanceBusinessLogic
+ .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID));
+ assertTrue(exception instanceof ByResponseFormatComponentException);
+ final ByResponseFormatComponentException actualException = (ByResponseFormatComponentException) exception;
+ assertEquals(expectedResponseFormat, actualException.getResponseFormat());
+ }
+
private ComponentInstance createServiceSubstitutionComponentInstance() {
final ComponentInstance instanceToBeCreated = new ComponentInstance();
instanceToBeCreated.setName(COMPONENT_INSTANCE_NAME);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceCapabilityServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceCapabilityServletTest.java
new file mode 100644
index 0000000000..8155f22d65
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceCapabilityServletTest.java
@@ -0,0 +1,240 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import fj.data.Either;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.ErrorInfo;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
+import org.openecomp.sdc.be.servlets.builder.ServletResponseBuilder;
+import org.openecomp.sdc.be.servlets.exception.OperationExceptionMapper;
+import org.openecomp.sdc.be.ui.mapper.CapabilityMapper;
+import org.openecomp.sdc.be.ui.model.ComponentInstanceCapabilityUpdateModel;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.openecomp.sdc.exception.ServiceException;
+
+class ComponentInstanceCapabilityServletTest extends JerseySpringBaseTest {
+
+ private static final String UPDATE_INSTANCE_REQUIREMENT_PATH_FORMAT = "/v1/catalog/%s/%s/componentInstances/%s/capability";
+ private static ConfigurationManager configurationManager;
+
+ private final String componentId = "componentId";
+ private final String componentInstanceId = "componentInstanceId";
+ private final String userId = "userId";
+
+ private CapabilityMapper capabilityMapper;
+ private ComponentInstanceBusinessLogic componentInstanceBusinessLogicMock;
+
+ @Override
+ protected ResourceConfig configure() {
+ componentInstanceBusinessLogicMock = mock(ComponentInstanceBusinessLogic.class);
+ capabilityMapper = new CapabilityMapper();
+ var servletResponseBuilder = new ServletResponseBuilder();
+ var componentInstanceCapabilityServlet =
+ new ComponentInstanceCapabilityServlet(componentInstanceBusinessLogicMock, capabilityMapper, servletResponseBuilder);
+ return super.configure().register(componentInstanceCapabilityServlet)
+ .register(new OperationExceptionMapper(servletResponseBuilder));
+ }
+
+ @BeforeAll
+ static void beforeAll() {
+ setupConfiguration();
+ }
+
+ private static void setupConfiguration() {
+ final ConfigurationSource configurationSource =
+ new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
+ configurationManager = new ConfigurationManager(configurationSource);
+ }
+
+ //workaround for JerseyTest + Junit5
+ @BeforeEach
+ void beforeEach() throws Exception {
+ super.setUp();
+ }
+
+ //workaround for JerseyTest + Junit5
+ @AfterEach
+ void afterEach() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ void updateInstanceRequirementSuccessTest() throws JsonProcessingException {
+ final var updateModel = createDefaultUpdateMode();
+ var expectedCapabilityDefinition = capabilityMapper.mapToCapabilityDefinition(updateModel);
+
+ when(componentInstanceBusinessLogicMock
+ .updateInstanceCapability(eq(ComponentTypeEnum.SERVICE), eq(componentId), eq(componentInstanceId), any(CapabilityDefinition.class), eq(userId)))
+ .thenReturn(Either.left(expectedCapabilityDefinition));
+ final var url =
+ String.format(UPDATE_INSTANCE_REQUIREMENT_PATH_FORMAT, ComponentTypeEnum.SERVICE_PARAM_NAME, componentId, componentInstanceId);
+
+ final Response response = target()
+ .path(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, userId)
+ .put(Entity.entity(parseToJson(updateModel), MediaType.APPLICATION_JSON));
+ var actualCapabilityDefinition = response.readEntity(CapabilityDefinition.class);
+ assertEquals(200, response.getStatus(), "The update status should be as expected");
+ assertEquals(MediaType.valueOf(MediaType.APPLICATION_JSON), response.getMediaType(), "The content type should be application/json");
+ assertCapabilityDefinition(actualCapabilityDefinition, expectedCapabilityDefinition);
+ }
+
+ @Test
+ void updateInstanceRequirementFailTest() throws JsonProcessingException {
+ final var expectedResponseFormat = new ResponseFormat(404);
+ final var requestErrorWrapper = expectedResponseFormat.new RequestErrorWrapper();
+ final var serviceException = new ServiceException("anErrorCode", "anErrorText", new String[2]);
+ requestErrorWrapper.setServiceException(serviceException);
+ expectedResponseFormat.setRequestError(requestErrorWrapper);
+
+ when(componentInstanceBusinessLogicMock
+ .updateInstanceCapability(eq(ComponentTypeEnum.SERVICE), eq(componentId), eq(componentInstanceId), any(CapabilityDefinition.class), eq(userId)))
+ .thenReturn(Either.right(expectedResponseFormat));
+
+ final var url =
+ String.format(UPDATE_INSTANCE_REQUIREMENT_PATH_FORMAT, ComponentTypeEnum.SERVICE_PARAM_NAME, componentId, componentInstanceId);
+ final Response response = target()
+ .path(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, userId)
+ .put(Entity.entity(parseToJson(createDefaultUpdateMode()), MediaType.APPLICATION_JSON));
+ var actualResponseFormat = response.readEntity(ResponseFormat.class);
+
+ assertEquals(expectedResponseFormat.getStatus(), response.getStatus(), "The update status should be as expected");
+ assertNotNull(actualResponseFormat.getRequestError());
+ assertNotNull(actualResponseFormat.getRequestError().getRequestError());
+ assertEquals(expectedResponseFormat.getMessageId(), actualResponseFormat.getMessageId());
+ assertEquals(expectedResponseFormat.getVariables().length, actualResponseFormat.getVariables().length);
+ }
+
+ @Test
+ void updateInstanceRequirementKnownErrorTest() throws JsonProcessingException {
+ when(componentInstanceBusinessLogicMock
+ .updateInstanceCapability(eq(ComponentTypeEnum.SERVICE), eq(componentId), eq(componentInstanceId), any(CapabilityDefinition.class), eq(userId)))
+ .thenThrow(new OperationException(ActionStatus.COMPONENT_NOT_FOUND, componentId));
+ final var url =
+ String.format(UPDATE_INSTANCE_REQUIREMENT_PATH_FORMAT, ComponentTypeEnum.SERVICE_PARAM_NAME, componentId, componentInstanceId);
+ final Response response = target()
+ .path(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, userId)
+ .put(Entity.entity(parseToJson(createDefaultUpdateMode()), MediaType.APPLICATION_JSON));
+ var responseFormat = response.readEntity(ResponseFormat.class);
+
+ final ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(ActionStatus.COMPONENT_NOT_FOUND.name());
+ assertNotNull(errorInfo);
+ assertEquals(errorInfo.getCode(), response.getStatus(), "The update status should be as expected");
+ assertEquals(errorInfo.getMessageId(), responseFormat.getMessageId());
+ assertEquals(errorInfo.getMessage(), responseFormat.getText());
+ }
+
+ @Test
+ void updateInstanceRequirementUnknownErrorTest() throws JsonProcessingException {
+ when(componentInstanceBusinessLogicMock
+ .updateInstanceCapability(eq(ComponentTypeEnum.SERVICE), eq(componentId), eq(componentInstanceId), any(CapabilityDefinition.class), eq(userId)))
+ .thenThrow(new RuntimeException());
+ final var url =
+ String.format(UPDATE_INSTANCE_REQUIREMENT_PATH_FORMAT, ComponentTypeEnum.SERVICE_PARAM_NAME, componentId, componentInstanceId);
+ final Response response = target()
+ .path(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, userId)
+ .put(Entity.entity(parseToJson(createDefaultUpdateMode()), MediaType.APPLICATION_JSON));
+ var responseFormat = response.readEntity(ResponseFormat.class);
+
+ final ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(ActionStatus.GENERAL_ERROR.name());
+ assertNotNull(errorInfo);
+ assertEquals(errorInfo.getCode(), response.getStatus(), "The update status should be as expected");
+ assertEquals(errorInfo.getMessageId(), responseFormat.getMessageId());
+ assertEquals(errorInfo.getMessage(), responseFormat.getText());
+ }
+
+ @Test
+ void updateInstanceRequirementIncorrectComponentTypeTest() throws JsonProcessingException {
+ final var url =
+ String.format(UPDATE_INSTANCE_REQUIREMENT_PATH_FORMAT, "wrongType", componentId, componentInstanceId);
+ final Response response = target()
+ .path(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, userId)
+ .put(Entity.entity(parseToJson(createDefaultUpdateMode()), MediaType.APPLICATION_JSON));
+ var responseFormat = response.readEntity(ResponseFormat.class);
+
+ final ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(ActionStatus.UNSUPPORTED_ERROR.name());
+ assertNotNull(errorInfo);
+ assertEquals(errorInfo.getCode(), response.getStatus(), "The update status should be as expected");
+ assertEquals(errorInfo.getMessageId(), responseFormat.getMessageId());
+ assertEquals(errorInfo.getMessage(), responseFormat.getText());
+ }
+
+ private ComponentInstanceCapabilityUpdateModel createDefaultUpdateMode() {
+ var capabilityUpdateModel = new ComponentInstanceCapabilityUpdateModel();
+ capabilityUpdateModel.setName("name");
+ capabilityUpdateModel.setExternal(true);
+ capabilityUpdateModel.setOwnerId("ownerId");
+ capabilityUpdateModel.setType("type");
+ capabilityUpdateModel.setOwnerName("ownerName");
+ capabilityUpdateModel.setUniqueId("uniqueId");
+ return capabilityUpdateModel;
+ }
+
+ private void assertCapabilityDefinition(final CapabilityDefinition actualCapabilityDefinition,
+ final CapabilityDefinition expectedCapabilityDefinition) {
+ assertEquals(expectedCapabilityDefinition.getUniqueId(), actualCapabilityDefinition.getUniqueId());
+ assertEquals(expectedCapabilityDefinition.getName(), actualCapabilityDefinition.getName());
+ assertEquals(expectedCapabilityDefinition.getOwnerId(), actualCapabilityDefinition.getOwnerId());
+ assertEquals(expectedCapabilityDefinition.getOwnerName(), actualCapabilityDefinition.getOwnerName());
+ assertEquals(expectedCapabilityDefinition.getType(), actualCapabilityDefinition.getType());
+ assertEquals(expectedCapabilityDefinition.isExternal(), actualCapabilityDefinition.isExternal());
+ }
+
+ private <T> String parseToJson(final T object) throws JsonProcessingException {
+ return new ObjectMapper().writeValueAsString(object);
+ }
+
+}
+
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
index e755de12f0..7fda4edd4f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
@@ -77,6 +77,7 @@ public abstract class JerseySpringBaseTest extends JerseyTest {
.register(jacksonJsonProvider);
}
+ @Override
protected ResourceConfig configure() {
forceSet(TestProperties.CONTAINER_PORT, "0");
return configure(BaseTestConfig.class);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverterTest.java
index 49920c3c45..5f1b62d1d4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverterTest.java
@@ -307,6 +307,7 @@ public class CapabilityRequirementConverterTest {
CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
capabilityDefinition.setName(capabilityName);
capabilityDefinition.setType("att.Node");
+ capabilityDefinition.setExternal(true);
List<ComponentInstanceProperty> properties = new ArrayList<>();
ComponentInstanceProperty prop = new ComponentInstanceProperty();
prop.setName(PROPERTY_NAME);