summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java98
1 files changed, 86 insertions, 12 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java
index 7069fe84d7..b432502996 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java
@@ -17,33 +17,43 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.property;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import org.apache.commons.collections.CollectionUtils;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.utils.InputsBuilder;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ServiceBuilder;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.Component;
+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.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 java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
-
@RunWith(MockitoJUnitRunner.class)
public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase {
@@ -56,6 +66,15 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase
@Mock
private ToscaOperationFacade toscaOperationFacade;
+ private static final String PROPERTY_UID = "propertyUid";
+ private static final String SERVICE_UID = "serviceUid";
+ private Service service;
+
+ @Before
+ public void init() {
+ service = new ServiceBuilder().setUniqueId(SERVICE_UID).build();
+ }
+
@Test
public void unDeclarePropertiesAsListInputsTest_whenPropertyUsedByOperation() {
InputDefinition input = new InputDefinition();
@@ -164,6 +183,62 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase
Assert.assertEquals(status, StorageOperationStatus.NOT_FOUND);
}
+
+ @Test
+ public void createDeclaredProperty_success() {
+ PropertyDataDefinition propertyDataDefinition = getPropertyForDeclaration();
+ PropertyDataDefinition declaredProperty = testInstance.createDeclaredProperty(propertyDataDefinition);
+
+ assertTrue(Objects.nonNull(declaredProperty));
+ assertEquals(propertyDataDefinition.getUniqueId(), declaredProperty.getUniqueId());
+ }
+
+ @Test
+ public void updatePropertiesValues_success() {
+ PropertyDataDefinition propertyForDeclaration = getPropertyForDeclaration();
+ when(toscaOperationFacade.updatePropertyOfComponent(any(Component.class), any(PropertyDefinition.class)))
+ .thenReturn(Either.left(new PropertyDefinition(propertyForDeclaration)));
+
+ Either<List<PropertyDataDefinition>, StorageOperationStatus> updateEither =
+ (Either<List<PropertyDataDefinition>, StorageOperationStatus>) testInstance
+ .updatePropertiesValues(service,
+ SERVICE_UID, Collections
+ .singletonList(
+ propertyForDeclaration));
+
+ assertTrue(updateEither.isLeft());
+
+ List<PropertyDataDefinition> properties = updateEither.left().value();
+ assertTrue(CollectionUtils.isNotEmpty(properties));
+ assertEquals(1, properties.size());
+ assertEquals(propertyForDeclaration, properties.get(0));
+ }
+
+ @Test
+ public void resolvePropertiesOwner_success() {
+ Optional<Component> ownerCandidate = testInstance.resolvePropertiesOwner(service, SERVICE_UID);
+
+ assertTrue(ownerCandidate.isPresent());
+ assertEquals(service, ownerCandidate.get());
+ }
+
+ @Test
+ public void addPropertiesListToInput_success() {
+ InputDefinition input = InputsBuilder.create().setPropertyId(PROPERTY_UID).build();
+ PropertyDataDefinition propertyForDeclaration = getPropertyForDeclaration();
+
+ testInstance.addPropertiesListToInput(propertyForDeclaration, input);
+
+ List<ComponentInstanceProperty> inputProperties = input.getProperties();
+ assertTrue(CollectionUtils.isNotEmpty(inputProperties));
+ assertEquals(1, inputProperties.size());
+ assertEquals(propertyForDeclaration.getUniqueId(), inputProperties.get(0).getUniqueId());
+ }
+
+ private PropertyDataDefinition getPropertyForDeclaration() {
+ return new PropertyDataDefinitionBuilder().setUniqueId(PROPERTY_UID).build();
+ }
+
private GetInputValueDataDefinition buildGetInputValue(String InputId) {
GetInputValueDataDefinition getInputValue = new GetInputValueDataDefinition();
getInputValue.setInputId(InputId);
@@ -171,5 +246,4 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase
return getInputValue;
}
-
-}
+} \ No newline at end of file