From e4f211d69d65a28b665eb307b89408208a536c8b Mon Sep 17 00:00:00 2001 From: talio Date: Tue, 14 May 2019 11:03:19 +0300 Subject: Fix test coverage Fix test coverage for ComponentInstanceInputPropertyDeclarator.java Change-Id: Ie52b56ce07ad8eaec47166311cd8e7942b153bd0 Issue-ID: SDC-2298 Signed-off-by: talio --- ...mponentInstanceInputPropertyDeclaratorTest.java | 78 ++++++++++++++++++---- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java index f5d4aabd92..258cad5ae9 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java @@ -1,6 +1,33 @@ +/* + * ============LICENSE_START============================================================================================================= + * Copyright (c) 2019 . + * =================================================================== + * 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. + * ============LICENSE_END=============================================================================================================== + * + */ package org.openecomp.sdc.be.components.property; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.be.MockGenerator.mockComponentUtils; +import static org.openecomp.sdc.be.MockGenerator.mockExceptionUtils; + import fj.data.Either; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -17,6 +44,7 @@ import org.openecomp.sdc.be.components.utils.ResourceBuilder; import org.openecomp.sdc.be.datatypes.elements.Annotation; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceInput; import org.openecomp.sdc.be.model.ComponentInstancePropInput; import org.openecomp.sdc.be.model.ComponentParametersView; @@ -27,18 +55,6 @@ import org.openecomp.sdc.be.model.operations.StorageException; 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.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import static org.openecomp.sdc.be.MockGenerator.mockComponentUtils; -import static org.openecomp.sdc.be.MockGenerator.mockExceptionUtils; - @RunWith(MockitoJUnitRunner.class) public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @@ -57,7 +73,9 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar @Captor private ArgumentCaptor inputsFilterCaptor; - private Annotation annotation1, annotation2; + private Annotation annotation1; + + private Annotation annotation2; @Override @Before @@ -101,6 +119,38 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar assertThatExceptionOfType(StorageException.class).isThrownBy(() -> testInstance.declarePropertiesAsInputs(resource, "inst1", propsToDeclare)); } + @Test + public void testCreateDeclaredProperty() { + ComponentInstanceInput declaredProperty = testInstance.createDeclaredProperty(prop1); + assertThat(declaredProperty.getUniqueId()).isEqualTo(prop1.getUniqueId()); + } + + @Test + public void testUpdateDeclaredProperties() { + List expectedProperties = Collections.singletonList(new ComponentInstanceInput(prop1)); + Map> expectedMap = new HashMap<>(); + expectedMap.put(prop1.getName(), expectedProperties); + + when(toscaOperationFacade.addComponentInstanceInputsToComponent(eq(resource), anyMap())) + .thenReturn(Either.left(expectedMap)); + + Either>, StorageOperationStatus> updateEither = + (Either>, StorageOperationStatus>) testInstance.updatePropertiesValues(resource, resource.getUniqueId(), expectedProperties); + + assertThat(updateEither.isLeft()); + Map> actualProperties = updateEither.left().value(); + assertThat(actualProperties.values().size()).isEqualTo(expectedProperties.size()); + assertThat(actualProperties.values().iterator().next()).isEqualTo(expectedProperties); + } + + @Test + public void testResolvePropertiesOwner() { + Optional componentInstance = testInstance.resolvePropertiesOwner(resource, INSTANCE_ID); + + assertThat(componentInstance.isPresent()); + assertThat(componentInstance.get().getUniqueId()).isEqualTo(INSTANCE_ID); + } + @Test public void unDeclarePropertiesAsListInputsTest() { InputDefinition inputToDelete = new InputDefinition(); @@ -182,4 +232,4 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar .addInput(input) .build(); } -} +} \ No newline at end of file -- cgit 1.2.3-korg