From: mark.j.leonard Date: Thu, 16 Aug 2018 14:14:07 +0000 (+0100) Subject: Additional VNF Configuration test scenarios X-Git-Tag: 1.3.0~13^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fbabel.git;a=commitdiff_plain;h=4cef44f73015d9f3e39a1249e7244fc9266f5d1b 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 --- 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; @@ -56,6 +58,18 @@ public class VnfVendorImageExtractorTest { extractArtifact("Duff.txt"); } + @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 new file mode 100644 index 0000000..7fcc408 Binary files /dev/null and b/src/test/resources/compressedArtifacts/catalog_csar_too_many_vnfConfigurations.csar differ 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":"\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"}]