Upgrade spring-boot to 2.7.X in model-loader
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / entity / model / TestModelArtifactHandler.java
index 5ccd1d2..7a630b5 100644 (file)
 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.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import javax.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
 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
@@ -55,9 +53,9 @@ public class TestModelArtifactHandler {
     @Mock
     private AaiRestClient aaiClient;
 
-    @Before
+    @BeforeEach
     public void setupMocks() {
-        MockitoAnnotations.initMocks(this);
+        MockitoAnnotations.openMocks(this);
     }
 
     @Test
@@ -68,26 +66,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<Artifact> 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<Artifact> artifacts = new ArrayList<>();
         Artifact artifact = new ModelArtifact();
@@ -105,13 +91,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<Artifact> artifacts = new ArrayList<>();
         artifacts.add(new ModelArtifact());
@@ -133,13 +119,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 +135,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()));
     }