diff options
9 files changed, 185 insertions, 126 deletions
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<Artifact> ymlFiles = extractArchive("service-SdWanServiceTest-csar.csar"); + final List<Artifact> ymlFiles = CsarTest.SD_WAN_CSAR_FILE.extractArtifacts(); List<String> 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<Artifact> 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<Artifact> ymlFiles = new YamlExtractor().extract(csarBytes, csarResourceName, "1.0"); - + List<Artifact> ymlFiles = CsarTest.VNF_VENDOR_CSAR.extractArtifacts(); Map<String, String> 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<String, String> expectedXmlFiles = createExpectedXmlFiles(); - List<BabelArtifact> 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<String> 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<String, String> expectedXmlFiles = createExpectedXmlFiles(); - List<BabelArtifact> 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<String> 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<String> matches(final String expected) { @@ -189,21 +168,22 @@ public class CsarToXmlConverterTest { }; } - private Map<String, String> createExpectedXmlFiles() throws IOException { + private Map<String, String> createExpectedXmlFiles(List<String> filesToLoad) throws IOException { Map<String, String> xmlMap = new HashMap<>(); - - List<String> 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<String, String> expectedXmlFiles, CsarTest csarFile) + throws CsarConverterException, IOException { + List<BabelArtifact> 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<Artifact> 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":"<model xmlns=\"http://org.onap.aai.inventory/v14\">\n <model-invariant-id>a8db6285-20ca-4fd3-9c85-e267bdb013f9</model-invariant-id>\n <model-type>service</model-type>\n <model-vers>\n <model-ver>\n <model-version-id>7f7f6fa4-275a-488f-8b3e-691a0765d57e</model-version-id>\n <model-name>Vscpaas_Test</model-name>\n <model-version>3.0</model-version>\n <model-description>Vscpaas_Test</model-description>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>2e42bac2-318a-410c-b8ff-3b3a31351be7</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>b2b88a73-5c55-4984-99dd-a35c55935d14</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>46b92144-923a-4d20-b85a-3cbd847668a9</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>82194af1-3c2c-485a-8f44-420e22a9eaa4</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n </model-ver>\n </model-vers>\n</model>"},{"name":"AAI-ScpTestVsp..asc_heat-int2..module-0-resource-1.xml","type":"MODEL","payload":"<model xmlns=\"http://org.onap.aai.inventory/v14\">\n <model-invariant-id>6f288081-b321-47c9-b038-6de70079a3bf</model-invariant-id>\n <model-type>resource</model-type>\n <model-vers>\n <model-ver>\n <model-version-id>06258c44-ab48-4b4b-a5db-16892f7d1e76</model-version-id>\n <model-name>ScpTestVsp..asc_heat-int2..module-0</model-name>\n <model-version>1</model-version>\n <model-description></model-description>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>F</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>f6a038c2-820c-42ba-8c2b-375e24e8f932</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>3f4c7204-739b-4bbb-87a7-8a6856439c90</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>F</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>abcc54bc-bb74-49dc-9043-7f7171707545</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>97c26c99-6870-44c1-8a07-1d900d3f4ce6</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>F</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>36200fb5-f251-4f5d-a520-7c5ad5c2cd4b</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>bace8d1c-a261-4041-9e37-823117415d0f</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>5761e0a7-c6df-4d8a-9ebd-b8f445054dec</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>96129eb9-f0de-4e05-8af2-73146473f766</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>8ecb2c5d-7176-4317-a255-26274edfdd53</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>ff69d4e0-a8e8-4108-bdb0-dd63217e63c7</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n </model-ver>\n </model-vers>\n</model>"},{"name":"AAI-SCP-Test-VSP-resource-1.0.xml","type":"MODEL","payload":"<model xmlns=\"http://org.onap.aai.inventory/v14\">\n <model-invariant-id>b2b88a73-5c55-4984-99dd-a35c55935d14</model-invariant-id>\n <model-type>resource</model-type>\n <model-vers>\n <model-ver>\n <model-version-id>2e42bac2-318a-410c-b8ff-3b3a31351be7</model-version-id>\n <model-name>SCP-Test-VSP</model-name>\n <model-version>1.0</model-version>\n <model-description>SCP Test VSP</model-description>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>06258c44-ab48-4b4b-a5db-16892f7d1e76</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>6f288081-b321-47c9-b038-6de70079a3bf</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>93a6166f-b3d5-4f06-b4ba-aed48d009ad9</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>acc6edd8-a8d4-4b93-afaa-0994068be14c</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n </model-ver>\n </model-vers>\n</model>"}] +[{"name":"AAI-Vscpaas_Test-service-1.0.xml","type":"MODEL","payload":"<model xmlns=\"http://org.onap.aai.inventory/v14\">\n <model-invariant-id>a8db6285-20ca-4fd3-9c85-e267bdb013f9</model-invariant-id>\n <model-type>service</model-type>\n <model-vers>\n <model-ver>\n <model-version-id>7f7f6fa4-275a-488f-8b3e-691a0765d57e</model-version-id>\n <model-name>Vscpaas_Test</model-name>\n <model-version>1.0</model-version>\n <model-description>Vscpaas_Test</model-description>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>2e42bac2-318a-410c-b8ff-3b3a31351be7</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>b2b88a73-5c55-4984-99dd-a35c55935d14</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>service-instance-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>service-instance-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n </model-ver>\n </model-vers>\n</model>"},{"name":"AAI-ScpTestVsp..asc_heat-int2..module-0-resource-1.xml","type":"MODEL","payload":"<model xmlns=\"http://org.onap.aai.inventory/v14\">\n <model-invariant-id>6f288081-b321-47c9-b038-6de70079a3bf</model-invariant-id>\n <model-type>resource</model-type>\n <model-vers>\n <model-ver>\n <model-version-id>06258c44-ab48-4b4b-a5db-16892f7d1e76</model-version-id>\n <model-name>ScpTestVsp..asc_heat-int2..module-0</model-name>\n <model-version>1</model-version>\n <model-description></model-description>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>F</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>image-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>image-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>F</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>flavor-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>flavor-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>vnfc-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>vnfc-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>F</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>tenant-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>tenant-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>vserver-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>vserver-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>l3-network-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>l3-network-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>vf-module-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>vf-module-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n </model-ver>\n </model-vers>\n</model>"},{"name":"AAI-SCP-Test-VSP-resource-1.0.xml","type":"MODEL","payload":"<model xmlns=\"http://org.onap.aai.inventory/v14\">\n <model-invariant-id>b2b88a73-5c55-4984-99dd-a35c55935d14</model-invariant-id>\n <model-type>resource</model-type>\n <model-vers>\n <model-ver>\n <model-version-id>2e42bac2-318a-410c-b8ff-3b3a31351be7</model-version-id>\n <model-name>SCP-Test-VSP</model-name>\n <model-version>1.0</model-version>\n <model-description>SCP Test VSP</model-description>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements>\n <model-element>\n <new-data-del-flag>T</new-data-del-flag>\n <cardinality>unbounded</cardinality>\n <model-elements/>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>06258c44-ab48-4b4b-a5db-16892f7d1e76</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>6f288081-b321-47c9-b038-6de70079a3bf</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n <relationship-list>\n <relationship>\n <related-to>model-ver</related-to>\n <relationship-data>\n <relationship-key>model-ver.model-version-id</relationship-key>\n <relationship-value>generic-vnf-version-id</relationship-value>\n </relationship-data>\n <relationship-data>\n <relationship-key>model.model-invariant-id</relationship-key>\n <relationship-value>generic-vnf-invariant-id</relationship-value>\n </relationship-data>\n </relationship>\n </relationship-list>\n </model-element>\n </model-elements>\n </model-ver>\n </model-vers>\n</model>"}] |