diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-01-09 19:28:36 +0100 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-01-10 14:07:41 +0100 |
commit | 1d77fc5b646f3c3a9a0f14dba5218d7f866e48ba (patch) | |
tree | ace6828cfa3d5b97a26a7df3584a0be6a7ae87c2 | |
parent | 8c73a2f4ebf8067e630ce7525183f75bbf8a9bce (diff) |
Return an index of invalid bulk operation if there are missing parameters on request
Catch AAIException on AAI Bulk poplulateIntrospectors method to prepare an exception body with failing operation number.
Issue-ID: AAI-3722
Change-Id: I38b2e1c802ae7f2843cda5c188365890a86f65af
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
3 files changed, 32 insertions, 8 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java index 1b274b9..900da96 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java @@ -213,7 +213,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { /** * Builds the response - * + * * @param transaction the input transactions * @param results the response of all of he operations * @return TansactionResponse obj representing the result of the transaction @@ -242,7 +242,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { /** * Generate one DBRequest per BulkOperation - * + * * @param headers request headers * @param transId transaction id * @param bulkOperations operations to convert @@ -268,7 +268,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { /** * Sets the uriquery for each bulk operation - * + * * @param bulkOperations operations to generate queries for * @param dbEngine engine for query builder generation * @throws AAIException thrown for issues with generating uri query @@ -289,7 +289,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { /** * Sets the introspector for each bulk operation. requires that uriquery is set per operation - * + * * @param bulkOperations operations to generate introspector for * @param loader Loader for generating introspector * @throws AAIException thrown for issues with generating introspector @@ -315,6 +315,8 @@ public class BulkSingleTransactionConsumer extends RESTAPI { } bulkOperation.setIntrospector(obj); } + } catch (AAIException e) { + throw new AAIException(e.getCode(), "Error with operation " + i + ": " + e.getMessage()); } catch (UnsupportedEncodingException e) { throw new AAIException("AAI_3000", String.format(objectUnMarshallMsg, i, bulkOperation.getRawReq())); } @@ -327,7 +329,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { * - Integer.MAX_VALUE if override limit is configured * - Property in aaiconfig * - 30 by default - * + * * @param headers request header */ private void setOperationCount(HttpHeaders headers) { @@ -348,7 +350,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { /** * Converts the request transaction into a list of bulk operations - * + * * @param transaction transaction to extract bulk operations from * @return list of bulk operations */ @@ -381,7 +383,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { /** * Map action to httpmethod - * + * * @param action action to be mapped * @param uri uri of the action * @return HttpMethod thats action/uri maps to @@ -415,7 +417,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI { * - action is provided and correct. * - uri exists * - body exists - * + * * @param transaction parsed payload * @throws AAIException with the violations in the msg */ diff --git a/aai-resources/src/test/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumerTest.java index 7629178..fb9f13f 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumerTest.java @@ -354,6 +354,19 @@ public class BulkSingleTransactionConsumerTest extends BulkProcessorTestAbstract assertEquals("Request success", Response.Status.CREATED.getStatusCode(), response.getStatus()); } + @Test + public void invalidNodeCreationPaylodTest() throws IOException { + String payload = getBulkPayload("single-transaction/put-complex-with-missing-properties") + .replaceAll("<methodName>", name.getMethodName()); + Response response = executeRequest(payload); + + assertEquals("Request fails with 400", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + assertThat("Response contains correct index of failed operation.", response.getEntity().toString(), + containsString("Error with operation 0")); + assertThat("Response contains information about missing properties.", response.getEntity().toString(), + containsString("Missing required property:")); + } + protected Response executeRequest(String finalPayload) { MockHttpServletRequest mockReq = new MockHttpServletRequest(HttpMethod.POST, "http://www.test.com"); diff --git a/aai-resources/src/test/resources/payloads/bulk/single-transaction/put-complex-with-missing-properties.json b/aai-resources/src/test/resources/payloads/bulk/single-transaction/put-complex-with-missing-properties.json new file mode 100644 index 0000000..b371583 --- /dev/null +++ b/aai-resources/src/test/resources/payloads/bulk/single-transaction/put-complex-with-missing-properties.json @@ -0,0 +1,9 @@ +{ + "operations": [ + { + "action": "put", + "uri": "cloud-infrastructure/complexes/complex/complex-<methodName>", + "body": {} + } + ] +}
\ No newline at end of file |