summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2020-09-04 15:27:00 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-07 13:28:22 +0000
commit3e9a9769dd21f0b16b3f238e42349cba3b1a78de (patch)
tree1517e5266d5b9ae8e5c386d06937eb503d59d431 /catalog-be/src/test
parent84a51513bca9c41c8757db017eb45b2d801da195 (diff)
Enable selection of requirements
Instead of all requirements of the component instances in a component being exposed outside the component, this change will enable the component designer to specifiy which should be exposed outside the component and which are to be internal to the component Change-Id: Ib063f7b8b0aca94896e78a46f069725bae3d494d Issue-ID: SDC-2771 Signed-off-by: MichaelMorris <michael.morris@est.tech> Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java30
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java35
2 files changed, 65 insertions, 0 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 d585c6f77a..12ffe1c193 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
@@ -1143,6 +1143,36 @@ class ComponentInstanceBusinessLogicTest {
componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
assertNotNull(result);
}
+
+ @Test
+ void testUpdateInstanceRequirement() {
+ ComponentInstanceBusinessLogic testSubject;
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
+ createComponents();
+ String userId = "userId";
+ resource.setLastUpdaterUserId(userId);
+ String containerComponentId = resource.getUniqueId();
+ String componentInstanceUniqueId = TO_INSTANCE_ID;
+ String capabilityType = "";
+ String capabilityName = "";
+ RequirementDefinition requirementDef = new RequirementDefinition();
+
+ Either<RequirementDefinition, ResponseFormat> result;
+
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
+ testSubject = createTestSubject();
+ when(toscaOperationFacade.updateComponentInstanceRequirement(containerComponentId, TO_INSTANCE_ID, requirementDef)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(resource)).thenReturn(Either.left(resource));
+ when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
+ .thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
+ .thenReturn(StorageOperationStatus.OK);
+
+ result = testSubject.updateInstanceRequirement(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, requirementDef, userId);
+ assertEquals(requirementDef, result.left().value());
+
+ }
@Test
void testCopyComponentInstanceWrongUserId() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java
index d801314c79..0eee7a1238 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java
@@ -39,6 +39,7 @@ import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import javax.ws.rs.Path;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -66,6 +67,7 @@ import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.user.UserBusinessLogic;
@@ -433,4 +435,37 @@ public class ComponentInstanceServletTest extends JerseyTest {
.header("USER_ID", USER_ID).post(Entity.entity(inputs, MediaType.APPLICATION_JSON));
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404);
}
+
+ @Test
+ public void testUpdateInstanceRequirement(){
+
+ String containerComponentType = "services";
+ String componentId = "componentId";
+ String componentInstanceId = "componentInstanceIdInstanceId";
+ String capabilityType = "capabilityType";
+ String requirementName = "requirementName";
+ RequirementDefinition requirementDefinition = new RequirementDefinition();
+ ObjectMapper mapper = new ObjectMapper();
+ String requirementJson = null;
+ try {
+ requirementJson = mapper.writeValueAsString(requirementDefinition);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/componentInstances/" +
+ componentInstanceId + "/requirement/" + capabilityType + "/requirementName/" + requirementName;
+ when(componentsUtils.convertJsonToObjectUsingObjectMapper(eq(requirementJson), any(User.class), eq(RequirementDefinition.class),
+ eq(AuditingActionEnum.GET_TOSCA_MODEL), eq(ComponentTypeEnum.SERVICE))).thenReturn(Either.left(requirementDefinition));
+ when(componentInstanceBusinessLogic.updateInstanceRequirement(ComponentTypeEnum.SERVICE,
+ componentId, componentInstanceId, capabilityType, requirementName, requirementDefinition, USER_ID))
+ .thenReturn(Either.left(requirementDefinition));
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
+ when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
+
+ Response response = target()
+ .path(path)
+ .request(MediaType.APPLICATION_JSON)
+ .header("USER_ID", USER_ID).put(Entity.entity(requirementDefinition, MediaType.APPLICATION_JSON));
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
+ }
}