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;
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.URLUtilities;
import org.powermock.api.mockito.PowerMockito;
@Mock
private CloseableHttpResponse response;
- @Mock
- private ByteArrayOutputStream byteArrayOutputStream;
-
private SynchronizerTask synchronizerTask;
- private ExecutorService executorService;
-
private static EntityManagerFactory emf;
private static EntityManager em;
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"));
}
@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();
}
@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"));
}
@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"));
}
@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"));
}
@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();
}
@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);