From f1dc7620477e26db40a91c43ded1dbfa8fe3ccc0 Mon Sep 17 00:00:00 2001 From: ed852m Date: Thu, 14 Mar 2019 11:18:48 +0000 Subject: Handle unexpected HTTP return codes Issue-ID: AAI-2263 Change-Id: I2510b7a2630918ffe17efbbf813c3e43b0b44d34 Signed-off-by: ed852m --- .../entity/model/TestModelArtifactHandler.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/test/java/org') diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java index 2a951a8..b7a8cf2 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java @@ -120,5 +120,50 @@ public class TestModelArtifactHandler { assertThat(pushed, is(true)); handler.rollback(artifacts, "", aaiClient); } + + @Test + public void testPushNewModelsBadRequest() { + when(config.getAaiBaseUrl()).thenReturn(""); + when(config.getAaiModelUrl(any())).thenReturn(""); + when(config.getAaiNamedQueryUrl(any())).thenReturn(""); + + OperationResult getResult = mock(OperationResult.class); + when(aaiClient.getResource(any(), any(), any())).thenReturn(getResult); + when(getResult.getResultCode()).thenReturn(Response.Status.NOT_FOUND.getStatusCode()); + + OperationResult putResult = mock(OperationResult.class); + when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getResultCode()).thenReturn(Response.Status.BAD_REQUEST.getStatusCode()); + + checkRollback(Collections.singletonList(new ModelArtifact())); + } + + @Test + public void testBadRequestResourceModelResult() { + when(config.getAaiBaseUrl()).thenReturn(""); + when(config.getAaiModelUrl(any())).thenReturn(""); + + OperationResult operationResult = mock(OperationResult.class); + when(aaiClient.getResource(any(), any(), any())).thenReturn(operationResult); + when(operationResult.getResultCode()).thenReturn(Response.Status.BAD_REQUEST.getStatusCode()); + + checkRollback(Collections.singletonList(new ModelArtifact())); + } + + @Test + public void testNullResourceModelResult() { + when(config.getAaiBaseUrl()).thenReturn(""); + when(config.getAaiModelUrl(any())).thenReturn(""); + when(aaiClient.getResource(any(), any(), any())).thenReturn(null); + + checkRollback(Collections.singletonList(new ModelArtifact())); + } + + private void checkRollback(List artifacts) { + ModelArtifactHandler handler = new ModelArtifactHandler(config); + boolean pushed = handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); + assertThat(pushed, is(false)); + handler.rollback(artifacts, "", aaiClient); + } } -- cgit