Refactor Prov DB handling
[dmaap/datarouter.git] / datarouter-prov / src / test / java / org / onap / dmaap / datarouter / provisioning / SynchronizerTaskTest.java
index 79d8389..7ebe45d 100755 (executable)
@@ -29,20 +29,14 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.powermock.api.mockito.PowerMockito.when;
 
-import com.att.eelf.configuration.EELFManager;
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.StatusLine;
@@ -59,8 +53,8 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
 import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet;
+import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask;
 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PowerMockIgnore;
@@ -84,13 +78,8 @@ public class SynchronizerTaskTest {
     @Mock
     private CloseableHttpResponse response;
 
-    @Mock
-    private ByteArrayOutputStream byteArrayOutputStream;
-
     private SynchronizerTask synchronizerTask;
 
-    private ExecutorService executorService;
-
     private static EntityManagerFactory emf;
     private static EntityManager em;
 
@@ -124,19 +113,15 @@ public class SynchronizerTaskTest {
 
         synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
         doReturn(2).when(synchronizerTask).lookupState();
-
-        executorService = Executors.newSingleThreadExecutor();
-        executorService.execute(synchronizerTask);
     }
 
     @After
-    public void tearDown() throws InterruptedException {
-        executorService.shutdown();
-        executorService.awaitTermination(2, TimeUnit.SECONDS);
+    public void tearDown() {
     }
 
     @Test
-    public void Given_Synch_Task_readRemoteLoglist_Called_And_Valid_BitSet_Returned_Success() throws Exception {
+    public void Given_Synch_Task_readRemoteLoglist_Called_And_Valid_BitSet_Returned_Success()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
         Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
@@ -146,7 +131,8 @@ public class SynchronizerTaskTest {
     }
 
     @Test
-    public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Resonse_Code_Failure() throws Exception {
+    public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Resonse_Code_Failure()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
         RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
@@ -154,7 +140,8 @@ public class SynchronizerTaskTest {
     }
 
     @Test
-    public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Content_Type_Failure() throws Exception {
+    public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Content_Type_Failure()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
         Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
@@ -163,7 +150,8 @@ public class SynchronizerTaskTest {
     }
 
     @Test
-    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Valid_BitSet_Returned_Success() throws Exception {
+    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Valid_BitSet_Returned_Success()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
         Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
@@ -172,7 +160,8 @@ public class SynchronizerTaskTest {
     }
 
     @Test
-    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Content_Type_Failure() throws Exception {
+    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Content_Type_Failure()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
         Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
@@ -181,7 +170,8 @@ public class SynchronizerTaskTest {
     }
 
     @Test
-    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Resonse_Code_Failure() throws Exception {
+    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Resonse_Code_Failure()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
         RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
@@ -189,15 +179,17 @@ public class SynchronizerTaskTest {
     }
 
     @Test
-    public void Given_Synch_Task_Is_Started_And_LogFileLoader_Is_Idle_Then_Standby_Pod_Synch_Is_Successful() throws Exception {
+    public void Given_Synch_Task_Is_Started_And_LogFileLoader_Is_Idle_Then_Standby_Pod_Synch_Is_Successful()
+            throws IOException, IllegalAccessException {
         mockHttpClientForGetRequest();
         Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
         Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "application/vnd.dmaap-dr.provfeed-full; version=1.0"));
         mockResponseFromGet();
+        synchronizerTask.run();
     }
 
 
-    private void mockHttpClientForGetRequest() throws Exception {
+    private void mockHttpClientForGetRequest() throws IllegalAccessException, IOException {
         FieldUtils.writeField(synchronizerTask, "httpclient", httpClient, true);
         Mockito.when(httpClient.execute(anyObject())).thenReturn(response);
         Mockito.when(response.getEntity()).thenReturn(httpEntity);