aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-10-21 16:24:14 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-10-21 16:24:14 +0200
commit02dacdfc3f1f47103044375a4adcbb5b18c93ee7 (patch)
tree6a997d3caca1b0ae640f9b4b22740f37a9748b9d /src/test
parent8cb2c97c400b30fb71a89aefaf19f247b450d49f (diff)
Reduce amount of explicit object mapping in babel
- let the framework do the object mapping to BabelRequest Issue-ID: AAI-4022 Change-Id: Ia657c5ce6974b25b85364b2deff3aab34f27d10a Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java33
-rw-r--r--src/test/java/org/onap/aai/babel/testdata/CsarTest.java18
2 files changed, 26 insertions, 25 deletions
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 3070566..27eeb51 100644
--- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
+++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
@@ -96,7 +96,7 @@ public class TestGenerateArtifactsServiceImpl {
*/
@Test
public void testGenerateArtifactsWithoutRequestId() throws URISyntaxException, IOException {
- Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequest(), Optional.empty());
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getBabelRequest(), Optional.empty());
assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getEntity(), is(getResponseJson("response.json")));
}
@@ -111,7 +111,7 @@ public class TestGenerateArtifactsServiceImpl {
*/
@Test
public void testGenerateArtifactsWithoutMinorArtifactVersion() throws URISyntaxException, IOException {
- Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("1"),
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getBabelRequestWithArtifactVersion("1"),
Optional.of("transaction-id"));
assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getEntity(), is(getResponseJson("response.json")));
@@ -127,7 +127,7 @@ public class TestGenerateArtifactsServiceImpl {
*/
@Test
public void testGenerateArtifactsWithInvalidArtifactVersion() throws URISyntaxException, IOException {
- Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("a"),
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getBabelRequestWithArtifactVersion("a"),
Optional.of("transaction-id"));
assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getEntity(), is(getResponseJson("response.json")));
@@ -144,7 +144,7 @@ public class TestGenerateArtifactsServiceImpl {
*/
@Test
public void testGenerateArtifactsWithArtifactVerLessThan1() throws URISyntaxException, IOException {
- Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("0.1"),
+ Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getBabelRequestWithArtifactVersion("0.1"),
Optional.of("transaction-id"));
assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getEntity(), is(getResponseJson("responseWithVersionLessThan1.json")));
@@ -187,24 +187,17 @@ public class TestGenerateArtifactsServiceImpl {
request.setArtifactName("hello");
request.setArtifactVersion("1.0");
request.setCsar("xxxx");
- Response response = invokeService(new Gson().toJson(request));
+ Response response = invokeService(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 = invokeService("{\"csar:\"xxxx\"");
- assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode()));
- assertThat(response.getEntity(), is("Malformed request."));
- }
-
- @Test
public void testMissingArtifactName() throws Exception {
BabelRequest request = new BabelRequest();
request.setArtifactVersion("1.0");
request.setCsar("");
- Response response = invokeService(new Gson().toJson(request));
+ Response response = invokeService(request);
assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode()));
assertThat(response.getEntity(), is("No artifact name attribute found in the request body."));
}
@@ -214,7 +207,7 @@ public class TestGenerateArtifactsServiceImpl {
BabelRequest request = new BabelRequest();
request.setArtifactName("hello");
request.setCsar("");
- Response response = invokeService(new Gson().toJson(request));
+ Response response = invokeService(request);
assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode()));
assertThat(response.getEntity(), is("No artifact version attribute found in the request body."));
}
@@ -224,7 +217,7 @@ public class TestGenerateArtifactsServiceImpl {
BabelRequest request = new BabelRequest();
request.setArtifactName("test-name");
request.setArtifactVersion("1.0");
- Response response = invokeService(new Gson().toJson(request));
+ Response response = invokeService(request);
assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode()));
assertThat(response.getEntity(), is("No csar attribute found in the request body."));
}
@@ -244,7 +237,7 @@ public class TestGenerateArtifactsServiceImpl {
*/
private Response processJsonRequest(CsarTest csar)
throws URISyntaxException, IOException {
- return invokeService(csar.getJsonRequest(), Optional.of("transaction-id"));
+ return invokeService(csar.getBabelRequest(), Optional.of("transaction-id"));
}
/**
@@ -256,8 +249,8 @@ public class TestGenerateArtifactsServiceImpl {
* @throws URISyntaxException
* if the URI cannot be created
*/
- private Response invokeService(String jsonRequest) throws URISyntaxException {
- return invokeService(jsonRequest, Optional.of("transaction-id"));
+ private Response invokeService(BabelRequest babelRequest) throws URISyntaxException {
+ return invokeService(babelRequest, Optional.of("transaction-id"));
}
/**
@@ -273,7 +266,7 @@ public class TestGenerateArtifactsServiceImpl {
* @throws URISyntaxException
* if the URI cannot be created
*/
- private Response invokeService(String jsonString, Optional<String> transactionId)
+ private Response invokeService(BabelRequest babelRequest, Optional<String> transactionId)
throws URISyntaxException {
UriInfo mockUriInfo = Mockito.mock(UriInfo.class);
Mockito.when(mockUriInfo.getRequestUri()).thenReturn(new URI("/validate")); // NOSONAR (mocked)
@@ -310,7 +303,7 @@ public class TestGenerateArtifactsServiceImpl {
servletRequest.setAttribute("javax.servlet.request.cipher_suite", "");
GenerateArtifactsControllerImpl service = new GenerateArtifactsControllerImpl(gson);
- return service.generateArtifacts(mockUriInfo, headers, servletRequest, jsonString);
+ return service.generateArtifacts(babelRequest);
}
private String getResponseJson(String jsonResponse) throws IOException, URISyntaxException {
diff --git a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
index 461e75c..c20e554 100644
--- a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
+++ b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
@@ -96,31 +96,39 @@ public enum CsarTest {
/**
* Create a BabelRequest containing the encoded CSAR content.
- *
+ *
* @return a new Babel request for this CSAR
* @throws IOException
* if an I/O exception occurs
*/
public String getJsonRequest() throws IOException {
+ return new Gson().toJson(getBabelRequest());
+ }
+
+ public BabelRequest getBabelRequest() 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);
+ return request;
}
-
+
/**
* Create a BabelRequest containing the encoded CSAR content by passing in the artifact version.
- *
+ *
* @return a new Babel request for this CSAR
* @throws IOException
* if an I/O exception occurs
*/
public String getJsonRequestWithArtifactVersion(String artifactVersion) throws IOException {
+ BabelRequest babelRequest = getBabelRequestWithArtifactVersion(artifactVersion);
+ return new Gson().toJson(babelRequest);
+ }
+ public BabelRequest getBabelRequestWithArtifactVersion(String artifactVersion) throws IOException {
BabelRequest request = new BabelRequest();
request.setArtifactName(getName());
request.setArtifactVersion(artifactVersion);
request.setCsar(new String(GeneratorUtil.encode(getContent())));
- return new Gson().toJson(request);
+ return request;
}
}