diff options
Diffstat (limited to 'src/test/java')
5 files changed, 76 insertions, 35 deletions
diff --git a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java index ecef30ee4..00d5dffbb 100644 --- a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java +++ b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java @@ -20,7 +20,9 @@ package org.onap.clamp.clds.config.sdc; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -58,13 +60,16 @@ public class SdcSingleControllerConfigurationTest { assertEquals("consumerGroup", sdcConfig.getConsumerGroup()); assertEquals("consumerId", sdcConfig.getConsumerID()); assertEquals("environmentName", sdcConfig.getEnvironmentName()); - assertEquals("hostname", sdcConfig.getAsdcAddress()); + assertEquals("hostname:8080", sdcConfig.getAsdcAddress()); assertEquals(10, sdcConfig.getPollingInterval()); assertEquals(30, sdcConfig.getPollingTimeout()); assertEquals(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST.size(), sdcConfig.getRelevantArtifactTypes().size()); assertTrue(sdcConfig.activateServerTLSAuth()); assertEquals("ThePassword", sdcConfig.getKeyStorePassword()); + assertArrayEquals(new String[] { + "localhost" + }, sdcConfig.getMsgBusAddress().toArray()); } @Test(expected = SdcParametersException.class) @@ -78,6 +83,15 @@ public class SdcSingleControllerConfigurationTest { } @Test + public final void testAllRequiredParametersEmptyEncrypted() + throws JsonParseException, JsonMappingException, IOException { + SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration( + "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1"); + sdcConfig.testAllRequiredParameters(); + assertNull(sdcConfig.getKeyStorePassword()); + } + + @Test public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json", "sdc-controller1"); diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java index ba37b57f8..788a7ff7c 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java @@ -44,10 +44,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsDbServiceCache; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsModel; +import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.util.ResourceFileUtil; diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java index fc5cb040f..c0300eff6 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -24,6 +24,7 @@ package org.onap.clamp.clds.it.sdc.controller.installer; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -45,9 +46,9 @@ import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -58,7 +59,7 @@ public class CsarInstallerItCase { private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92"; - private static final String INVARIANT_RESOURCE1_UUID = "ba4d4b5d-f861-4155-886b-b1cdba5e0957"; + private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec"; @Autowired private CsarInstaller csarInstaller; @Autowired @@ -94,6 +95,7 @@ public class CsarInstallerItCase { throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csarHandler = buildFakeCsarHandler(generatedName); + assertFalse(csarInstaller.isCsarAlreadyDeployed(csarHandler)); csarInstaller.installTheCsar(csarHandler); assertTrue(csarInstaller.isCsarAlreadyDeployed(csarHandler)); } @@ -104,22 +106,22 @@ public class CsarInstallerItCase { String generatedName = RandomStringUtils.randomAlphanumeric(5); csarInstaller.installTheCsar(buildFakeCsarHandler(generatedName)); // Get the template back from DB - CldsTemplate templateFromDB = CldsTemplate.retrieve(cldsDao, + CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName, false); - assertNotNull(templateFromDB); - assertNotNull(templateFromDB.getBpmnText()); - assertNotNull(templateFromDB.getImageText()); - assertNotNull(templateFromDB.getPropText()); - assertTrue(templateFromDB.getPropText().contains("global") - && templateFromDB.getPropText().contains("node_templates:")); - assertEquals(templateFromDB.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName); + assertNotNull(templateFromDb); + assertNotNull(templateFromDb.getBpmnText()); + assertNotNull(templateFromDb.getImageText()); + assertNotNull(templateFromDb.getPropText()); + assertTrue(templateFromDb.getPropText().contains("global") + && templateFromDb.getPropText().contains("node_templates:")); + assertEquals(templateFromDb.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName); // Get the Model back from DB - CldsModel modelFromDB = CldsModel.retrieve(cldsDao, generatedName, true); - assertNotNull(modelFromDB); - assertNotNull(modelFromDB.getBpmnText()); - assertNotNull(modelFromDB.getImageText()); - assertNotNull(modelFromDB.getPropText()); - assertEquals(modelFromDB.getName(), generatedName); - assertEquals(CsarInstallerImpl.MODEL_NAME_PREFIX, modelFromDB.getControlNamePrefix()); + CldsModel modelFromDb = CldsModel.retrieve(cldsDao, generatedName, true); + assertNotNull(modelFromDb); + assertNotNull(modelFromDb.getBpmnText()); + assertNotNull(modelFromDb.getImageText()); + assertNotNull(modelFromDb.getPropText()); + assertEquals(modelFromDb.getName(), generatedName); + assertEquals(CsarInstallerImpl.MODEL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); } } diff --git a/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java b/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java index 447e25531..033c67d42 100644 --- a/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java +++ b/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java @@ -41,15 +41,15 @@ public class CldsDbServiceCacheTest { cldsServiceData.setServiceUUID("testUUID"); cldsServiceData.setAgeOfRecord(Long.valueOf(100)); cldsServiceData.setServiceInvariantUUID("testInvariantUUID"); - List<CldsVfData> cldsVfs = new ArrayList<>(); CldsVfData cldsVfData = new CldsVfData(); cldsVfData.setVfName("vf"); - List<CldsVfKPIData> cldsKPIList = new ArrayList<>(); - CldsVfKPIData cldsVfKPIData = new CldsVfKPIData(); - cldsVfKPIData.setFieldPath("fieldPath"); - cldsVfKPIData.setFieldPathValue("fieldValue"); - cldsKPIList.add(cldsVfKPIData); - cldsVfData.setCldsKPIList(cldsKPIList); + CldsVfKPIData cldsVfKpiData = new CldsVfKPIData(); + cldsVfKpiData.setFieldPath("fieldPath"); + cldsVfKpiData.setFieldPathValue("fieldValue"); + List<CldsVfKPIData> cldsKpiList = new ArrayList<>(); + cldsKpiList.add(cldsVfKpiData); + cldsVfData.setCldsKPIList(cldsKpiList); + List<CldsVfData> cldsVfs = new ArrayList<>(); cldsVfs.add(cldsVfData); cldsServiceData.setCldsVfs(cldsVfs); CldsDbServiceCache cldsDbServiceCache = new CldsDbServiceCache(cldsServiceData); diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java index c842068d9..3a37f9457 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java @@ -43,11 +43,11 @@ import org.mockito.Mockito; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; public class CsarHandlerTest { @@ -90,8 +90,6 @@ public class CsarHandlerTest { // Build what is needed for UUID Mockito.when(notifData.getServiceInvariantUUID()).thenReturn(SERVICE_UUID); // Build fake resource with one artifact BLUEPRINT - List<IResourceInstance> resourcesList = new ArrayList<>(); - List<IArtifactInfo> artifactsListForResource = new ArrayList<>(); IResourceInstance resource1 = Mockito.mock(IResourceInstance.class); Mockito.when(resource1.getResourceType()).thenReturn("VF"); Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID); @@ -99,8 +97,10 @@ public class CsarHandlerTest { IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class); Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE); Mockito.when(blueprintArtifact.getArtifactName()).thenReturn(BLUEPRINT1_NAME); + List<IArtifactInfo> artifactsListForResource = new ArrayList<>(); artifactsListForResource.add(blueprintArtifact); Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource); + List<IResourceInstance> resourcesList = new ArrayList<>(); resourcesList.add(resource1); Mockito.when(notifData.getResources()).thenReturn(resourcesList); return notifData; @@ -135,4 +135,29 @@ public class CsarHandlerTest { Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); } + + @Test + public void testDoubleSave() + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); + // Test the save + csar.save(buildFakeSdcResut()); + assertTrue((new File(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME)).exists()); + assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); + assertNotNull(csar.getSdcCsarHelper()); + // Test dcaeBlueprint + String blueprint = csar.getDcaeBlueprint(); + assertNotNull(blueprint); + assertTrue(!blueprint.isEmpty()); + assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); + // Test additional properties from Sdc notif + assertEquals(BLUEPRINT1_NAME, csar.getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, csar.getBlueprintInvariantResourceUuid()); + assertEquals(SERVICE_UUID, csar.getBlueprintInvariantServiceUuid()); + Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); + // A double save should simply overwrite the existing + csar.save(buildFakeSdcResut()); + // Do some cleanup + Files.deleteIfExists(path); + } } |