From 8f9a8df44dc8d45abae56df406748aab0ef64729 Mon Sep 17 00:00:00 2001 From: talio Date: Tue, 14 May 2019 11:12:47 +0300 Subject: Fix test coverage Fix test coverage for ComponentInstancePropertyDeclarator.java Change-Id: I8c504990863147af421bc7e0333241d1a9bcc746 Issue-ID: SDC-2298 Signed-off-by: talio --- .../ComponentInstancePropertyDeclaratorTest.java | 107 ++++++++++++++++++--- 1 file changed, 91 insertions(+), 16 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java index deb634e232..0b44899ad9 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java @@ -1,37 +1,53 @@ package org.openecomp.sdc.be.components.property; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createCapabilityDefinition; +import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties; + import fj.data.Either; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.*; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.utils.InputsBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; +import org.openecomp.sdc.be.components.utils.ServiceBuilder; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstancePropInput; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; -import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createCapabilityDefinition; -import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties; - @RunWith(MockitoJUnitRunner.class) public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorTestBase { @@ -48,6 +64,11 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT @Captor private ArgumentCaptor>> instancePropertiesCaptor; + private static final String PROPERTY_ID = "propertyUid"; + private static final String PROEPRTY_NAME = "propertyName"; + private static final String SERVICE_ID = "serviceUid"; + private static final String SERVICE_NAME = "serviceName"; + @Test public void declarePropertiesAsInputs_componentInstanceNotExist() { Component cmpt = new Resource(); @@ -164,6 +185,60 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT verifyUpdatedComplexProperty(capturedInstanceProperties, inputs); } + @Test + public void testCreateDeclaredProperty() { + PropertyDefinition propertyDefinition = getPropertyForDeclaration(); + ComponentInstanceProperty declaredProperty = testInstance.createDeclaredProperty(propertyDefinition); + + assertThat(declaredProperty).isNotNull(); + assertThat(declaredProperty.getUniqueId()).isEqualTo(propertyDefinition.getUniqueId()); + } + + @Test + public void testUndeclareProperty() { + Service service = new ServiceBuilder() + .setUniqueId(SERVICE_ID) + .setName(SERVICE_NAME) + .build(); + + + + InputDefinition inputToDelete = InputsBuilder + .create() + .setPropertyId(PROPERTY_ID) + .setName(PROEPRTY_NAME) + .build(); + + inputToDelete.setGetInputValues(getGetInputListForDeclaration()); + + ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(getPropertyForDeclaration()); + List componentInstanceProperties = new ArrayList<>(); + componentInstanceProperties.add(componentInstanceProperty); + + when(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(any(), any())).thenReturn(new LinkedList<>()); + + StorageOperationStatus undeclareStatus = + testInstance.unDeclarePropertiesAsInputs(service, inputToDelete); + + assertThat(undeclareStatus).isEqualTo(StorageOperationStatus.OK); + } + + private List getGetInputListForDeclaration() { + GetInputValueDataDefinition getInput = new GetInputValueDataDefinition(); + getInput.setInputId(PROPERTY_ID); + getInput.setInputName(PROEPRTY_NAME); + getInput.setPropName(PROEPRTY_NAME); + List getInputList = new ArrayList<>(); + getInputList.add(getInput); + return getInputList; + } + + private PropertyDefinition getPropertyForDeclaration() { + return new PropertyDataDefinitionBuilder() + .setUniqueId(PROPERTY_ID) + .build(); + } + @Test public void declarePropertiesAsListInput() { // construct arguments @@ -257,7 +332,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); Assert.assertEquals(status, StorageOperationStatus.OK); } - + private void verifyUpdatedProperties(List properties, List capturedInstanceProperties, List inputs) { assertThat(capturedInstanceProperties).hasSize(properties.size()); Map updatedPropertiesByName = MapUtil.toMap(capturedInstanceProperties, ComponentInstanceProperty::getName); @@ -379,4 +454,4 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT .addInput(input) .build(); } -} +} \ No newline at end of file -- cgit 1.2.3-korg