diff options
Diffstat (limited to 'src/test/java')
3 files changed, 112 insertions, 16 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java index 1caa637c5..be2997a31 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java @@ -35,7 +35,6 @@ import java.security.Principal; import java.util.List; import javax.ws.rs.core.SecurityContext; -import javax.xml.transform.TransformerException; import org.junit.Before; import org.junit.Test; @@ -93,13 +92,7 @@ public class CldsTemplateServiceItCase { cldsTemplate.setBpmnText(bpmnText); cldsTemplate.setImageText(imageText); cldsTemplate.setPropText(bpmnPropText); - try { - cldsTemplateService.putTemplate("testModel", cldsTemplate); - } catch (IOException e) { - logger.error("IOException while saving template", e); - } catch (TransformerException ex) { - logger.error("Transforming exception while saving template.", ex); - } + cldsTemplateService.putTemplate("testModel", cldsTemplate); } @Test 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 new file mode 100644 index 000000000..94adfafa8 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it.sdc.controller.installer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import com.att.aft.dme2.internal.apache.commons.io.IOUtils; +import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils; + +import java.io.IOException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.clamp.clds.dao.CldsDao; +import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; +import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; +import org.onap.clamp.clds.model.CldsTemplate; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CsarInstallerItCase { + + private static final String sdcFolder = "/tmp/csar-handler-tests"; + private static final String csarArtifactName = "testArtifact.csar"; + @Autowired + private CsarInstaller csarInstaller; + @Autowired + private CldsDao cldsDao; + + private void loadFile(String fileName) throws IOException { + ReflectionTestUtils.setField(csarInstaller, "blueprintMappingFile", fileName); + ((CsarInstallerImpl) csarInstaller).loadConfiguration(); + } + + @Test(expected = SdcArtifactInstallerException.class) + public void testInstallTheCsarFail() + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + CsarHandler csarHandler = Mockito.mock(CsarHandler.class); + Mockito.when(csarHandler.getDcaeBlueprint()).thenReturn(IOUtils + .toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"))); + csarInstaller.installTheCsar(csarHandler); + fail("Should have raised an SdcArtifactInstallerException"); + } + + @Test() + public void testInstallTheCsarTca() + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + String generatedName = RandomStringUtils.randomAlphanumeric(5); + CsarHandler csarHandler = Mockito.mock(CsarHandler.class); + Mockito.when(csarHandler.getDcaeBlueprint()).thenReturn( + IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/tca.yaml"))); + ISdcCsarHelper csarHelper = Mockito.mock(ISdcCsarHelper.class); + Metadata data = Mockito.mock(Metadata.class); + Mockito.when(data.getValue("name")).thenReturn(generatedName); + Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data); + Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); + csarInstaller.installTheCsar(csarHandler); + // Get it back from DB + CldsTemplate templateFromDB = CldsTemplate.retrieve(cldsDao, + generatedName + CsarInstallerImpl.TEMPLATE_NAME_SUFFIX, false); + assertNotNull(templateFromDB); + assertNotNull(templateFromDB.getBpmnText()); + assertNotNull(templateFromDB.getImageText()); + assertNotNull(templateFromDB.getPropText()); + assertEquals(templateFromDB.getName(), generatedName + CsarInstallerImpl.TEMPLATE_NAME_SUFFIX); + } +} 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 d1b177d22..34805d87a 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 @@ -38,7 +38,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; import org.junit.Test; import org.mockito.Mockito; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; @@ -54,13 +53,6 @@ public class CsarHandlerTest { private static final String sdcFolder = "/tmp/csar-handler-tests"; private static final String csarArtifactName = "testArtifact.csar"; - @AfterClass - public static void removeAllFiles() throws IOException { - // Do some cleanup - Path path = Paths.get(sdcFolder + "/test-controller/" + csarArtifactName); - Files.deleteIfExists(path); - } - @Test public void testConstructor() throws CsarHandlerException { IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class); @@ -96,9 +88,18 @@ public class CsarHandlerTest { IDistributionClientDownloadResult resultArtifact = Mockito.mock(IDistributionClientDownloadResult.class); Mockito.when(resultArtifact.getArtifactPayload()).thenReturn( IOUtils.toByteArray(ResourceFileUtil.getResourceAsStream("example/sdc/service-Simsfoimap0112.csar"))); + // Test the save csar.save(resultArtifact); assertTrue((new File(sdcFolder + "/test-controller/" + csarArtifactName)).exists()); assertEquals(csarArtifactName, 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")); + // Do some cleanup + Path path = Paths.get(sdcFolder + "/test-controller/" + csarArtifactName); + Files.deleteIfExists(path); } } |