diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java')
6 files changed, 0 insertions, 625 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 deleted file mode 100644 index 688d1d4236..0000000000 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ComponentQuestionnaireHealerTest.java +++ /dev/null @@ -1,261 +0,0 @@ -package org.openecomp.sdc.healing.healers; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; -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.Collection; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; - -public class ComponentQuestionnaireHealerTest { - private static final String HANDLE_NUM_OF_VMS_METHOD = "handleNumOfVm"; - private static final String GENERAL = "general"; - private static final String IMAGE = "image"; - private static final String FORMAT = "format"; - private static final String CPU_OVER_SUBSCRIPTION_RATIO = "CpuOverSubscriptionRatio"; - private static final String MEMORY_RAM = "MemoryRAM"; - private static final String VM_SIZING = "vmSizing"; - private static final String COMPUTE = "compute"; - private static final String NUM_OF_VMS = "numOfVMs"; - private static final String DISK = "disk"; - private static final String BOOT_DISK_SIZE_PER_VM = "bootDiskSizePerVM"; - private static final String EPHEMERAL_DISK_SIZE_PER_VM = "ephemeralDiskSizePerVM"; - private static final Version VERSION = new Version(0, 1); - private static final String DUMMY_VSP_ID = "1495ef442f964cbfb00d82bd54292f89"; - 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 final String componentQuestionnaireData = "{\"compute\": {" + - "\"guestOS\": {\"bitSize\": 64},\"vmSizing\": {\"IOOperationsPerSec\": \"0\"}," + - "\"numOfVMs\": {\"CpuOverSubscriptionRatio\": \"1:1\",\"MemoryRAM\": \"2 GB\"}}," + - "\"general\": {\"image\": {\"providedBy\": \"AIC\",\"format\":\"qcow2\"," + - "\"bootDiskSizePerVM\": \"100\",\"ephemeralDiskSizePerVM\": \"200\"},\"hypervisor\": {" + - "\"hypervisor\": \"KVM\" } },\"highAvailabilityAndLoadBalancing\": {" + - "\"isComponentMandatory\": \"\",\"highAvailabilityMode\": \"\"},\"storage\": {" + - "\"backup\": {\"backupNIC\": \"\",\"backupType\": \"On Site\" }," + - "\"snapshotBackup\": {\"snapshotFrequency\": \"24\"}},\"network\": {\"networkCapacity\": {" + - "\"protocolWithHighestTrafficProfileAcrossAllNICs\": \"\"}}}"; - - private static final String componentQuestionnaireMissingDiskAttrData = "{\"compute\": {" + - "\"guestOS\": {\"bitSize\": 64},\"vmSizing\": {\"IOOperationsPerSec\": \"0\"},\"numOfVMs\"" + - ": {\"CpuOverSubscriptionRatio\": \"1:1\",\"MemoryRAM\": \"2 GB\"}},\"general\": " + - "{\"image\": {\"providedBy\": \"AIC\",\"format\":\"qcow2\"}," + - "\"hypervisor\": {\"hypervisor\": \"KVM\" } },\"highAvailabilityAndLoadBalancing\": {" + - "\"isComponentMandatory\": \"\",\"highAvailabilityMode\": \"\"},\"storage\": {" + - "\"backup\": {\"backupNIC\": \"\",\"backupType\": \"On Site\" }," + - "\"snapshotBackup\": {\"snapshotFrequency\": \"24\"}},\"network\": {\"networkCapacity\": {" + - "\"protocolWithHighestTrafficProfileAcrossAllNICs\": \"\"}}}"; - - private static final String componentQuestionnaireWithoutVMSizingData = "{\"compute\": {" + - "\"guestOS\": {\"bitSize\": 64},\"numOfVMs\": {\"CpuOverSubscriptionRatio\": \"1:1\"," + - "\"maximum\": \"400\"," + - "\"MemoryRAM\": \"2 GB\"}},\"general\": {\"image\": {\"providedBy\": \"AIC\",\"format\"" + - ":\"qcow2\",\"bootDiskSizePerVM\": \"100\",\"ephemeralDiskSizePerVM\": \"200\"}," + - "\"hypervisor\": {\"hypervisor\": \"KVM\" } },\"highAvailabilityAndLoadBalancing\": {" + - "\"isComponentMandatory\": \"\",\"highAvailabilityMode\": \"\"},\"storage\": {" + - "\"backup\": {\"backupNIC\": \"\",\"backupType\": \"On Site\" }," + - "\"snapshotBackup\": {\"snapshotFrequency\": \"24\"}},\"network\": {\"networkCapacity\": {" + - "\"protocolWithHighestTrafficProfileAcrossAllNICs\": \"\"}}}"; - - private static final String componentQuestionnaireWithoutNumOfVMData = "{\"compute\": " + - "{\"guestOS\": {\"bitSize\": 64}," + - "\"vmSizing\": {\"IOOperationsPerSec\": \"0\"}}," + - "\"general\": {\"image\": {\"providedBy\": \"AIC\",\"format\":\"qcow2\"," + - "\"bootDiskSizePerVM\": \"100\",\"ephemeralDiskSizePerVM\": \"200\"}," + - "\"hypervisor\": {\"hypervisor\": \"KVM\" } },\"highAvailabilityAndLoadBalancing\": {" + - "\"isComponentMandatory\": \"\",\"highAvailabilityMode\": \"\"},\"storage\": {" + - "\"backup\": {\"backupNIC\": \"\",\"backupType\": \"On Site\" }," + - "\"snapshotBackup\": {\"snapshotFrequency\": \"24\"}},\"network\": {\"networkCapacity\": {" + - "\"protocolWithHighestTrafficProfileAcrossAllNICs\": \"\"}}}"; - - private static final String componentQuestionnaireWithMemoryRamData = "{\"compute\": " + - "{\"guestOS\": {\"bitSize\": 64}," + - "\"vmSizing\": {\"IOOperationsPerSec\": \"0\"},\"numOfVMs\": {\"MemoryRAM\": \"2 GB\"}}," + - "\"general\": {\"image\": {\"providedBy\": \"AIC\",\"format\":\"qcow2\"," + - "\"bootDiskSizePerVM\": \"100\",\"ephemeralDiskSizePerVM\": \"200\"}," + - "\"hypervisor\": {\"hypervisor\": \"KVM\" } },\"highAvailabilityAndLoadBalancing\": {" + - "\"isComponentMandatory\": \"\",\"highAvailabilityMode\": \"\"},\"storage\": {" + - "\"backup\": {\"backupNIC\": \"\",\"backupType\": \"On Site\" }," + - "\"snapshotBackup\": {\"snapshotFrequency\": \"24\"}},\"network\": {\"networkCapacity\": {" + - "\"protocolWithHighestTrafficProfileAcrossAllNICs\": \"\"}}}"; - - private static final String componentQuestionnaireWithCPURatioData = "{\"compute\": " + - "{\"guestOS\": {\"bitSize\": 64},\"vmSizing\": {\"IOOperationsPerSec\": " + - "\"0\"},\"numOfVMs\": {\"CpuOverSubscriptionRatio\": " + - "\"1:1\"}},\"general\": {\"image\": {\"providedBy\": \"AIC\",\"format\":\"qcow2\"," + - "\"bootDiskSizePerVM\": \"100\",\"ephemeralDiskSizePerVM\": \"200\"}," + - "\"hypervisor\": {\"hypervisor\": \"KVM\" } },\"highAvailabilityAndLoadBalancing\": {" + - "\"isComponentMandatory\": \"\",\"highAvailabilityMode\": \"\"},\"storage\": {" + - "\"backup\": {\"backupNIC\": \"\",\"backupType\": \"On Site\" }," + - "\"snapshotBackup\": {\"snapshotFrequency\": \"24\"}},\"network\": {\"networkCapacity\": {" + - "\"protocolWithHighestTrafficProfileAcrossAllNICs\": \"\"}}}"; - - private static final JsonParser jsonParser = new JsonParser(); - private ComponentEntity componentEntity; - - @Mock - private ImageDao imageDao; - - @Mock - private ComputeDao computeDao; - - @Mock - private ComponentDao componentDao; - - @InjectMocks - private ComponentQuestionnaireHealer componentQuestionnaireHealer; - - @Before - public void init() throws Exception { - MockitoAnnotations.initMocks(ComponentQuestionnaireHealerTest.this); - } - - @Test - public void healQuestionnaireNullTest() throws Exception { - prepareHealingData(); - componentEntity.setQuestionnaireData(null); - Object returnObject = componentQuestionnaireHealer.heal(DUMMY_VSP_ID, VERSION); - Assert.assertTrue(returnObject instanceof Collection); - Collection<ComponentEntity> componentEntities = (Collection<ComponentEntity>) returnObject; - componentEntities.forEach(componentEntity -> { - Assert.assertNull(componentEntity.getQuestionnaireData()); - }); - } - - @Test - public void healAllCasesTest() throws Exception { - prepareHealingData(); - - Object returnObject = componentQuestionnaireHealer.heal(DUMMY_VSP_ID, VERSION); - Assert.assertTrue(returnObject instanceof Collection); - Collection<ComponentEntity> componentEntities = (Collection<ComponentEntity>) returnObject; - componentEntities.forEach(componentEntity -> { - JsonObject json = (JsonObject) jsonParser.parse(componentEntity.getQuestionnaireData()); - Assert.assertNotNull(json.getAsJsonObject(GENERAL).getAsJsonObject(DISK)); - Assert.assertNotNull(json.getAsJsonObject(GENERAL).getAsJsonObject(DISK) - .getAsJsonPrimitive(BOOT_DISK_SIZE_PER_VM)); - Assert.assertNotNull(json.getAsJsonObject(GENERAL).getAsJsonObject(DISK) - .getAsJsonPrimitive(EPHEMERAL_DISK_SIZE_PER_VM)); - Assert.assertNotNull(json.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS)); - Assert.assertNull(json.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS) - .getAsJsonPrimitive(MEMORY_RAM)); - Assert.assertNull(json.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS) - .getAsJsonPrimitive(CPU_OVER_SUBSCRIPTION_RATIO)); - Assert.assertNull(json.getAsJsonObject(GENERAL).getAsJsonObject(IMAGE) - .getAsJsonPrimitive(FORMAT)); - Assert.assertNull(json.getAsJsonObject(COMPUTE).getAsJsonObject(VM_SIZING)); - }); - } - - @Test - public void healDiskAttrMissingTest() throws Exception { - prepareHealingData(); - componentEntity.setQuestionnaireData(componentQuestionnaireMissingDiskAttrData); - Object returnObject = componentQuestionnaireHealer.heal(DUMMY_VSP_ID, VERSION); - Assert.assertTrue(returnObject instanceof Collection); - Collection<ComponentEntity> componentEntities = (Collection<ComponentEntity>) returnObject; - componentEntities.forEach(componentEntity -> { - JsonObject json = (JsonObject) jsonParser.parse(componentEntity.getQuestionnaireData()); - Assert.assertNull(json.getAsJsonObject(COMPUTE).getAsJsonObject(VM_SIZING)); - }); - } - - @Test - public void handleVMSizingWithVMSizingTest() - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - JsonObject jsonObject = (JsonObject) jsonParser.parse(componentQuestionnaireWithoutNumOfVMData); - Method method = ComponentQuestionnaireHealer.class.getDeclaredMethod("handleVmSizing", - JsonObject.class); - method.setAccessible(true); - method.invoke(componentQuestionnaireHealer, jsonObject.getAsJsonObject(COMPUTE)); - - Assert.assertNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(VM_SIZING)); - } - - @Test - public void handleNumOfVMWithoutVMSizingTest() - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - JsonObject jsonObject = (JsonObject) jsonParser - .parse(componentQuestionnaireWithoutVMSizingData); - provideAccessToPrivateMethod(HANDLE_NUM_OF_VMS_METHOD, jsonObject); - - Assert.assertNotNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS)); - Assert.assertNotNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS) - .getAsJsonPrimitive("maximum")); - } - - @Test - public void handleVMSizingWithOnlyMemoryRAMTest() - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - JsonObject jsonObject = (JsonObject) jsonParser.parse(componentQuestionnaireWithMemoryRamData); - provideAccessToPrivateMethod(HANDLE_NUM_OF_VMS_METHOD, jsonObject); - - Assert.assertNotNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS)); - Assert.assertNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS) - .getAsJsonPrimitive(MEMORY_RAM)); - } - - @Test - public void handleVMSizingWithOnlyCpuRatioTest() - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - JsonObject jsonObject = (JsonObject) jsonParser.parse(componentQuestionnaireWithCPURatioData); - provideAccessToPrivateMethod(HANDLE_NUM_OF_VMS_METHOD, jsonObject); - - Assert.assertNotNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS)); - Assert.assertNull(jsonObject.getAsJsonObject(COMPUTE).getAsJsonObject(NUM_OF_VMS) - .getAsJsonPrimitive(CPU_OVER_SUBSCRIPTION_RATIO)); - } - - private void provideAccessToPrivateMethod(String methodName, JsonObject jsonObject) - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - Method method = ComponentQuestionnaireHealer.class - .getDeclaredMethod(methodName, JsonObject.class, JsonObject.class); - method.setAccessible(true); - - method.invoke(componentQuestionnaireHealer, jsonObject.getAsJsonObject(COMPUTE), null); - } - - private void prepareHealingData() { - componentEntity = new ComponentEntity(DUMMY_VSP_ID, VERSION, DUMMY_COMPONENT_ID); - componentEntity.setQuestionnaireData(componentQuestionnaireData); - - Collection<ComponentEntity> componentEntities = new ArrayList<>(); - componentEntities.add(componentEntity); - doReturn(componentEntities).when(componentDao).list(anyObject()); - doReturn(componentEntity).when(componentDao).getQuestionnaireData(DUMMY_VSP_ID, - VERSION, DUMMY_COMPONENT_ID); - - ComputeEntity computeEntity = new ComputeEntity(DUMMY_VSP_ID, VERSION, - DUMMY_COMPONENT_ID, DUMMY_COMPUTE_ID); - Collection<ComputeEntity> computeEntities = new ArrayList<>(); - computeEntities.add(computeEntity); - doReturn(computeEntities).when(computeDao).list(anyObject()); - - ImageEntity imageEntity = new ImageEntity(DUMMY_VSP_ID, VERSION, - DUMMY_COMPONENT_ID, DUMMY_IMAGE_ID); - Collection<ImageEntity> imageEntities = new ArrayList<>(); - imageEntities.add(imageEntity); - doReturn(imageEntities).when(imageDao).list(anyObject()); - - doNothing().when(componentDao).updateQuestionnaireData(anyObject(), - anyObject(), anyObject(), anyObject()); - } -} 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 deleted file mode 100644 index a07ace683f..0000000000 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/ForwarderCapabilityHealerTest.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.openecomp.sdc.healing.healers; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -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.healing.healers.util.TestUtil; -import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; -import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.togglz.testing.TestFeatureManager; -import org.togglz.testing.TestFeatureManagerProvider; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import static org.mockito.Matchers.any; -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; - - - @Mock - private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao; - @Mock - private ToscaAnalyzerService toscaAnalyzerService; - @InjectMocks - private ForwarderCapabilityHealer forwarderCapabilityHealer; - - @BeforeClass - public static void enableForwarderFeature(){ - manager = new TestFeatureManager(ToggleableFeature.class); - if (!ToggleableFeature.FORWARDER_CAPABILITY.isActive()) { - manager.enable(ToggleableFeature.FORWARDER_CAPABILITY); - } - } - - @AfterClass - public static void disableForwarderFeature() { - manager.disable(ToggleableFeature.FORWARDER_CAPABILITY); - manager = null; - TestFeatureManagerProvider.setFeatureManager(null); - } - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(ForwarderCapabilityHealerTest.this); - } - - - @Test - public void testHealingSubstitutionMappingsNeutronPort() throws Exception { - testForwarderHealer( - "/testSubMappingNeutronPort", "org.openecomp.resource.cp.nodes.heat.network.neutron.Port", true); - } - - @Test - public void testHealingSubstitutionMappingsContrailPort() throws Exception { - testForwarderHealer( - "/testSubMappingContrailPort", "org.openecomp.resource.cp.nodes.heat.network.contrail.Port", true); - } - - @Test - public void testHealingSubstitutionMappingsExtNeutronPort() throws Exception { - testForwarderHealer( - "/testSubMappingExtNeutronPort", "org.openecomp.resource.cp.v2.extNeutronCP", true); - } - - @Test - public void testHealingSubstitutionMappingsExtContrailPort() throws Exception { - testForwarderHealer( - "/testSubMappingExtContrailPort", "org.openecomp.resource.cp.v2.extContrailCP", true); - } - - @Ignore - public void testHealingGlobalServiceTemplates () throws Exception { - testForwarderHealer("/testGlobalServiceTemplates", null, false); - } - - @Test - public void testHealingNoPorts() throws Exception { - testForwarderHealer("/testNoPorts", null, false); - } - - private void testForwarderHealer(String testDirectory, - String portType, - boolean needToTestSubMapping) throws Exception { - - ToscaServiceModel toscaServiceModel = TestUtil.loadToscaServiceModel( - BASE_DIRECTORY + testDirectory + IN_SUFFIX, null, ENTRY_DEFINITION_SERVICE_TEMPLATE); - - Mockito.doReturn(toscaServiceModel) - .when(serviceModelDao).getServiceModel(any(), any()); - - if(needToTestSubMapping) { - Mockito.doReturn(true) - .when(toscaAnalyzerService).isTypeOf( - eq(getMockPortNodeTemplate(portType)), - eq(ToscaNodeType.NATIVE_NETWORK_PORT), - anyObject(), anyObject()); - } - - validateServiceModelAfterHealing(testDirectory); - } - - private void validateServiceModelAfterHealing(String testDirectory) throws Exception { - Optional<ToscaServiceModel> serviceModelObject = - (Optional<ToscaServiceModel>) forwarderCapabilityHealer.heal(vspId, version); - - Assert.assertTrue(serviceModelObject.isPresent()); - TestUtil - .compareToscaServiceModels( - BASE_DIRECTORY + testDirectory + OUT_SUFFIX, serviceModelObject.get()); - } - - private NodeTemplate getMockPortNodeTemplate(String portType) { - NodeTemplate nodeTemplate = new NodeTemplate(); - nodeTemplate.setType(portType); - - Map<String, Object> properties = new HashMap<>(); - properties.put("exCP_naming", "port_pd01_port_exCP_naming"); - nodeTemplate.setProperties(properties); - - return nodeTemplate; - } - -} 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 deleted file mode 100644 index 5584a5fe77..0000000000 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/VspOnboardingMethodHealerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -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.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 static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; - -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); - } - - @Test - public void checkHealingWithHEATOnboarding() throws Exception { - VspDetails vspDetails = initAndExecuteHealer(HEAT); - assertEquals(vspDetails.getOnboardingMethod(), NETWORK_PACKAGE); - } - - @Test - public void checkHealingWithManualOnboarding() throws Exception { - VspDetails vspDetails = initAndExecuteHealer(MANUAL); - assertEquals(vspDetails.getOnboardingMethod(), MANUAL); - } - - private VspDetails initAndExecuteHealer(String onboardingMethod) throws Exception { - VspDetails vspDetails = new VspDetails(); - vspDetails.setOnboardingMethod(onboardingMethod); - - setMockActions(vspDetails); - vspOnboardingMethodHealer.heal(vspId, version); - return vspDetails; - } - - 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 deleted file mode 100644 index aac1a502ef..0000000000 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/data/TestDescriptionHealer.java +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 7d71c0319b..0000000000 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/testHealers/structure/TestNewEntityInVspHealer.java +++ /dev/null @@ -1,16 +0,0 @@ -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; - } -} diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java deleted file mode 100644 index da44ec422f..0000000000 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.openecomp.sdc.healing.healers.util; - -import org.junit.Assert; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; -import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; -import org.openecomp.sdc.tosca.services.ToscaUtil; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.NotDirectoryException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -public class TestUtil { - private final static Logger log = (Logger) LoggerFactory.getLogger - (TestUtil.class.getName()); - - public static ToscaServiceModel loadToscaServiceModel(String serviceTemplatesPath, - String globalServiceTemplatesPath, - String entryDefinitionServiceTemplate) - throws IOException { - ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(); - if (entryDefinitionServiceTemplate == null) { - entryDefinitionServiceTemplate = "MainServiceTemplate.yaml"; - } - - loadServiceTemplates(serviceTemplatesPath, toscaExtensionYamlUtil, serviceTemplates); - if (globalServiceTemplatesPath != null) { - loadServiceTemplates(globalServiceTemplatesPath, toscaExtensionYamlUtil, serviceTemplates); - } - - return new ToscaServiceModel(null, serviceTemplates, entryDefinitionServiceTemplate); - } - - private static void loadServiceTemplates(String serviceTemplatesPath, - ToscaExtensionYamlUtil toscaExtensionYamlUtil, - Map<String, ServiceTemplate> serviceTemplates) - throws IOException { - URL urlFile = TestUtil.class.getResource(serviceTemplatesPath); - if (urlFile != null) { - File pathFile = new File(urlFile.getFile()); - Collection<File> files = org.apache.commons.io.FileUtils.listFiles(pathFile, null, true); - if (files != null) { - addServiceTemplateFiles(serviceTemplates, files, toscaExtensionYamlUtil); - } else { - throw new NotDirectoryException(serviceTemplatesPath); - } - } else { - throw new NotDirectoryException(serviceTemplatesPath); - } - } - - private static void addServiceTemplateFiles(Map<String, ServiceTemplate> serviceTemplates, - Collection<File> files, - ToscaExtensionYamlUtil toscaExtensionYamlUtil) - throws IOException { - for (File file : files) { - try (InputStream yamlFile = new FileInputStream(file)) { - ServiceTemplate serviceTemplateFromYaml = - toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); - serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplateFromYaml), serviceTemplateFromYaml); - try { - yamlFile.close(); - } catch (IOException ignore) { - log.debug("",ignore); - } - } catch (FileNotFoundException exception) { - throw exception; - } catch (IOException exception) { - throw exception; - } - } - } - - public static void compareToscaServiceModels(String expectedServiceModelPath, - ToscaServiceModel actualServiceModel) - throws IOException { - ToscaServiceModel expectedServiceModel = - loadToscaServiceModel(expectedServiceModelPath, null, null); - - Map<String, ServiceTemplate> expectedServiceTemplates = - new HashMap<>(expectedServiceModel.getServiceTemplates()); - Map<String, ServiceTemplate> actualServiceTemplates = - new HashMap<>(actualServiceModel.getServiceTemplates()); - - for (Map.Entry<String, ServiceTemplate> expectedServiceTemplateEntry : expectedServiceTemplates.entrySet()) { - String serviceTemplateName = expectedServiceTemplateEntry.getKey(); - ServiceTemplate actualServiceTemplate = - actualServiceTemplates.get(serviceTemplateName); - - Assert.assertNotNull("Missing service template in service model : " + serviceTemplateName, actualServiceTemplate); - org.junit.Assert.assertEquals("Difference in file " + serviceTemplateName, - JsonUtil.object2Json(expectedServiceTemplateEntry.getValue()), - JsonUtil.object2Json(actualServiceTemplate)); - } - } -} |