X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fcsar%2Fextractor%2FYamlExtractorTest.java;h=20c34344c6f25b04f781608268bac22cf2f023fb;hb=60457e41054465e9fa10c8e6bfdbfa62a45d1f0a;hp=f783e7c9dc20dcf740cd96b7d0c2e2dbbbbe6dd2;hpb=dc94e09008ba0eb9dce7541d2c898ddc5c500814;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java b/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java index f783e7c..20c3434 100644 --- a/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java +++ b/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.csar.extractor; import static org.junit.Assert.assertEquals; @@ -28,6 +29,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.xml.generator.data.Artifact; @@ -89,18 +91,18 @@ public class YamlExtractorTest { @Test public void testInvalidContentSupplied() { invalidArgumentsTest("This is a piece of nonsense and not a zip file".getBytes(), FOO, FOO, - "An error occurred trying to create a ZipFile. Is the content being converted really a csar file?"); + "An error occurred trying to create a ZipFile. Is the content being converted really a CSAR file?"); } @Test public void testArchiveContainsNoYmlFiles() throws IOException { try { - extractArchive("noYmlFilesArchive.zip"); + CsarTest.NO_YAML_FILES.extractArtifacts(); fail("An instance of InvalidArchiveException should have been thrown."); } catch (Exception e) { assertTrue("An instance of InvalidArchiveException should have been thrown.", e instanceof InvalidArchiveException); - assertEquals("Incorrect message was returned", "No valid YAML files were found in the csar file.", + assertEquals("Incorrect message was returned", "No valid YAML files were found in the CSAR file.", e.getMessage()); } } @@ -108,22 +110,36 @@ public class YamlExtractorTest { @Test public void testArchiveContainsOnlyTheExpectedYmlFilesFromSdWanService() throws IOException, InvalidArchiveException { - final List ymlFiles = extractArchive("service-SdWanServiceTest-csar.csar"); + final List ymlFiles = CsarTest.SD_WAN_CSAR_FILE.extractArtifacts(); List payloads = new ArrayList<>(); payloads.add("ymlFiles/resource-SdWanTestVsp-template.yml"); + payloads.add("ymlFiles/resource-SdWanTestVsp-template-interface.yml"); payloads.add("ymlFiles/resource-TunnelXconntest-template.yml"); + payloads.add("ymlFiles/resource-TunnelXconntest-template-interface.yml"); payloads.add("ymlFiles/service-SdWanServiceTest-template.yml"); + payloads.add("ymlFiles/service-SdWanServiceTest-template-interface.yml"); + payloads.add("ymlFiles/resource-Allotedresource-template.yml"); + payloads.add("ymlFiles/resource-SdwantestvspNodesDummyServer-template.yml"); + payloads.add("ymlFiles/nodes.yml"); + payloads.add("ymlFiles/capabilities.yml"); payloads.add("ymlFiles/artifacts.yml"); payloads.add("ymlFiles/data.yml"); + payloads.add("ymlFiles/groups.yml"); new ArtifactTestUtils().performYmlAsserts(ymlFiles, payloads); } /** + * Call the extractor with the specified arguments and assert that an exception is thrown. + * * @param archive + * the compressed archive in the form of a byte array, expected to contain one or more YAML files * @param name + * the name of the archive * @param version + * the version of the archive * @param expectedErrorMessage + * the text of the InvalidArchiveException thrown by the extractor */ private void invalidArgumentsTest(byte[] archive, String name, String version, String expectedErrorMessage) { try { @@ -134,14 +150,4 @@ public class YamlExtractorTest { assertEquals(expectedErrorMessage, ex.getLocalizedMessage()); } } - - /** - * @param resourceName - * @return - * @throws InvalidArchiveException - * @throws IOException - */ - private List extractArchive(String resourceName) throws InvalidArchiveException, IOException { - return new YamlExtractor().extract(new ArtifactTestUtils().getCompressedArtifact(resourceName), resourceName, "v1"); - } }