From 80276b1b3ca9b832bfa0fd30b73af45ffaffef9c Mon Sep 17 00:00:00 2001 From: talio Date: Tue, 14 May 2019 11:03:19 +0300 Subject: [PATCH] Fix test coverage Fix test coverage for ComponentInstanceInputPropertyDeclarator.java Change-Id: Ie7125bb8107031db1362ba6a616fc4150bf99fca Issue-ID: SDC-2298 Signed-off-by: talio --- ...mponentInstanceInputPropertyDeclaratorTest.java | 75 ++++++++++++++++++---- 1 file changed, 63 insertions(+), 12 deletions(-) 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 acfa721e74..63c272fddf 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,32 @@ +/* + * ============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.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -14,6 +40,8 @@ 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; import org.openecomp.sdc.be.model.InputDefinition; @@ -21,17 +49,6 @@ import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -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 { @@ -44,7 +61,9 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar @Captor private ArgumentCaptor inputsFilterCaptor; - private Annotation annotation1, annotation2; + private Annotation annotation1; + + private Annotation annotation2; @Override @Before @@ -88,6 +107,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); + } + private void verifyInputAnnotations(InputDefinition inputDefinition) { List annotations = inputDefinition.getAnnotations(); assertThat(annotations) -- 2.16.6