From: mark.j.leonard Date: Thu, 6 Sep 2018 10:56:00 +0000 (+0100) Subject: Refactor Junit test code to remove duplication X-Git-Tag: 1.3.0~11 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fbabel.git;a=commitdiff_plain;h=6b2de4b2de03890d0f0ba0663244ef1a98457309 Refactor Junit test code to remove duplication Simplify the code by introducing an Enum to store each of the test input CSAR files. Add common functionality to this Enum class. Change-Id: I3c44d7ec3b7808a193b8918c43cf0a9eb5369533 Issue-ID: AAI-1250 Signed-off-by: mark.j.leonard --- 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 e01a8f0..abe6f4d 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 @@ -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; @@ -95,7 +97,7 @@ public class YamlExtractorTest { @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.", @@ -108,7 +110,7 @@ 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"); @@ -130,10 +132,10 @@ public class YamlExtractorTest { /** * Call the extractor with the specified arguments and assert that an exception is thrown. * - * @param archive - * @param name - * @param version - * @param expectedErrorMessage + * @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 { @@ -144,19 +146,4 @@ public class YamlExtractorTest { assertEquals(expectedErrorMessage, ex.getLocalizedMessage()); } } - - /** - * Extract Artifacts from the specified CSAR resource. - * - * @param resourceName - * the CSAR file - * @return the extracted artifacts - * @throws InvalidArchiveException - * @throws IOException - * for I/O errors - */ - private List extractArchive(String resourceName) throws InvalidArchiveException, IOException { - byte[] csar = new ArtifactTestUtils().getCompressedArtifact(resourceName); - return new YamlExtractor().extract(csar, resourceName, "v1"); - } } diff --git a/src/test/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractorTest.java b/src/test/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractorTest.java index 49784c1..b1229b4 100644 --- a/src/test/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractorTest.java +++ b/src/test/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractorTest.java @@ -31,10 +31,11 @@ import java.io.IOException; import org.junit.Test; import org.onap.aai.babel.service.data.BabelArtifact; import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType; +import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; /** - * Tests {@link VnfVendorImageExtractor} + * Tests {@link VnfVendorImageExtractor}. */ public class VnfVendorImageExtractorTest { @@ -50,18 +51,18 @@ public class VnfVendorImageExtractorTest { @Test(expected = ToscaToCatalogException.class) public void createVendorImageMappingsInvalidCsarFile() throws IOException, ToscaToCatalogException { - extractArtifact("noYmlFilesArchive.zip"); + CsarTest.NO_YAML_FILES.extractVnfVendorImages(); } @Test(expected = ToscaToCatalogException.class) public void createVendorImageMappingsInvalidFile() throws IOException, ToscaToCatalogException { - extractArtifact("Duff.txt"); + new VnfVendorImageExtractor().extract("not a real file".getBytes()); } @Test public void createVendorImageMappingsMoreThanOneVnfConfigurationExists() throws IOException { try { - extractArtifact("catalog_csar_too_many_vnfConfigurations.csar"); + CsarTest.MULTIPLE_VNF_CSAR.extractArtifacts(); } catch (Exception e) { assertThat(e, is(instanceOf(ToscaToCatalogException.class))); assertThat(e.getLocalizedMessage(), @@ -72,19 +73,15 @@ public class VnfVendorImageExtractorTest { @Test public void createVendorImageMappingsNoVnfConfigurationExists() throws IOException, ToscaToCatalogException { - assertThat(extractArtifact("noVnfConfiguration.csar"), is(nullValue())); + assertThat(CsarTest.NO_VNF_CONFIG_CSAR.extractVnfVendorImages(), is(nullValue())); } @Test public void createVendorImageMappingsValidFile() throws IOException, ToscaToCatalogException { - BabelArtifact artifact = extractArtifact("catalog_csar.csar"); + BabelArtifact artifact = CsarTest.VNF_VENDOR_CSAR.extractVnfVendorImages(); assertThat(artifact.getName(), is(equalTo("vnfVendorImageConfigurations"))); assertThat(artifact.getType(), is(equalTo(ArtifactType.VNFCATALOG))); assertThat(artifact.getPayload(), is(equalTo(new ArtifactTestUtils().getRequestJson("vnfVendorImageConfigurations.json")))); } - - private BabelArtifact extractArtifact(String artifactName) throws ToscaToCatalogException, IOException { - return new VnfVendorImageExtractor().extract(new ArtifactTestUtils().getCompressedArtifact(artifactName)); - } } diff --git a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java index 93b3576..f340132 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java @@ -34,7 +34,7 @@ import java.util.Properties; import org.junit.Before; import org.junit.Test; import org.onap.aai.babel.csar.extractor.InvalidArchiveException; -import org.onap.aai.babel.csar.extractor.YamlExtractor; +import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator; import org.onap.aai.babel.xml.generator.data.AdditionalParams; @@ -59,6 +59,7 @@ public class TestToscaParser { public void setup() throws FileNotFoundException, IOException { System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE, new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG)); + InputStream in = TestToscaParser.class.getClassLoader().getResourceAsStream("artifact-generator.properties"); Properties properties = new Properties(); properties.load(in); @@ -68,15 +69,13 @@ public class TestToscaParser { @Test public void testParserWithCsarFile() throws IOException, InvalidArchiveException { - String csarResourceName = "catalog_csar.csar"; - byte[] csarBytes = new ArtifactTestUtils().getCompressedArtifact(csarResourceName); - List ymlFiles = new YamlExtractor().extract(csarBytes, csarResourceName, "1.0"); - + List ymlFiles = CsarTest.VNF_VENDOR_CSAR.extractArtifacts(); Map additionalParams = new HashMap<>(); additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0"); AaiArtifactGenerator generator = new AaiArtifactGenerator(); - GenerationData data = generator.generateArtifact(csarBytes, ymlFiles, additionalParams); + GenerationData data = generator.generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(), ymlFiles, + additionalParams); assertThat(data.getErrorData().size(), is(equalTo(0))); assertThat(data.getResultData().size(), is(equalTo(2))); diff --git a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java index 9cfdf9b..67539bb 100644 --- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java +++ b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java @@ -21,6 +21,8 @@ package org.onap.aai.babel.service; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.io.IOException; @@ -40,6 +42,7 @@ import org.onap.aai.babel.csar.CsarConverterException; import org.onap.aai.babel.csar.CsarToXmlConverter; import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser; import org.onap.aai.babel.service.data.BabelArtifact; +import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; @@ -58,36 +61,6 @@ public class CsarToXmlConverterTest { } } - private enum CsarTest { - VALID_CSAR_FILE( - "service-SdWanServiceTest-csar.csar" - ), - MISSING_METADATA_CSAR( - "service-MissingMetadataTest.csar" - ), - NO_YAML_FILES( - "noYmlFilesArchive.zip" - ), - PORT_MIRROR_CSAR( - "service_PortMirror.csar" - ); - - private String filename; - private ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils(); - - CsarTest(String filename) { - this.filename = filename; - } - - public String getName() { - return filename; - } - - public byte[] getContent() throws IOException { - return artifactTestUtils.getCompressedArtifact(filename); - } - } - // The class to be tested. private CsarToXmlConverter converter; @@ -113,12 +86,12 @@ public class CsarToXmlConverterTest { @Test(expected = NullPointerException.class) public void testMissingName() throws CsarConverterException, IOException { - converter.generateXmlFromCsar(CsarTest.VALID_CSAR_FILE.getContent(), null, null); + converter.generateXmlFromCsar(CsarTest.SD_WAN_CSAR_FILE.getContent(), null, null); } @Test(expected = NullPointerException.class) public void testMissingVersion() throws CsarConverterException, IOException { - converter.generateXmlFromCsar(CsarTest.VALID_CSAR_FILE.getContent(), INCORRECT_CSAR_NAME, null); + converter.generateXmlFromCsar(CsarTest.SD_WAN_CSAR_FILE.getContent(), INCORRECT_CSAR_NAME, null); } @Test(expected = CsarConverterException.class) @@ -128,18 +101,28 @@ public class CsarToXmlConverterTest { @Test(expected = CsarConverterException.class) public void testCsarFileHasNoYmlFiles() throws CsarConverterException, IOException { - converter.generateXmlFromCsar(CsarTest.NO_YAML_FILES.getContent(), "noYmlFilesArchive.zip", SERVICE_VERSION); + converter.generateXmlFromCsar(CsarTest.NO_YAML_FILES.getContent(), CsarTest.NO_YAML_FILES.getName(), + SERVICE_VERSION); } + /** + * Test that an Exception is thrown when the Artifact Generator properties are not present. + * + * @throws CsarConverterException if there is an error either extracting the YAML files or generating XML artifacts + * @throws IOException if an I/O exception occurs loading the test CSAR file + */ @Test - public void testArtifactGeneratorConfigMissing() - throws IOException, XmlArtifactGenerationException, CsarConverterException { + public void testArtifactGeneratorConfigMissing() throws CsarConverterException, IOException { exception.expect(CsarConverterException.class); - exception.expectMessage("Cannot generate artifacts. artifactgenerator.config system property not configured"); + exception.expectMessage( + "An error occurred trying to generate XML files from a collection of YAML files :" + + " org.onap.aai.babel.xml.generator.XmlArtifactGenerationException: " + + "Error occurred during artifact generation: " + + "{AAI=[Cannot generate artifacts. artifactgenerator.config system property not configured]}"); // Unset the required system property System.clearProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE); - converter.generateXmlFromCsar(CsarTest.VALID_CSAR_FILE.getContent(), CsarTest.VALID_CSAR_FILE.getName(), + converter.generateXmlFromCsar(CsarTest.SD_WAN_CSAR_FILE.getContent(), CsarTest.SD_WAN_CSAR_FILE.getName(), SERVICE_VERSION); } @@ -151,26 +134,22 @@ public class CsarToXmlConverterTest { } @Test - public void generateXmlFromCsar() throws CsarConverterException, IOException, XmlArtifactGenerationException { - Map expectedXmlFiles = createExpectedXmlFiles(); - List generatedArtifacts = converter.generateXmlFromCsar(CsarTest.VALID_CSAR_FILE.getContent(), - CsarTest.VALID_CSAR_FILE.getName(), SERVICE_VERSION); - - generatedArtifacts - .forEach(ga -> assertThat("The content of " + ga.getName() + " must match the expected content", - ga.getPayload(), matches(expectedXmlFiles.get(ga.getName())))); + public void generateXmlFromSdWanCsar() throws IOException, CsarConverterException { + List filesToLoad = new ArrayList<>(); + filesToLoad.add("AAI-SD-WAN-Service-Test-service-1.0.xml"); + filesToLoad.add("AAI-SdWanTestVsp..DUMMY..module-0-resource-2.xml"); + filesToLoad.add("AAI-Tunnel_XConnTest-resource-2.0.xml"); + filesToLoad.add("AAI-SD-WAN-Test-VSP-resource-1.0.xml"); + assertThatGeneratedFilesMatchExpected(createExpectedXmlFiles(filesToLoad), CsarTest.SD_WAN_CSAR_FILE); } @Test public void generatePortMirrorConfigurationModel() throws CsarConverterException, IOException, XmlArtifactGenerationException { - Map expectedXmlFiles = createExpectedXmlFiles(); - List generatedArtifacts = converter.generateXmlFromCsar(CsarTest.PORT_MIRROR_CSAR.getContent(), - CsarTest.PORT_MIRROR_CSAR.getName(), SERVICE_VERSION); - - generatedArtifacts - .forEach(ga -> assertThat("The content of " + ga.getName() + " must match the expected content", - ga.getPayload(), matches(expectedXmlFiles.get(ga.getName())))); + List filesToLoad = new ArrayList<>(); + filesToLoad.add("AAI-Port Mirror_Test-service-1.0.xml"); + filesToLoad.add("AAI-Port Mirroring Configuration-resource-35.0.xml"); + assertThatGeneratedFilesMatchExpected(createExpectedXmlFiles(filesToLoad), CsarTest.PORT_MIRROR_CSAR); } public Matcher matches(final String expected) { @@ -189,21 +168,22 @@ public class CsarToXmlConverterTest { }; } - private Map createExpectedXmlFiles() throws IOException { + private Map createExpectedXmlFiles(List filesToLoad) throws IOException { Map xmlMap = new HashMap<>(); - - List filesToLoad = new ArrayList<>(); - filesToLoad.add("AAI-SD-WAN-Service-Test-service-1.0.xml"); - filesToLoad.add("AAI-SdWanTestVsp..DUMMY..module-0-resource-2.xml"); - filesToLoad.add("AAI-Tunnel_XConnTest-resource-2.0.xml"); - filesToLoad.add("AAI-SD-WAN-Test-VSP-resource-1.0.xml"); - filesToLoad.add("AAI-Port Mirror_Test-service-1.0.xml"); - filesToLoad.add("AAI-Port Mirroring Configuration-resource-35.0.xml"); - for (String filename : filesToLoad) { xmlMap.put(filename, new ArtifactTestUtils().loadResourceAsString("generatedXml/" + filename)); } - return xmlMap; } + + private void assertThatGeneratedFilesMatchExpected(Map expectedXmlFiles, CsarTest csarFile) + throws CsarConverterException, IOException { + List generatedArtifacts = converter.generateXmlFromCsar(csarFile.getContent(), + csarFile.getName(), SERVICE_VERSION); + assertThat("Incorrect number of files generated", // + generatedArtifacts.size(), is(equalTo(expectedXmlFiles.size()))); + generatedArtifacts + .forEach(ga -> assertThat("The content of " + ga.getName() + " must match the expected content", + ga.getPayload(), matches(expectedXmlFiles.get(ga.getName())))); + } } diff --git a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java index 66a36ad..5bd5484 100644 --- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java +++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java @@ -44,8 +44,8 @@ import org.mockito.Mockito; import org.onap.aai.auth.AAIMicroServiceAuth; import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser; import org.onap.aai.babel.service.data.BabelRequest; +import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; -import org.onap.aai.babel.xml.generator.data.GeneratorUtil; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -78,7 +78,7 @@ public class TestGenerateArtifactsServiceImpl { @Test public void testGenerateArtifacts() throws Exception { - Response response = processJsonRequest(getRequestJson("success_request_vnf_catalog.json")); + Response response = processJsonRequest(CsarTest.VNF_VENDOR_CSAR); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); assertThat(response.getEntity(), is(getResponseJson("response.json"))); } @@ -90,49 +90,55 @@ public class TestGenerateArtifactsServiceImpl { */ @Test public void testGenerateArtifactsWithoutVnfConfiguration() throws Exception { - final byte[] csarContent = new ArtifactTestUtils().getCompressedArtifact("noVnfConfiguration.csar"); - - BabelRequest babelRequest = new BabelRequest(); - babelRequest.setCsar(new String(GeneratorUtil.encode(csarContent))); - babelRequest.setArtifactVersion("3.0"); - babelRequest.setArtifactName("service-Vscpass-Test"); - - Response response = processJsonRequest(new Gson().toJson(babelRequest)); + Response response = processJsonRequest(CsarTest.NO_VNF_CONFIG_CSAR); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); assertThat(response.getEntity(), is(getResponseJson("validNoVnfConfigurationResponse.json"))); } @Test public void testInvalidCsarFile() throws URISyntaxException, IOException { - Response response = processJsonRequest(getRequestJson("invalid_csar_request.json")); + BabelRequest request = new BabelRequest(); + request.setArtifactName("hello"); + request.setArtifactVersion("1.0"); + request.setCsar("xxxx"); + Response response = invokeService(new Gson().toJson(request)); assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); assertThat(response.getEntity(), is("Error converting CSAR artifact to XML model.")); } @Test public void testInvalidJsonFile() throws URISyntaxException, IOException { - Response response = processJsonRequest(getRequestJson("invalid_json_request.json")); + Response response = invokeService("{\"csar:\"xxxx\""); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode())); assertThat(response.getEntity(), is("Malformed request.")); } @Test public void testMissingArtifactName() throws Exception { - Response response = processJsonRequest(getRequestJson("missing_artifact_name_request.json")); + BabelRequest request = new BabelRequest(); + request.setArtifactVersion("1.0"); + request.setCsar(""); + Response response = invokeService(new Gson().toJson(request)); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode())); assertThat(response.getEntity(), is("No artifact name attribute found in the request body.")); } @Test public void testMissingArtifactVersion() throws Exception { - Response response = processJsonRequest(getRequestJson("missing_artifact_version_request.json")); + BabelRequest request = new BabelRequest(); + request.setArtifactName("hello"); + request.setCsar(""); + Response response = invokeService(new Gson().toJson(request)); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode())); assertThat(response.getEntity(), is("No artifact version attribute found in the request body.")); } @Test public void testMissingCsarFile() throws Exception { - Response response = processJsonRequest(getRequestJson("missing_csar_request.json")); + BabelRequest request = new BabelRequest(); + request.setArtifactName("test-name"); + request.setArtifactVersion("1.0"); + Response response = invokeService(new Gson().toJson(request)); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode())); assertThat(response.getEntity(), is("No csar attribute found in the request body.")); } @@ -140,12 +146,16 @@ public class TestGenerateArtifactsServiceImpl { /** * Create a (mocked) HTTPS request and invoke the Babel generate artifacts API. * - * @param resource path to the incoming JSON request + * @param csar * @return the Response from the HTTP API * @throws URISyntaxException if the URI cannot be created * @throws IOException if the resource cannot be loaded */ - private Response processJsonRequest(String jsonString) throws URISyntaxException, IOException { + private Response processJsonRequest(CsarTest csar) throws IOException, URISyntaxException { + String jsonString = csar.getJsonRequest(); + return invokeService(jsonString); + } + private Response invokeService(String jsonString) throws URISyntaxException { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getRequestUri()).thenReturn(new URI("/validate")); // NOSONAR (mocked) Mockito.when(mockUriInfo.getPath(false)).thenReturn("validate"); // URI prefix is stripped by AJSC routing @@ -181,10 +191,6 @@ public class TestGenerateArtifactsServiceImpl { return service.generateArtifacts(mockUriInfo, headers, servletRequest, jsonString); } - private String getRequestJson(String resource) throws IOException, URISyntaxException { - return new ArtifactTestUtils().getRequestJson(resource); - } - private String getResponseJson(String jsonResponse) throws IOException, URISyntaxException { return new ArtifactTestUtils().getResponseJson(jsonResponse); } diff --git a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java new file mode 100644 index 0000000..d884e4f --- /dev/null +++ b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java @@ -0,0 +1,94 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 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. + * 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========================================================= + */ + +package org.onap.aai.babel.testdata; + +import com.google.gson.Gson; +import java.io.IOException; +import java.util.List; +import org.onap.aai.babel.csar.extractor.InvalidArchiveException; +import org.onap.aai.babel.csar.extractor.YamlExtractor; +import org.onap.aai.babel.csar.vnfcatalog.ToscaToCatalogException; +import org.onap.aai.babel.csar.vnfcatalog.VnfVendorImageExtractor; +import org.onap.aai.babel.service.data.BabelArtifact; +import org.onap.aai.babel.service.data.BabelRequest; +import org.onap.aai.babel.util.ArtifactTestUtils; +import org.onap.aai.babel.xml.generator.data.Artifact; +import org.onap.aai.babel.xml.generator.data.GeneratorUtil; + +public enum CsarTest { + // @formatter:off + VNF_VENDOR_CSAR("catalog_csar.csar"), + NO_VNF_CONFIG_CSAR("noVnfConfiguration.csar"), + SD_WAN_CSAR_FILE("service-SdWanServiceTest-csar.csar"), + MISSING_METADATA_CSAR("service-MissingMetadataTest.csar"), + NO_YAML_FILES("noYmlFilesArchive.zip"), + PORT_MIRROR_CSAR("service_PortMirror.csar"), + VNFOD_SERVICE("service-Dev2devnfodservice17July-csar.csar"), + MULTIPLE_VNF_CSAR("catalog_csar_too_many_vnfConfigurations.csar"); + // @formatter:on + + private String filename; + private ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils(); + + CsarTest(String filename) { + this.filename = filename; + } + + public String getName() { + return filename; + } + + public byte[] getContent() throws IOException { + return artifactTestUtils.getCompressedArtifact(filename); + } + + /** + * Extract YAML Artifacts. + * + * @return the extracted artifacts + * @throws InvalidArchiveException if the CSAR is invalid + * @throws IOException for I/O errors + */ + public List extractArtifacts() throws InvalidArchiveException, IOException { + return new YamlExtractor().extract(getContent(), getName(), "v1"); + } + + /** + * Extract VNF Vendor Image Artifacts. + * + * @return the extracted artifacts + * @throws IOException + * @throws ToscaToCatalogException + * + */ + public BabelArtifact extractVnfVendorImages() throws ToscaToCatalogException, IOException { + return new VnfVendorImageExtractor().extract(getContent()); + } + + public String getJsonRequest() throws IOException { + BabelRequest request = new BabelRequest(); + request.setArtifactName(getName()); + request.setArtifactVersion("1.0"); + request.setCsar(new String(GeneratorUtil.encode(getContent()))); + return new Gson().toJson(request); + } +} diff --git a/src/test/resources/compressedArtifacts/Duff.txt b/src/test/resources/compressedArtifacts/Duff.txt deleted file mode 100644 index 51faa6e..0000000 --- a/src/test/resources/compressedArtifacts/Duff.txt +++ /dev/null @@ -1 +0,0 @@ -a bogus file. \ No newline at end of file diff --git a/src/test/resources/jsonFiles/invalid_csar_request.json b/src/test/resources/jsonFiles/invalid_csar_request.json deleted file mode 100644 index f7ecca1..0000000 --- a/src/test/resources/jsonFiles/invalid_csar_request.json +++ /dev/null @@ -1,3 +0,0 @@ -{"csar": "xxxx", - "artifactVersion":"1.0", - "artifactName":"hello"} \ No newline at end of file diff --git a/src/test/resources/response/validNoVnfConfigurationResponse.json b/src/test/resources/response/validNoVnfConfigurationResponse.json index f84488a..67a2fdc 100644 --- a/src/test/resources/response/validNoVnfConfigurationResponse.json +++ b/src/test/resources/response/validNoVnfConfigurationResponse.json @@ -1 +1 @@ -[{"name":"AAI-Vscpaas_Test-service-3.0.xml","type":"MODEL","payload":"\n a8db6285-20ca-4fd3-9c85-e267bdb013f9\n service\n \n \n 7f7f6fa4-275a-488f-8b3e-691a0765d57e\n Vscpaas_Test\n 3.0\n Vscpaas_Test\n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 2e42bac2-318a-410c-b8ff-3b3a31351be7\n \n \n model.model-invariant-id\n b2b88a73-5c55-4984-99dd-a35c55935d14\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n 46b92144-923a-4d20-b85a-3cbd847668a9\n \n \n model.model-invariant-id\n 82194af1-3c2c-485a-8f44-420e22a9eaa4\n \n \n \n \n \n \n \n"},{"name":"AAI-ScpTestVsp..asc_heat-int2..module-0-resource-1.xml","type":"MODEL","payload":"\n 6f288081-b321-47c9-b038-6de70079a3bf\n resource\n \n \n 06258c44-ab48-4b4b-a5db-16892f7d1e76\n ScpTestVsp..asc_heat-int2..module-0\n 1\n \n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n F\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n f6a038c2-820c-42ba-8c2b-375e24e8f932\n \n \n model.model-invariant-id\n 3f4c7204-739b-4bbb-87a7-8a6856439c90\n \n \n \n \n \n F\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n abcc54bc-bb74-49dc-9043-7f7171707545\n \n \n model.model-invariant-id\n 97c26c99-6870-44c1-8a07-1d900d3f4ce6\n \n \n \n \n \n F\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 36200fb5-f251-4f5d-a520-7c5ad5c2cd4b\n \n \n model.model-invariant-id\n bace8d1c-a261-4041-9e37-823117415d0f\n \n \n \n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 5761e0a7-c6df-4d8a-9ebd-b8f445054dec\n \n \n model.model-invariant-id\n 96129eb9-f0de-4e05-8af2-73146473f766\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n 8ecb2c5d-7176-4317-a255-26274edfdd53\n \n \n model.model-invariant-id\n ff69d4e0-a8e8-4108-bdb0-dd63217e63c7\n \n \n \n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 9111f20f-e680-4001-b83f-19a2fc23bfc1\n \n \n model.model-invariant-id\n 3d560d81-57d0-438b-a2a1-5334dba0651a\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n c00563ae-812b-4e62-8330-7c4d0f47088a\n \n \n model.model-invariant-id\n ef86f9c5-2165-44f3-8fc3-96018b609ea5\n \n \n \n \n \n \n \n"},{"name":"AAI-SCP-Test-VSP-resource-1.0.xml","type":"MODEL","payload":"\n b2b88a73-5c55-4984-99dd-a35c55935d14\n resource\n \n \n 2e42bac2-318a-410c-b8ff-3b3a31351be7\n SCP-Test-VSP\n 1.0\n SCP Test VSP\n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 06258c44-ab48-4b4b-a5db-16892f7d1e76\n \n \n model.model-invariant-id\n 6f288081-b321-47c9-b038-6de70079a3bf\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n 93a6166f-b3d5-4f06-b4ba-aed48d009ad9\n \n \n model.model-invariant-id\n acc6edd8-a8d4-4b93-afaa-0994068be14c\n \n \n \n \n \n \n \n"}] +[{"name":"AAI-Vscpaas_Test-service-1.0.xml","type":"MODEL","payload":"\n a8db6285-20ca-4fd3-9c85-e267bdb013f9\n service\n \n \n 7f7f6fa4-275a-488f-8b3e-691a0765d57e\n Vscpaas_Test\n 1.0\n Vscpaas_Test\n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 2e42bac2-318a-410c-b8ff-3b3a31351be7\n \n \n model.model-invariant-id\n b2b88a73-5c55-4984-99dd-a35c55935d14\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n service-instance-version-id\n \n \n model.model-invariant-id\n service-instance-invariant-id\n \n \n \n \n \n \n \n"},{"name":"AAI-ScpTestVsp..asc_heat-int2..module-0-resource-1.xml","type":"MODEL","payload":"\n 6f288081-b321-47c9-b038-6de70079a3bf\n resource\n \n \n 06258c44-ab48-4b4b-a5db-16892f7d1e76\n ScpTestVsp..asc_heat-int2..module-0\n 1\n \n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n F\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n image-version-id\n \n \n model.model-invariant-id\n image-invariant-id\n \n \n \n \n \n F\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n flavor-version-id\n \n \n model.model-invariant-id\n flavor-invariant-id\n \n \n \n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n vnfc-version-id\n \n \n model.model-invariant-id\n vnfc-invariant-id\n \n \n \n \n \n F\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n tenant-version-id\n \n \n model.model-invariant-id\n tenant-invariant-id\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n vserver-version-id\n \n \n model.model-invariant-id\n vserver-invariant-id\n \n \n \n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n l3-network-version-id\n \n \n model.model-invariant-id\n l3-network-invariant-id\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n vf-module-version-id\n \n \n model.model-invariant-id\n vf-module-invariant-id\n \n \n \n \n \n \n \n"},{"name":"AAI-SCP-Test-VSP-resource-1.0.xml","type":"MODEL","payload":"\n b2b88a73-5c55-4984-99dd-a35c55935d14\n resource\n \n \n 2e42bac2-318a-410c-b8ff-3b3a31351be7\n SCP-Test-VSP\n 1.0\n SCP Test VSP\n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 06258c44-ab48-4b4b-a5db-16892f7d1e76\n \n \n model.model-invariant-id\n 6f288081-b321-47c9-b038-6de70079a3bf\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n generic-vnf-version-id\n \n \n model.model-invariant-id\n generic-vnf-invariant-id\n \n \n \n \n \n \n \n"}]