+ new ArtifactTestUtils().setGeneratorSystemProperties();
+ }
+
+ /**
+ * Test with a valid request (and valid CSAR content) by calling the Service implementation directly using a mocked
+ * HTTPS request.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifacts() throws URISyntaxException, IOException {
+ Response response = processJsonRequest(CsarTest.VNF_VENDOR_CSAR, auth);
+ assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getEntity(), is(getResponseJson("response.json")));
+ }
+
+ /**
+ * Test with a valid request that has no Transaction ID header value.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifactsWithoutRequestId() throws URISyntaxException, IOException {
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequest(), Optional.empty(), auth);
+ assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getEntity(), is(getResponseJson("response.json")));
+ }
+
+ /**
+ * Test with a valid request without Minor Artifact version.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifactsWithoutMinorArtifactVersion() throws URISyntaxException, IOException {
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("1"),
+ Optional.of("transaction-id"), auth);
+ assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getEntity(), is(getResponseJson("response.json")));
+ }
+
+ /**
+ * Test with a valid request without Minor Artifact version.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifactsWithInvalidArtifactVersion() throws URISyntaxException, IOException {
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("a"),
+ Optional.of("transaction-id"), auth);
+ assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getEntity(), is(getResponseJson("response.json")));
+ }
+
+
+ /**
+ * Test with a valid request with Artifact version less than 1.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifactsWithArtifactVerLessThan1() throws URISyntaxException, IOException {
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("0.1"),
+ Optional.of("transaction-id"), auth);
+ assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getEntity(), is(getResponseJson("responseWithVersionLessThan1.json")));
+ }
+
+
+ /**
+ * Test with a valid request, using a CSAR file that has no VNF configuration present.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifactsWithoutVnfConfiguration() throws IOException, URISyntaxException {
+ Response response = processJsonRequest(CsarTest.NO_VNF_CONFIG_CSAR, auth);
+ assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getEntity(), is(getResponseJson("validNoVnfConfigurationResponse.json")));
+ }
+
+ /**
+ * Test for a valid request with invalid CSAR file content.
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
+ */
+ @Test
+ public void testGenerateArtifactsInvalidCsar() throws IOException, URISyntaxException {
+ Response response = processJsonRequest(CsarTest.MULTIPLE_VNF_CSAR, auth);
+ assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ assertThat(response.getEntity().toString(), containsString("VNF catalog"));
+ }
+
+ @Test
+ public void testUninitializedService() throws IOException, URISyntaxException, AAIAuthException {
+ AAIMicroServiceAuth uninitializedAuth = Mockito.mock(AAIMicroServiceAuth.class);
+ Mockito.when(uninitializedAuth.validateRequest(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenThrow(new AAIAuthException("test"));
+ Response response = processJsonRequest(CsarTest.NO_VNF_CONFIG_CSAR, uninitializedAuth);
+ assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ assertThat(response.getEntity().toString(), containsString("check the Babel service logs"));
+ }
+
+ @Test
+ public void testUnauthorizedRequest() throws IOException, URISyntaxException, AAIAuthException {
+ AAIMicroServiceAuth uninitializedAuth = Mockito.mock(AAIMicroServiceAuth.class);
+ Mockito.when(uninitializedAuth.validateRequest(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(false);
+ Response response = processJsonRequest(CsarTest.NO_VNF_CONFIG_CSAR, uninitializedAuth);
+ assertThat(response.getStatus(), is(Response.Status.UNAUTHORIZED.getStatusCode()));
+ assertThat(response.getEntity().toString(), containsString("User not authorized"));