summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2019-05-14 11:58:24 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-05-14 10:01:24 +0000
commitcf356e391528149cb5d133d19fbcdda5b3dace2a (patch)
tree7fc7a5648ea4a8c4560fc1dc130244e61b96449c
parentbbf9b3e999e6901ef08f3c519eadad59ae492de4 (diff)
Fix test coverage
Fix test coverage for PropertyDeclarationOrchestrator.java Change-Id: Iecf25e2e2d6410a3adc9f8edd6c234c1c0989c33 Issue-ID: SDC-2298 Signed-off-by: talio <tali.orenbach@amdocs.com>
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java108
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestratorTest.java249
2 files changed, 249 insertions, 108 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
deleted file mode 100644
index 1a2a76e433..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.openecomp.sdc.be.components.property;
-
-import fj.data.Either;
-import mockit.Deencapsulation;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-
-import java.util.*;
-
-public class PropertyDecelerationOrchestratorTest {
-
- @InjectMocks
- PropertyDeclarationOrchestrator testSubject;
-
- @Mock
- List<PropertyDeclarator> propertyDeceleratorsMock;
-
- @Mock
- private ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDecelerator;
- @Mock
- private ComponentInstancePropertyDeclarator componentInstancePropertyDecelerator;
- @Mock
- private PolicyPropertyDeclarator policyPropertyDecelerator;
-
- @Before
- public void setUp() throws Exception {
-
- MockitoAnnotations.initMocks(this);
- }
-
- @Test(expected = IllegalStateException.class)
- public void testDeclarePropertiesToInputs() throws Exception {
- Component component = new Resource();
- ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
- Either<List<InputDefinition>, StorageOperationStatus> result;
-
- // default test
- result = testSubject.declarePropertiesToInputs(component, componentInstInputsMap);
- }
-
- @Test
- public void testUnDeclarePropertiesAsInputs() throws Exception {
- Component component = new Resource();
- InputDefinition inputToDelete = new InputDefinition();
- StorageOperationStatus result;
-
- Iterator<PropertyDeclarator> mockIter = Mockito.mock(Iterator.class);
- Mockito.when(propertyDeceleratorsMock.iterator()).thenReturn(mockIter);
- Mockito.when(mockIter.hasNext()).thenReturn(false);
-
- // default test
- result = testSubject.unDeclarePropertiesAsInputs(component, inputToDelete);
- }
-
- @Test(expected = IllegalStateException.class)
- public void testGetPropertyDecelerator() throws Exception {
- ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
- PropertyDeclarator result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
- }
-
- @Test
- public void testGetPropertyDeceleratorWithInputsMap() throws Exception {
- ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
- Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap = new HashMap<>();
- List<ComponentInstancePropInput> value = new LinkedList<>();
- componentInstanceInputsMap.put("mock", value);
- componentInstInputsMap.setComponentInstanceInputsMap(componentInstanceInputsMap);
- PropertyDeclarator result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
- }
-
- @Test
- public void testGetPropertyDeceleratorWithCIProperties() throws Exception {
- ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
- Map<String, List<ComponentInstancePropInput>> componentInstanceProperties = new HashMap<>();
- List<ComponentInstancePropInput> value = new LinkedList<>();
- componentInstanceProperties.put("mock", value);
- componentInstInputsMap.setComponentInstanceProperties(componentInstanceProperties);
- PropertyDeclarator result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
- }
-
- @Test
- public void testGetPropertyDeceleratorWithCIPolicy() throws Exception {
- ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
- Map<String, List<ComponentInstancePropInput>> policyProperties = new HashMap<>();
- List<ComponentInstancePropInput> value = new LinkedList<>();
- policyProperties.put("mock", value);
- componentInstInputsMap.setPolicyProperties(policyProperties);
- PropertyDeclarator result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
- }
-}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestratorTest.java
new file mode 100644
index 0000000000..9c70159c53
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestratorTest.java
@@ -0,0 +1,249 @@
+/*
+ * ============LICENSE_START=============================================================================================================
+ * Copyright (c) 2019 <Company or Individual>.
+ * ===================================================================
+ * 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import mockit.Deencapsulation;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentInstancePropertyToPolicyDeclarator;
+import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator;
+import org.openecomp.sdc.be.components.utils.ServiceBuilder;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class PropertyDeclarationOrchestratorTest {
+
+ @InjectMocks
+ PropertyDeclarationOrchestrator testSubject;
+
+ @Mock
+ List<PropertyDeclarator> propertyDeceleratorsToInput;
+
+ @Mock
+ private ComponentInstancePropertyToPolicyDeclarator componentInstancePropertyToPolicyDeclarator;
+
+ @Mock
+ private ComponentPropertyToPolicyDeclarator componentPropertyToPolicyDeclarator;
+
+ @Mock
+ private ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDecelerator;
+
+ @Mock
+ private ComponentInstancePropertyDeclarator componentInstancePropertyDecelerator;
+
+ @Mock
+ private ComponentPropertyDeclarator servicePropertyDeclarator;
+
+ @Mock
+ private PolicyPropertyDeclarator policyPropertyDecelerator;
+
+ @Mock
+ private GroupPropertyDeclarator groupPropertyDeclarator;;
+
+ private static final String PROP_UID = "propertyUid";
+ private static final String SERVICE_UID = "serviceUid";
+
+ private Service service;
+
+ @Before
+ public void setUp() throws Exception {
+
+ MockitoAnnotations.initMocks(this);
+
+ service = new ServiceBuilder().setUniqueId(SERVICE_UID).build();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testDeclarePropertiesToInputs() throws Exception {
+ Component component = new Resource();
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Either<List<InputDefinition>, StorageOperationStatus> result;
+
+ // default test
+ result = testSubject.declarePropertiesToInputs(component, componentInstInputsMap);
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsInputs() throws Exception {
+ Component component = new Resource();
+ InputDefinition inputToDelete = new InputDefinition();
+ StorageOperationStatus result;
+
+ Iterator<PropertyDeclarator> mockIter = Mockito.mock(Iterator.class);
+ when(propertyDeceleratorsToInput.iterator()).thenReturn(mockIter);
+ when(mockIter.hasNext()).thenReturn(false);
+
+ setInputUndeclarationStubbings(component, inputToDelete);
+
+ // default test
+ result = testSubject.unDeclarePropertiesAsInputs(component, inputToDelete);
+
+ assertEquals(StorageOperationStatus.OK, result);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testGetPropertyDecelerator() throws Exception {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ PropertyDeclarator result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
+ }
+
+ @Test
+ public void testGetPropertyDeceleratorWithInputsMap() throws Exception {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap = getPropertiesMapToDeclare();
+ componentInstInputsMap.setComponentInstanceInputsMap(componentInstanceInputsMap);
+ PropertyDeclarator result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
+
+ assertTrue(result instanceof ComponentInstanceInputPropertyDeclarator);
+ }
+
+ @Test
+ public void testGetPropertyDeceleratorWithCIProperties() throws Exception {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> componentInstanceProperties = new HashMap<>();
+ List<ComponentInstancePropInput> value = new LinkedList<>();
+ componentInstanceProperties.put("mock", value);
+ componentInstInputsMap.setComponentInstanceProperties(componentInstanceProperties);
+ PropertyDeclarator result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
+
+ assertTrue(result instanceof ComponentInstancePropertyDeclarator);
+ }
+
+ @Test
+ public void testGetPropertyDeceleratorWithCIPolicy() throws Exception {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> policyProperties = getPropertiesMapToDeclare();
+ componentInstInputsMap.setPolicyProperties(policyProperties);
+ PropertyDeclarator result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
+
+ assertTrue(result instanceof PolicyPropertyDeclarator);
+ }
+
+ @Test
+ public void testDeclarePropertiesToPolicies() {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> policyProperties = getPropertiesMapToDeclare();
+ componentInstInputsMap.setComponentInstancePropertiesToPolicies(policyProperties);
+
+ PolicyDefinition declaredPolicy = getDeclaredPolicy();
+
+ when(componentInstancePropertyToPolicyDeclarator.declarePropertiesAsPolicies(any(), anyString(), anyList())).thenReturn(
+ Either.left(Collections.singletonList(declaredPolicy)));
+
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither =
+ testSubject.declarePropertiesToPolicies(service, componentInstInputsMap);
+
+ validatePolicyDeclaration(declaredPolicy, declareEither);
+ }
+
+ @Test
+ public void testUndeclarePropertiesAsPolicies() {
+ when(componentInstancePropertyToPolicyDeclarator.unDeclarePropertiesAsPolicies(any(), any(PolicyDefinition.class))).thenReturn(StorageOperationStatus.OK);
+ when(componentPropertyToPolicyDeclarator.unDeclarePropertiesAsPolicies(any(), any(PolicyDefinition.class))).thenReturn(StorageOperationStatus.OK);
+
+ StorageOperationStatus undeclareStatus =
+ testSubject.unDeclarePropertiesAsPolicies(service, getDeclaredPolicy());
+
+ assertEquals(StorageOperationStatus.OK, undeclareStatus);
+ }
+
+ @Test
+ public void testDeclareServiceProperties() {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> serviceProperties = getPropertiesMapToDeclare();
+ componentInstInputsMap.setServiceProperties(serviceProperties);
+
+ PolicyDefinition declaredPolicy = getDeclaredPolicy();
+
+ when(servicePropertyDeclarator.declarePropertiesAsPolicies(any(), anyString(), anyList())).thenReturn(
+ Either.left(Collections.singletonList(declaredPolicy)));
+
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither =
+ testSubject.declarePropertiesToPolicies(service, componentInstInputsMap);
+
+ validatePolicyDeclaration(declaredPolicy, declareEither);
+ }
+
+ private PolicyDefinition getDeclaredPolicy() {
+ PolicyDefinition declaredPolicy = new PolicyDefinition();
+ declaredPolicy.setUniqueId(PROP_UID);
+ return declaredPolicy;
+ }
+
+ private Map<String, List<ComponentInstancePropInput>> getPropertiesMapToDeclare() {
+ Map<String, List<ComponentInstancePropInput>> policyProperties = new HashMap<>();
+
+ ComponentInstancePropInput propertyToDeclare = new ComponentInstancePropInput();
+ propertyToDeclare.setUniqueId(PROP_UID);
+ propertyToDeclare.setPropertiesName(PROP_UID);
+
+ policyProperties.put("mock", Collections.singletonList(propertyToDeclare));
+ return policyProperties;
+ }
+
+ private void validatePolicyDeclaration(PolicyDefinition declaredPolicy,
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither) {
+ assertTrue(declareEither.isLeft());
+
+ List<PolicyDefinition> declaredPolicies = declareEither.left().value();
+ assertEquals(1, declaredPolicies.size());
+ assertEquals(declaredPolicy.getUniqueId(), declaredPolicies.get(0).getUniqueId());
+ }
+
+ private void setInputUndeclarationStubbings(Component component, InputDefinition inputToDelete) {
+ when(policyPropertyDecelerator.unDeclarePropertiesAsInputs(eq(component), eq(inputToDelete))).thenReturn(
+ StorageOperationStatus.OK);
+ when(servicePropertyDeclarator.unDeclarePropertiesAsInputs(eq(component), eq(inputToDelete))).thenReturn(StorageOperationStatus.OK);
+ when(componentInstancePropertyDecelerator.unDeclarePropertiesAsInputs(eq(component), eq(inputToDelete))).thenReturn(StorageOperationStatus.OK);
+ when(componentInstanceInputPropertyDecelerator.unDeclarePropertiesAsInputs(eq(component), eq(inputToDelete))).thenReturn(StorageOperationStatus.OK);
+ when(groupPropertyDeclarator.unDeclarePropertiesAsInputs(eq(component), eq(inputToDelete))).thenReturn(StorageOperationStatus.OK);
+ }
+}