X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fentity%2Fmodel%2FTestModelArtifactHandler.java;fp=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fentity%2Fmodel%2FTestModelArtifactHandler.java;h=b16c8a0fa0d3238b90cfc182d737f8599d04e31c;hb=93a7defb8a10ac29f97d3cfd860ca12a629bdc41;hp=177a8d264664e886dc45eb575b3b8ea4783ad573;hpb=8204d232f8cc37e28561ee18b60806c7b3f5f783;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 177a8d2..b16c8a0 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 @@ -32,8 +32,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import javax.ws.rs.core.Response; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -41,7 +39,8 @@ import org.mockito.MockitoAnnotations; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.onap.aai.restclient.client.OperationResult; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; /** * Test the Model Artifact Handler using Mocks @@ -68,26 +67,14 @@ public class TestModelArtifactHandler { assertTrue(true); } - @Test - public void testSingleItemList() { - when(config.getAaiBaseUrl()).thenReturn(""); - when(config.getAaiModelUrl(any())).thenReturn(""); - - ModelArtifactHandler handler = new ModelArtifactHandler(config); - List artifacts = Collections.singletonList(new ModelArtifact()); - handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); - handler.rollback(Collections.emptyList(), "", aaiClient); - assertThat(artifacts, hasSize(1)); - } - @Test public void testPushExistingModelsWithRollback() { 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.OK.getStatusCode()); + ResponseEntity operationResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(operationResult); + when(operationResult.getStatusCode()).thenReturn(HttpStatus.OK); List artifacts = new ArrayList<>(); Artifact artifact = new ModelArtifact(); @@ -105,13 +92,13 @@ public class TestModelArtifactHandler { 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()); + ResponseEntity getResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(getResult); + when(getResult.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND); - OperationResult putResult = mock(OperationResult.class); - when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); - when(putResult.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode()); + ResponseEntity putResult = mock(ResponseEntity.class); + when(aaiClient.putResource(any(), any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getStatusCode()).thenReturn(HttpStatus.CREATED); List artifacts = new ArrayList<>(); artifacts.add(new ModelArtifact()); @@ -133,13 +120,13 @@ public class TestModelArtifactHandler { 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()); + ResponseEntity getResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(getResult); + when(getResult.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND); - OperationResult putResult = mock(OperationResult.class); - when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); - when(putResult.getResultCode()).thenReturn(Response.Status.BAD_REQUEST.getStatusCode()); + ResponseEntity putResult = mock(ResponseEntity.class); + when(aaiClient.putResource(any(), any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST); checkRollback(Collections.singletonList(new ModelArtifact())); } @@ -149,18 +136,9 @@ public class TestModelArtifactHandler { 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); + ResponseEntity operationResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(operationResult); + when(operationResult.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST); checkRollback(Collections.singletonList(new ModelArtifact())); }