X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fentity%2Fmodel%2FTestModelArtifactHandler.java;h=5ccd1d2cc44e6c78f4463d428e5874422b3e1d5c;hb=b984f4c39231a32dd53d02e60741c7d32822aad0;hp=82990de0f54d4e6c42e9a0313f2e563bbc120db4;hpb=6e4f04afea4c2d07fdd9c15eda38438c7baeb308;p=aai%2Fmodel-loader.git 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 82990de..5ccd1d2 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 @@ -1,5 +1,5 @@ /** - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. @@ -21,7 +21,11 @@ package org.onap.aai.modelloader.entity.model; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.isEmptyString; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,6 +65,7 @@ public class TestModelArtifactHandler { ModelArtifactHandler handler = new ModelArtifactHandler(config); handler.pushArtifacts(Collections.emptyList(), "", Collections.emptyList(), aaiClient); handler.rollback(Collections.emptyList(), "", aaiClient); + assertTrue(true); } @Test @@ -72,6 +77,7 @@ public class TestModelArtifactHandler { List artifacts = Collections.singletonList(new ModelArtifact()); handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); handler.rollback(Collections.emptyList(), "", aaiClient); + assertThat(artifacts, hasSize(1)); } @Test @@ -89,7 +95,7 @@ public class TestModelArtifactHandler { ModelArtifactHandler handler = new ModelArtifactHandler(config); boolean pushed = handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); - assertThat(pushed, is(true)); + assertTrue(pushed); handler.rollback(artifacts, "", aaiClient); } @@ -120,5 +126,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); + } }