aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-09-01 13:29:56 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-07 13:57:24 +0000
commitcda67b6e9d477cad22de6d4ef5834e61c83db0a9 (patch)
tree6d7976fa363415ab5e74bfc6690eb3405b1fd9fd /catalog-be
parent3e9a9769dd21f0b16b3f238e42349cba3b1a78de (diff)
Add and change node_filter unit testes
Issue-ID: SDC-3272 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I29ff07fa5e4d4cec1379018d417e35a156e7aa2f
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java33
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java58
2 files changed, 86 insertions, 5 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
index 7c81807777..5867c4d199 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -457,6 +458,38 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
+ public void updateNodeFilterTest() throws BusinessLogicException {
+ componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
+
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId,
+ Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
+ when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
+ .thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
+ .thenReturn(StorageOperationStatus.OK);
+
+ when(nodeFilterOperation.updateCapabilities(anyString(), anyString(),
+ any(CINodeFilterDataDefinition.class), anyList())).thenReturn(Either.left(ciNodeFilterDataDefinition));
+
+ final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
+ final Optional<CINodeFilterDataDefinition> updateNodeFilterResult = componentNodeFilterBusinessLogic
+ .updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES);
+
+ assertThat(updateNodeFilterResult).isPresent();
+ assertThat(updateNodeFilterResult.get().getProperties().getListToscaDataDefinition()).hasSize(1);
+
+ verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
+ verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
+ verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
+ constraints, NodeFilterConstraintAction.UPDATE);
+ verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
+ verify(nodeFilterOperation, times(1))
+ .updateCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class), anyList());
+ }
+
+ @Test
public void updateNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
index 947a702db0..a745f41ec0 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
@@ -70,6 +70,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
@@ -113,7 +114,6 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
private static UserValidations userValidations;
private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
- private RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
private UIConstraint uiConstraint;
private String constraint;
private String inputJson;
@@ -309,7 +309,7 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
}
@Test
- public void updateNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
+ public void updateNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
initComponentData();
final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, componentInstance,
@@ -344,6 +344,44 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
}
@Test
+ public void updateNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
+ initComponentData();
+ final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, componentInstance,
+ NodeFilterConstraintType.CAPABILITIES_PARAM_NAME);
+
+ when(userValidations.validateUserExists(user)).thenReturn(user);
+ when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
+
+ when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
+
+ when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
+ .thenReturn(Collections.singletonList(uiConstraint));
+
+ when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
+ ArgumentMatchers.<Class<List>>any(),
+ nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
+ .thenReturn(Either.left(Arrays.asList(new ObjectMapper().convertValue(uiConstraint, Map.class))));
+
+ when(componentNodeFilterBusinessLogic
+ .updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
+ true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.CAPABILITIES))
+ .thenReturn(Optional.of(ciNodeFilterDataDefinition));
+ final Response response = target()
+ .path(path)
+ .request(MediaType.APPLICATION_JSON)
+ .header(USER_ID_HEADER, USER_ID)
+ .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
+
+ verify(componentNodeFilterBusinessLogic, times(1))
+ .updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
+ ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class));
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
+ }
+
+ @Test
public void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
initComponentData();
final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
@@ -514,15 +552,25 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
constraint = new ConstraintConvertor().convert(uiConstraint);
inputJson = buildConstraintDataJson(uiConstraint);
- requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
+ final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition =
+ new RequirementNodeFilterPropertyDataDefinition();
requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
+ final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionList =
new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
+ final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
+ new RequirementNodeFilterCapabilityDataDefinition();
+ requirementNodeFilterCapabilityDataDefinition.setName(uiConstraint.getServicePropertyName());
+ requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
+
+ final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilityDataDefinitionList =
+ new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterCapabilityDataDefinition)));
+
ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
- ciNodeFilterDataDefinition.setProperties(listDataDefinition);
+ ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList);
+ ciNodeFilterDataDefinition.setCapabilities(capabilityDataDefinitionList);
ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
user = new User();