diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2018-08-16 15:14:07 +0100 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2018-08-16 15:17:09 +0100 |
commit | 4cef44f73015d9f3e39a1249e7244fc9266f5d1b (patch) | |
tree | d8c0b2bee41190b2753c032d9cbe006f48b1d261 /src | |
parent | 90a8e74df9e1c89da4bb01bd5769c5e428285965 (diff) |
Additional VNF Configuration test scenarios
Add test cases for both 0 and 2 VNF Configurations in the input CSAR file
Issue-ID: AAI-1250
Change-Id: I0cae09f876d7bbb08cbe48019220e1836e4b7fca
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src')
4 files changed, 44 insertions, 8 deletions
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 de5ea3f..49784c1 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 @@ -18,9 +18,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.csar.vnfcatalog; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; @@ -57,6 +59,18 @@ public class VnfVendorImageExtractorTest { } @Test + public void createVendorImageMappingsMoreThanOneVnfConfigurationExists() throws IOException { + try { + extractArtifact("catalog_csar_too_many_vnfConfigurations.csar"); + } catch (Exception e) { + assertThat(e, is(instanceOf(ToscaToCatalogException.class))); + assertThat(e.getLocalizedMessage(), + is(equalTo("An error occurred trying to get the vnf catalog from a csar file. " + + "2 vnfConfigurations were found in the csar file and only one is allowed."))); + } + } + + @Test public void createVendorImageMappingsNoVnfConfigurationExists() throws IOException, ToscaToCatalogException { assertThat(extractArtifact("noVnfConfiguration.csar"), is(nullValue())); } 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 c770c60..66a36ad 100644 --- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java +++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java @@ -23,6 +23,7 @@ package org.onap.aai.babel.service; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import com.google.gson.Gson; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -42,7 +43,9 @@ import org.junit.runner.RunWith; 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.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; @@ -75,42 +78,61 @@ public class TestGenerateArtifactsServiceImpl { @Test public void testGenerateArtifacts() throws Exception { - Response response = processJsonRequest("success_request_vnf_catalog.json"); + Response response = processJsonRequest(getRequestJson("success_request_vnf_catalog.json")); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); assertThat(response.getEntity(), is(getResponseJson("response.json"))); } + /** + * No VNF Configuration exists. + * + * @throws Exception + */ + @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)); + 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("invalid_csar_request.json"); + Response response = processJsonRequest(getRequestJson("invalid_csar_request.json")); 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("invalid_json_request.json"); + Response response = processJsonRequest(getRequestJson("invalid_json_request.json")); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode())); assertThat(response.getEntity(), is("Malformed request.")); } @Test public void testMissingArtifactName() throws Exception { - Response response = processJsonRequest("missing_artifact_name_request.json"); + Response response = processJsonRequest(getRequestJson("missing_artifact_name_request.json")); 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("missing_artifact_version_request.json"); + Response response = processJsonRequest(getRequestJson("missing_artifact_version_request.json")); 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("missing_csar_request.json"); + Response response = processJsonRequest(getRequestJson("missing_csar_request.json")); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode())); assertThat(response.getEntity(), is("No csar attribute found in the request body.")); } @@ -123,7 +145,7 @@ public class TestGenerateArtifactsServiceImpl { * @throws URISyntaxException if the URI cannot be created * @throws IOException if the resource cannot be loaded */ - private Response processJsonRequest(String resource) throws URISyntaxException, IOException { + private Response processJsonRequest(String jsonString) throws URISyntaxException, IOException { 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 @@ -156,7 +178,6 @@ public class TestGenerateArtifactsServiceImpl { servletRequest.setAttribute("javax.servlet.request.cipher_suite", ""); GenerateArtifactsServiceImpl service = new GenerateArtifactsServiceImpl(auth); - String jsonString = getRequestJson(resource); return service.generateArtifacts(mockUriInfo, headers, servletRequest, jsonString); } diff --git a/src/test/resources/compressedArtifacts/catalog_csar_too_many_vnfConfigurations.csar b/src/test/resources/compressedArtifacts/catalog_csar_too_many_vnfConfigurations.csar Binary files differnew file mode 100644 index 0000000..7fcc408 --- /dev/null +++ b/src/test/resources/compressedArtifacts/catalog_csar_too_many_vnfConfigurations.csar diff --git a/src/test/resources/response/validNoVnfConfigurationResponse.json b/src/test/resources/response/validNoVnfConfigurationResponse.json new file mode 100644 index 0000000..f84488a --- /dev/null +++ b/src/test/resources/response/validNoVnfConfigurationResponse.json @@ -0,0 +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>"}] |