-/*\r
- * ===============================LICENSE_START======================================\r
- * dcae-analytics\r
- * ================================================================================\r
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============================LICENSE_END===========================================\r
- */\r
-\r
-package org.openecomp.dcae.apod.analytics.cdap.tca.worker;\r
-\r
-import co.cask.cdap.api.metrics.Metrics;\r
-import co.cask.cdap.api.worker.WorkerContext;\r
-import com.google.common.collect.ImmutableList;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.Mockito;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants;\r
-import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;\r
-import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;\r
-import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;\r
-import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse;\r
-import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber;\r
-import org.quartz.JobDataMap;\r
-import org.quartz.JobExecutionContext;\r
-\r
-import java.io.IOException;\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
-\r
-import static org.mockito.ArgumentMatchers.anyInt;\r
-import static org.mockito.ArgumentMatchers.anyString;\r
-import static org.mockito.ArgumentMatchers.eq;\r
-import static org.mockito.Mockito.doNothing;\r
-import static org.mockito.Mockito.doThrow;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-/**\r
- * @author Rajiv Singla . Creation Date: 12/20/2016.\r
- */\r
-public class TCADMaaPMRSubscriberJobTest extends BaseAnalyticsCDAPTCAUnitTest {\r
-\r
- private JobExecutionContext jobExecutionContext;\r
- private TCADMaaPMRSubscriberJob subscriberJob;\r
- private JobDataMap jobDataMap;\r
- private WorkerContext workerContext;\r
- private DMaaPMRSubscriber subscriber;\r
- private Metrics metrics;\r
-\r
-\r
- @Before\r
- public void before() throws Exception {\r
-\r
- jobExecutionContext = mock(JobExecutionContext.class);\r
- workerContext = mock(WorkerContext.class);\r
-\r
- metrics = mock(Metrics.class);\r
- doNothing().when(metrics).count(anyString(), anyInt());\r
- subscriber = mock(DMaaPMRSubscriber.class);\r
-\r
- jobDataMap = mock(JobDataMap.class);\r
- when(jobDataMap.getString(eq(AnalyticsConstants.CDAP_STREAM_VARIABLE_NAME))).thenReturn\r
- (CDAPComponentsConstants.TCA_DEFAULT_SUBSCRIBER_OUTPUT_NAME_STREAM);\r
- when(jobDataMap.get(eq(AnalyticsConstants.WORKER_CONTEXT_VARIABLE_NAME))).thenReturn(workerContext);\r
- when(jobDataMap.get(eq(AnalyticsConstants.DMAAP_SUBSCRIBER_VARIABLE_NAME))).thenReturn(subscriber);\r
- when(jobDataMap.get(AnalyticsConstants.DMAAP_METRICS_VARIABLE_NAME)).thenReturn(metrics);\r
- when(jobExecutionContext.getMergedJobDataMap()).thenReturn(jobDataMap);\r
-\r
- doNothing().when(workerContext).write(anyString(), anyString());\r
-\r
- subscriberJob = new TCADMaaPMRSubscriberJob();\r
- }\r
-\r
- @Test\r
- public void testExecuteWhenMessagesAreFound() throws Exception {\r
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
- when(subscriberResponse.getResponseCode()).thenReturn(200);\r
- when(subscriberResponse.getResponseMessage()).thenReturn("testMessage");\r
- when(subscriberResponse.getFetchedMessages()).thenReturn(ImmutableList.of("testMessage1", "testMessage1"));\r
- when(subscriber.fetchMessages()).thenReturn(subscriberResponse);\r
- subscriberJob.execute(jobExecutionContext);\r
- verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants\r
- .DMAAP_MR_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC), eq(2));\r
- }\r
-\r
- @Test\r
- public void testExecuteWhenNoMessagesFound() throws Exception {\r
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
- when(subscriberResponse.getResponseCode()).thenReturn(200);\r
- when(subscriberResponse.getResponseMessage()).thenReturn("no messages");\r
- when(subscriberResponse.getFetchedMessages()).thenReturn(Collections.<String>emptyList());\r
- when(subscriber.fetchMessages()).thenReturn(subscriberResponse);\r
- subscriberJob.execute(jobExecutionContext);\r
- verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants\r
- .DMAAP_MR_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC), eq(1));\r
- }\r
-\r
-\r
- @Test\r
- public void testExecuteWhenSubscriberReturnNonSuccessfulReturnCode() throws Exception {\r
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
- when(subscriberResponse.getResponseCode()).thenReturn(500);\r
- when(subscriber.fetchMessages()).thenReturn(subscriberResponse);\r
- subscriberJob.execute(jobExecutionContext);\r
- verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants\r
- .DMAAP_MR_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC), eq(1));\r
- }\r
-\r
- @Test(expected = DCAEAnalyticsRuntimeException.class)\r
- public void testExecuteWhenWritingToCDAPStreamThrowsException() throws Exception {\r
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
- when(subscriberResponse.getResponseCode()).thenReturn(200);\r
- when(subscriberResponse.getFetchedMessages()).thenReturn(Arrays.asList("TestMessage"));\r
- when(subscriber.fetchMessages()).thenReturn(subscriberResponse);\r
- doThrow(new IOException()).when(workerContext).write(anyString(), anyString());\r
- subscriberJob.execute(jobExecutionContext);\r
- }\r
-\r
-\r
-\r
-}\r
+/*
+ * ===============================LICENSE_START======================================
+ * dcae-analytics
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================LICENSE_END===========================================
+ */
+
+package org.onap.dcae.apod.analytics.cdap.tca.worker;
+
+import co.cask.cdap.api.metrics.Metrics;
+import co.cask.cdap.api.worker.WorkerContext;
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.onap.dcae.apod.analytics.cdap.common.CDAPMetricsConstants;
+import org.onap.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+import org.onap.dcae.apod.analytics.common.AnalyticsConstants;
+import org.onap.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
+import org.onap.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse;
+import org.onap.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 12/20/2016.
+ */
+public class TCADMaaPMRSubscriberJobTest extends BaseAnalyticsCDAPTCAUnitTest {
+
+ private JobExecutionContext jobExecutionContext;
+ private TCADMaaPMRSubscriberJob subscriberJob;
+ private JobDataMap jobDataMap;
+ private WorkerContext workerContext;
+ private DMaaPMRSubscriber subscriber;
+ private Metrics metrics;
+
+
+ @Before
+ public void before() throws Exception {
+
+ jobExecutionContext = mock(JobExecutionContext.class);
+ workerContext = mock(WorkerContext.class);
+
+ metrics = mock(Metrics.class);
+ doNothing().when(metrics).count(anyString(), anyInt());
+ subscriber = mock(DMaaPMRSubscriber.class);
+
+ jobDataMap = mock(JobDataMap.class);
+ when(jobDataMap.getString(eq(AnalyticsConstants.CDAP_STREAM_VARIABLE_NAME))).thenReturn
+ (CDAPComponentsConstants.TCA_DEFAULT_SUBSCRIBER_OUTPUT_NAME_STREAM);
+ when(jobDataMap.get(eq(AnalyticsConstants.WORKER_CONTEXT_VARIABLE_NAME))).thenReturn(workerContext);
+ when(jobDataMap.get(eq(AnalyticsConstants.DMAAP_SUBSCRIBER_VARIABLE_NAME))).thenReturn(subscriber);
+ when(jobDataMap.get(AnalyticsConstants.DMAAP_METRICS_VARIABLE_NAME)).thenReturn(metrics);
+ when(jobExecutionContext.getMergedJobDataMap()).thenReturn(jobDataMap);
+
+ doNothing().when(workerContext).write(anyString(), anyString());
+
+ subscriberJob = new TCADMaaPMRSubscriberJob();
+ }
+
+ @Test
+ public void testExecuteWhenMessagesAreFound() throws Exception {
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
+ when(subscriberResponse.getResponseCode()).thenReturn(200);
+ when(subscriberResponse.getResponseMessage()).thenReturn("testMessage");
+ when(subscriberResponse.getFetchedMessages()).thenReturn(ImmutableList.of("testMessage1", "testMessage1"));
+ when(subscriber.fetchMessages()).thenReturn(subscriberResponse);
+ subscriberJob.execute(jobExecutionContext);
+ verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants
+ .DMAAP_MR_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC), eq(2));
+ }
+
+ @Test
+ public void testExecuteWhenNoMessagesFound() throws Exception {
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
+ when(subscriberResponse.getResponseCode()).thenReturn(200);
+ when(subscriberResponse.getResponseMessage()).thenReturn("no messages");
+ when(subscriberResponse.getFetchedMessages()).thenReturn(Collections.<String>emptyList());
+ when(subscriber.fetchMessages()).thenReturn(subscriberResponse);
+ subscriberJob.execute(jobExecutionContext);
+ verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants
+ .DMAAP_MR_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC), eq(1));
+ }
+
+
+ @Test
+ public void testExecuteWhenSubscriberReturnNonSuccessfulReturnCode() throws Exception {
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
+ when(subscriberResponse.getResponseCode()).thenReturn(500);
+ when(subscriber.fetchMessages()).thenReturn(subscriberResponse);
+ subscriberJob.execute(jobExecutionContext);
+ verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants
+ .DMAAP_MR_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC), eq(1));
+ }
+
+ @Test(expected = DCAEAnalyticsRuntimeException.class)
+ public void testExecuteWhenWritingToCDAPStreamThrowsException() throws Exception {
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
+ when(subscriberResponse.getResponseCode()).thenReturn(200);
+ when(subscriberResponse.getFetchedMessages()).thenReturn(Arrays.asList("TestMessage"));
+ when(subscriber.fetchMessages()).thenReturn(subscriberResponse);
+ doThrow(new IOException()).when(workerContext).write(anyString(), anyString());
+ subscriberJob.execute(jobExecutionContext);
+ }
+
+
+
+}