Search in sources :

Example 1 with SingleTransactionResponse

use of org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse in project so by onap.

the class AAISingleTransactionClientTest method testFailure.

@Test
public void testFailure() throws IOException {
    AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
    SingleTransactionResponse expected = mapper.readValue(this.getJson("sample-response-failure.json"), SingleTransactionResponse.class);
    Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
    assertThat(expected.getOperationResponses().size(), greaterThan(0));
    assertThat(errorMessage.isPresent(), equalTo(true));
}
Also used : SingleTransactionResponse(org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse) Test(org.junit.Test)

Example 2 with SingleTransactionResponse

use of org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse in project so by onap.

the class AAISingleTransactionClient method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.onap.aaiclient.client.aai.GraphInventoryTransactionClient#execute()
     */
@Override
public void execute() throws BulkProcessFailed {
    try {
        if (!this.request.getOperations().isEmpty()) {
            RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION));
            SingleTransactionResponse response = client.post(this.request, SingleTransactionResponse.class);
            if (response != null) {
                final Optional<String> errorMessage = this.locateErrorMessages(response);
                if (errorMessage.isPresent()) {
                    throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
                }
            } else {
                throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
            }
        }
    } finally {
        this.request.getOperations().clear();
        this.actionCount = 0;
    }
}
Also used : SingleTransactionResponse(org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse) RestClient(org.onap.so.client.RestClient) BulkProcessFailed(org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)

Example 3 with SingleTransactionResponse

use of org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse in project so by onap.

the class AAISingleTransactionClientTest method testSuccessResponse.

@Test
public void testSuccessResponse() throws IOException {
    AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
    SingleTransactionResponse expected = mapper.readValue(this.getJson("sample-response.json"), SingleTransactionResponse.class);
    Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
    assertThat(expected.getOperationResponses().size(), greaterThan(0));
    assertThat(errorMessage.isPresent(), equalTo(false));
}
Also used : SingleTransactionResponse(org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse) Test(org.junit.Test)

Aggregations

SingleTransactionResponse (org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse)3 Test (org.junit.Test)2 BulkProcessFailed (org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)1 RestClient (org.onap.so.client.RestClient)1