diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test')
5 files changed, 97 insertions, 67 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ComponentQuestionnaireHealerTest.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ComponentQuestionnaireHealerTest.java index 69f4287cd1..688d1d4236 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ComponentQuestionnaireHealerTest.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ComponentQuestionnaireHealerTest.java @@ -8,7 +8,6 @@ import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; @@ -20,10 +19,7 @@ import org.openecomp.sdc.versioning.dao.types.Version; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.doNothing; @@ -47,7 +43,6 @@ public class ComponentQuestionnaireHealerTest { private static final String DUMMY_COMPONENT_ID = "2495ef442f964cbfb00d82bd54292f89"; private static final String DUMMY_COMPUTE_ID = "3495ef442f964cbfb00d82bd54292f89"; private static final String DUMMY_IMAGE_ID = "4495ef442f964cbfb00d82bd54292f89"; - private static Map<String, Object> healingParams = new HashMap<>(); private static final String componentQuestionnaireData = "{\"compute\": {" + "\"guestOS\": {\"bitSize\": 64},\"vmSizing\": {\"IOOperationsPerSec\": \"0\"}," + "\"numOfVMs\": {\"CpuOverSubscriptionRatio\": \"1:1\",\"MemoryRAM\": \"2 GB\"}}," + @@ -131,16 +126,13 @@ public class ComponentQuestionnaireHealerTest { @Before public void init() throws Exception { MockitoAnnotations.initMocks(ComponentQuestionnaireHealerTest.this); - - healingParams.put(SdcCommon.VSP_ID, DUMMY_VSP_ID); - healingParams.put(SdcCommon.VERSION, VERSION); } @Test public void healQuestionnaireNullTest() throws Exception { prepareHealingData(); componentEntity.setQuestionnaireData(null); - Object returnObject = componentQuestionnaireHealer.heal(healingParams); + Object returnObject = componentQuestionnaireHealer.heal(DUMMY_VSP_ID, VERSION); Assert.assertTrue(returnObject instanceof Collection); Collection<ComponentEntity> componentEntities = (Collection<ComponentEntity>) returnObject; componentEntities.forEach(componentEntity -> { @@ -152,7 +144,7 @@ public class ComponentQuestionnaireHealerTest { public void healAllCasesTest() throws Exception { prepareHealingData(); - Object returnObject = componentQuestionnaireHealer.heal(healingParams); + Object returnObject = componentQuestionnaireHealer.heal(DUMMY_VSP_ID, VERSION); Assert.assertTrue(returnObject instanceof Collection); Collection<ComponentEntity> componentEntities = (Collection<ComponentEntity>) returnObject; componentEntities.forEach(componentEntity -> { @@ -177,7 +169,7 @@ public class ComponentQuestionnaireHealerTest { public void healDiskAttrMissingTest() throws Exception { prepareHealingData(); componentEntity.setQuestionnaireData(componentQuestionnaireMissingDiskAttrData); - Object returnObject = componentQuestionnaireHealer.heal(healingParams); + Object returnObject = componentQuestionnaireHealer.heal(DUMMY_VSP_ID, VERSION); Assert.assertTrue(returnObject instanceof Collection); Collection<ComponentEntity> componentEntities = (Collection<ComponentEntity>) returnObject; componentEntities.forEach(componentEntity -> { @@ -238,7 +230,7 @@ public class ComponentQuestionnaireHealerTest { .getDeclaredMethod(methodName, JsonObject.class, JsonObject.class); method.setAccessible(true); - method.invoke(componentQuestionnaireHealer,jsonObject.getAsJsonObject(COMPUTE), null); + method.invoke(componentQuestionnaireHealer, jsonObject.getAsJsonObject(COMPUTE), null); } private void prepareHealingData() { diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ForwarderCapabilityHealerTest.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ForwarderCapabilityHealerTest.java index 406d039178..a07ace683f 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ForwarderCapabilityHealerTest.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ForwarderCapabilityHealerTest.java @@ -13,7 +13,6 @@ import org.mockito.MockitoAnnotations; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.sdc.common.togglz.ToggleableFeature; -import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.healing.healers.util.TestUtil; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -32,13 +31,14 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.eq; public class ForwarderCapabilityHealerTest { + private static final String vspId = "1"; + private static final Version version = new Version(1, 1); private static final String IN_SUFFIX = "/in"; private static final String OUT_SUFFIX = "/out"; private static final String BASE_DIRECTORY = "/mock/healers/forwarder"; private static final String ENTRY_DEFINITION_SERVICE_TEMPLATE = "MainServiceTemplate.yaml"; private static TestFeatureManager manager; - private Map<String,Object> params = new HashMap<>(); @Mock private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao; @@ -65,8 +65,6 @@ public class ForwarderCapabilityHealerTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(ForwarderCapabilityHealerTest.this); - params.put(SdcCommon.VSP_ID,"1"); - params.put(SdcCommon.VERSION, new Version(1,1)); } @@ -127,7 +125,7 @@ public class ForwarderCapabilityHealerTest { private void validateServiceModelAfterHealing(String testDirectory) throws Exception { Optional<ToscaServiceModel> serviceModelObject = - (Optional<ToscaServiceModel>) forwarderCapabilityHealer.heal(params); + (Optional<ToscaServiceModel>) forwarderCapabilityHealer.heal(vspId, version); Assert.assertTrue(serviceModelObject.isPresent()); TestUtil diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java index b732cb03b6..5584a5fe77 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java @@ -2,69 +2,77 @@ package org.openecomp.sdc.healing.healers; 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.common.utils.SdcCommon; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.HashMap; -import java.util.Map; - import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; -public class VspOnboardingMethodHealerTest{ +public class VspOnboardingMethodHealerTest { + private static final String vspId = "1"; + private static final Version version = new Version(1, 1); + + @Mock + private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDao; + @Mock + private OrchestrationTemplateCandidateDao candidateDao; + @InjectMocks + private VspOnboardingMethodHealer vspOnboardingMethodHealer; + + private OrchestrationTemplateEntity orchestrationTemplateEntity = new OrchestrationTemplateEntity(); + private OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); + private static final String NETWORK_PACKAGE = "NetworkPackage"; + private static final String HEAT = "HEAT"; + private static final String MANUAL = "Manual"; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(VspOnboardingMethodHealerTest.this); + } + + @Test + public void checkHealingWithNullOnboarding() throws Exception { + VspDetails vspDetails = initAndExecuteHealer(null); + assertEquals(vspDetails.getOnboardingMethod(), NETWORK_PACKAGE); + } - @Mock - private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao; + @Test + public void checkHealingWithHEATOnboarding() throws Exception { + VspDetails vspDetails = initAndExecuteHealer(HEAT); + assertEquals(vspDetails.getOnboardingMethod(), NETWORK_PACKAGE); + } - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(VspOnboardingMethodHealerTest.this); - } + @Test + public void checkHealingWithManualOnboarding() throws Exception { + VspDetails vspDetails = initAndExecuteHealer(MANUAL); + assertEquals(vspDetails.getOnboardingMethod(), MANUAL); + } - @Test - public void checkHealingWithNullOnboarding() throws Exception{ - VspOnboardingMethodHealer vspOnboardingMethodHealer = new VspOnboardingMethodHealer(vendorSoftwareProductInfoDao); - Map<String,Object> params = new HashMap<>(); - params.put(SdcCommon.VSP_ID,"1"); - params.put(SdcCommon.VERSION, new Version(1,1)); - VspDetails vspDetails = new VspDetails(); - vspDetails.setOnboardingMethod(null); - Mockito.when(vendorSoftwareProductInfoDao.get(any())).thenReturn(vspDetails); - vspOnboardingMethodHealer.heal(params); - assertEquals(vspDetails.getOnboardingMethod(),"NetworkPackage"); - assertEquals(vspDetails.getOnboardingOrigin(),"zip"); - } + private VspDetails initAndExecuteHealer(String onboardingMethod) throws Exception { + VspDetails vspDetails = new VspDetails(); + vspDetails.setOnboardingMethod(onboardingMethod); - @Test - public void checkHealingWithHEATOnboarding() throws Exception{ - VspOnboardingMethodHealer vspOnboardingMethodHealer = new VspOnboardingMethodHealer(vendorSoftwareProductInfoDao); - Map<String,Object> params = new HashMap<>(); - params.put(SdcCommon.VSP_ID,"1"); - params.put(SdcCommon.VERSION, new Version(1,1)); - VspDetails vspDetails = new VspDetails(); - vspDetails.setOnboardingMethod("HEAT"); - Mockito.when(vendorSoftwareProductInfoDao.get(any())).thenReturn(vspDetails); - vspOnboardingMethodHealer.heal(params); - assertEquals(vspDetails.getOnboardingMethod(),"NetworkPackage"); - assertEquals(vspDetails.getOnboardingOrigin(),"zip"); - } + setMockActions(vspDetails); + vspOnboardingMethodHealer.heal(vspId, version); + return vspDetails; + } - @Test - public void checkHealingWithManualOnboarding() throws Exception{ - VspOnboardingMethodHealer vspOnboardingMethodHealer = new VspOnboardingMethodHealer(vendorSoftwareProductInfoDao); - Map<String,Object> params = new HashMap<>(); - params.put(SdcCommon.VSP_ID,"1"); - params.put(SdcCommon.VERSION, new Version(1,1)); - VspDetails vspDetails = new VspDetails(); - vspDetails.setOnboardingMethod("Manual"); - Mockito.when(vendorSoftwareProductInfoDao.get(any())).thenReturn(vspDetails); - vspOnboardingMethodHealer.heal(params); - assertEquals(vspDetails.getOnboardingMethod(),"Manual"); - assertEquals(vspDetails.getOnboardingOrigin(),null); - } + private void setMockActions(VspDetails vspDetails) { + Mockito.doReturn(vspDetails).when(vendorSoftwareProductInfoDao).get(any()); + Mockito.doReturn(orchestrationTemplateEntity).when(orchestrationTemplateDao).get(any(), any()); + Mockito.doNothing().when(orchestrationTemplateDao).update(any(), any(), any()); + Mockito.doReturn(candidateData).when(candidateDao).get(any(), any()); + Mockito.doNothing().when(candidateDao).update(any(), any(), any()); + } }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/data/TestDescriptionHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/data/TestDescriptionHealer.java new file mode 100644 index 0000000000..aac1a502ef --- /dev/null +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/data/TestDescriptionHealer.java @@ -0,0 +1,16 @@ +package org.openecomp.sdc.healing.healers.testHealers.data; + +import org.openecomp.sdc.healing.interfaces.Healer; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.dao.types.Version; + +public class TestDescriptionHealer implements Healer { + + @Override + public Object heal(String vspId, Version version) throws Exception { + VspDetails vspDetails = new VspDetails(vspId, version); + vspDetails.setDescription("This is a data healer"); + + return vspDetails; + } +} diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/structure/TestNewEntityInVspHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/structure/TestNewEntityInVspHealer.java new file mode 100644 index 0000000000..7d71c0319b --- /dev/null +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/structure/TestNewEntityInVspHealer.java @@ -0,0 +1,16 @@ +package org.openecomp.sdc.healing.healers.testHealers.structure; + +import org.openecomp.sdc.healing.interfaces.Healer; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.dao.types.Version; + +public class TestNewEntityInVspHealer implements Healer { + + @Override + public Object heal(String vspId, Version version) throws Exception { + VspDetails vspDetails = new VspDetails(vspId, version); + vspDetails.setDescription("This is a structure healer"); + + return vspDetails; + } +} |