diff options
Diffstat (limited to 'dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker')
5 files changed, 567 insertions, 567 deletions
diff --git a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/BaseTCADMaaPMRWorkerTest.java b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/BaseTCADMaaPMRWorkerTest.java index fa48ea8..3f13b7f 100644 --- a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/BaseTCADMaaPMRWorkerTest.java +++ b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/BaseTCADMaaPMRWorkerTest.java @@ -1,99 +1,99 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker; - -import org.junit.Before; -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest; -import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants; -import org.quartz.Scheduler; - -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 12/19/2016. - */ -public class BaseTCADMaaPMRWorkerTest extends BaseAnalyticsCDAPTCAUnitTest { - - private static final String SCHEDULER_NAME = "testSchedulerName"; - - private Scheduler mockScheduler; - private AtomicBoolean mockIsSchedulerShutdown; - private BaseTestTCADMaaPMRWorker baseTestTCADMaaPMRWorker; - - private static class BaseTestTCADMaaPMRWorker extends BaseTCADMaaPMRWorker { - - public BaseTestTCADMaaPMRWorker(final Scheduler scheduler, final AtomicBoolean isSchedulerShutdown) { - this.scheduler = scheduler; - this.isSchedulerShutdown = isSchedulerShutdown; - } - - } - - @Before - public void before() throws Exception { - mockScheduler = mock(Scheduler.class); - mockIsSchedulerShutdown = mock(AtomicBoolean.class); - baseTestTCADMaaPMRWorker = new BaseTestTCADMaaPMRWorker(mockScheduler, mockIsSchedulerShutdown); - when(mockScheduler.getSchedulerName()).thenReturn(SCHEDULER_NAME); - doNothing().when(mockScheduler).start(); - doNothing().when(mockScheduler).shutdown(); - } - - @Test - public void testRun() throws Exception { - createShutdownHookThread(); - baseTestTCADMaaPMRWorker.run(); - verify(mockScheduler, times(1)).start(); - } - - @Test - public void testStop() throws Exception { - baseTestTCADMaaPMRWorker.stop(); - verify(mockScheduler, times(1)).shutdown(); - } - - /** - * A helper thread which shuts down the scheduler after some time - */ - public void createShutdownHookThread() { - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.yield(); - Thread.sleep(AnalyticsConstants.TCA_DEFAULT_WORKER_SHUTDOWN_CHECK_INTERVAL_MS * 2); - } catch (InterruptedException e) { - LOG.error("Interrupted Exception while running test: {}", e); - throw new RuntimeException(e); - } - mockIsSchedulerShutdown.getAndSet(true); - } - }).start(); - } - -} +/*
+ * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
+import org.quartz.Scheduler;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 12/19/2016.
+ */
+public class BaseTCADMaaPMRWorkerTest extends BaseAnalyticsCDAPTCAUnitTest {
+
+ private static final String SCHEDULER_NAME = "testSchedulerName";
+
+ private Scheduler mockScheduler;
+ private AtomicBoolean mockIsSchedulerShutdown;
+ private BaseTestTCADMaaPMRWorker baseTestTCADMaaPMRWorker;
+
+ private static class BaseTestTCADMaaPMRWorker extends BaseTCADMaaPMRWorker {
+
+ public BaseTestTCADMaaPMRWorker(final Scheduler scheduler, final AtomicBoolean isSchedulerShutdown) {
+ this.scheduler = scheduler;
+ this.isSchedulerShutdown = isSchedulerShutdown;
+ }
+
+ }
+
+ @Before
+ public void before() throws Exception {
+ mockScheduler = mock(Scheduler.class);
+ mockIsSchedulerShutdown = mock(AtomicBoolean.class);
+ baseTestTCADMaaPMRWorker = new BaseTestTCADMaaPMRWorker(mockScheduler, mockIsSchedulerShutdown);
+ when(mockScheduler.getSchedulerName()).thenReturn(SCHEDULER_NAME);
+ doNothing().when(mockScheduler).start();
+ doNothing().when(mockScheduler).shutdown();
+ }
+
+ @Test
+ public void testRun() throws Exception {
+ createShutdownHookThread();
+ baseTestTCADMaaPMRWorker.run();
+ verify(mockScheduler, times(1)).start();
+ }
+
+ @Test
+ public void testStop() throws Exception {
+ baseTestTCADMaaPMRWorker.stop();
+ verify(mockScheduler, times(1)).shutdown();
+ }
+
+ /**
+ * A helper thread which shuts down the scheduler after some time
+ */
+ public void createShutdownHookThread() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.yield();
+ Thread.sleep(AnalyticsConstants.TCA_DEFAULT_WORKER_SHUTDOWN_CHECK_INTERVAL_MS * 2);
+ } catch (InterruptedException e) {
+ LOG.error("Interrupted Exception while running test: {}", e);
+ throw new RuntimeException(e);
+ }
+ mockIsSchedulerShutdown.getAndSet(true);
+ }
+ }).start();
+ }
+
+}
diff --git a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRPublisherJobTest.java b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRPublisherJobTest.java index 5f7e989..8028dd4 100644 --- a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRPublisherJobTest.java +++ b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRPublisherJobTest.java @@ -1,158 +1,158 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker; - -import co.cask.cdap.api.TxRunnable; -import co.cask.cdap.api.metrics.Metrics; -import co.cask.cdap.api.worker.WorkerContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants; -import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAVESAlertEntity; -import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest; -import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants; -import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.quartz.JobDataMap; -import org.quartz.JobExecutionContext; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import static org.mockito.ArgumentMatchers.any; -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.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 12/20/2016. - */ -public class TCADMaaPMRPublisherJobTest extends BaseAnalyticsCDAPTCAUnitTest { - - private JobExecutionContext jobExecutionContext; - private TCADMaaPMRPublisherJob publisherJob; - private JobDataMap jobDataMap; - private WorkerContext workerContext; - private DMaaPMRPublisher publisher; - private Metrics metrics; - - private class TCATestDMaaPMRPublisherJob extends TCADMaaPMRPublisherJob { - - private Map<String, TCAVESAlertEntity> alertEntityMap; - - public TCATestDMaaPMRPublisherJob(Map<String, TCAVESAlertEntity> alertEntityMap) { - this.alertEntityMap = alertEntityMap; - } - - @Override - protected Map<String, TCAVESAlertEntity> getNewAlertsMap( - String cdapAlertsTableName, WorkerContext workerContext) { - return alertEntityMap; - } - - @Override - protected void deleteAlertsByKey(String cdapAlertsTableName, WorkerContext workerContext, - Set<String> rowKeys, Metrics metrics) { - // do nothing - } - } - - @Before - public void before() throws Exception { - - jobExecutionContext = mock(JobExecutionContext.class); - workerContext = mock(WorkerContext.class); - - metrics = mock(Metrics.class); - doNothing().when(metrics).count(anyString(), anyInt()); - publisher = mock(DMaaPMRPublisher.class); - - jobDataMap = mock(JobDataMap.class); - when(jobDataMap.getString(eq(AnalyticsConstants.CDAP_ALERTS_TABLE_VARIABLE_NAME))).thenReturn - ("testAlertTableName"); - when(jobDataMap.get(eq(AnalyticsConstants.WORKER_CONTEXT_VARIABLE_NAME))).thenReturn(workerContext); - when(jobDataMap.get(eq(AnalyticsConstants.DMAAP_PUBLISHER_VARIABLE_NAME))).thenReturn(publisher); - when(jobDataMap.get(AnalyticsConstants.DMAAP_METRICS_VARIABLE_NAME)).thenReturn(metrics); - when(jobExecutionContext.getMergedJobDataMap()).thenReturn(jobDataMap); - - - publisherJob = new TCADMaaPMRPublisherJob(); - } - - @Test - public void testExecuteWhenNoAlertsFoundInAlertsTable() throws Exception { - doNothing().when(workerContext).execute(any(TxRunnable.class)); - publisherJob.execute(jobExecutionContext); - verify(metrics, times(1)) - .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_NO_NEW_ALERTS_LOOKUP_METRIC), eq(1)); - } - - @Test - public void testExecuteWhenAlertsWereFoundInAlertsTable() throws Exception { - - final DMaaPMRPublisherResponse publisherResponse = mock(DMaaPMRPublisherResponse.class); - when(publisherResponse.getResponseCode()).thenReturn(200); - when(publisherResponse.getResponseMessage()).thenReturn("success"); - when(publisherResponse.getPendingMessagesCount()).thenReturn(0); - when(publisher.publish(ArgumentMatchers.<String>anyList())).thenReturn(publisherResponse); - - final TCAVESAlertEntity tcavesAlertEntity = mock(TCAVESAlertEntity.class); - when(tcavesAlertEntity.getAlertMessage()).thenReturn("testAlertMessage"); - Map<String, TCAVESAlertEntity> alertEntityMap = new HashMap<>(); - alertEntityMap.put("key1", tcavesAlertEntity); - final TCATestDMaaPMRPublisherJob testPublisherJob = new TCATestDMaaPMRPublisherJob(alertEntityMap); - testPublisherJob.execute(jobExecutionContext); - verify(metrics, times(1)) - .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_NEW_ALERTS_METRIC), eq(1)); - verify(metrics, times(1)) - .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_SUCCESSFUL_DMAAP_RESPONSE_METRIC), eq(1)); - } - - @Test - public void testExecuteWhenAlertsWereFoundButPublisherReturnedNon200ResponseCode() throws Exception { - - final DMaaPMRPublisherResponse publisherResponse = mock(DMaaPMRPublisherResponse.class); - when(publisherResponse.getResponseCode()).thenReturn(500); - when(publisherResponse.getResponseMessage()).thenReturn("failed"); - when(publisherResponse.getPendingMessagesCount()).thenReturn(0); - when(publisher.publish(ArgumentMatchers.<String>anyList())).thenReturn(publisherResponse); - - final TCAVESAlertEntity tcavesAlertEntity = mock(TCAVESAlertEntity.class); - when(tcavesAlertEntity.getAlertMessage()).thenReturn("testAlertMessage"); - Map<String, TCAVESAlertEntity> alertEntityMap = new HashMap<>(); - alertEntityMap.put("key1", tcavesAlertEntity); - final TCATestDMaaPMRPublisherJob testPublisherJob = new TCATestDMaaPMRPublisherJob(alertEntityMap); - testPublisherJob.execute(jobExecutionContext); - verify(metrics, times(1)) - .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_NEW_ALERTS_METRIC), eq(1)); - verify(metrics, times(1)) - .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_UNSUCCESSFUL_DMAAP_RESPONSE_METRIC), eq(1)); - } - - -} +/*
+ * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker;
+
+import co.cask.cdap.api.TxRunnable;
+import co.cask.cdap.api.metrics.Metrics;
+import co.cask.cdap.api.worker.WorkerContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants;
+import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAVESAlertEntity;
+import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
+import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse;
+import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.mockito.ArgumentMatchers.any;
+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.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 12/20/2016.
+ */
+public class TCADMaaPMRPublisherJobTest extends BaseAnalyticsCDAPTCAUnitTest {
+
+ private JobExecutionContext jobExecutionContext;
+ private TCADMaaPMRPublisherJob publisherJob;
+ private JobDataMap jobDataMap;
+ private WorkerContext workerContext;
+ private DMaaPMRPublisher publisher;
+ private Metrics metrics;
+
+ private class TCATestDMaaPMRPublisherJob extends TCADMaaPMRPublisherJob {
+
+ private Map<String, TCAVESAlertEntity> alertEntityMap;
+
+ public TCATestDMaaPMRPublisherJob(Map<String, TCAVESAlertEntity> alertEntityMap) {
+ this.alertEntityMap = alertEntityMap;
+ }
+
+ @Override
+ protected Map<String, TCAVESAlertEntity> getNewAlertsMap(
+ String cdapAlertsTableName, WorkerContext workerContext) {
+ return alertEntityMap;
+ }
+
+ @Override
+ protected void deleteAlertsByKey(String cdapAlertsTableName, WorkerContext workerContext,
+ Set<String> rowKeys, Metrics metrics) {
+ // do nothing
+ }
+ }
+
+ @Before
+ public void before() throws Exception {
+
+ jobExecutionContext = mock(JobExecutionContext.class);
+ workerContext = mock(WorkerContext.class);
+
+ metrics = mock(Metrics.class);
+ doNothing().when(metrics).count(anyString(), anyInt());
+ publisher = mock(DMaaPMRPublisher.class);
+
+ jobDataMap = mock(JobDataMap.class);
+ when(jobDataMap.getString(eq(AnalyticsConstants.CDAP_ALERTS_TABLE_VARIABLE_NAME))).thenReturn
+ ("testAlertTableName");
+ when(jobDataMap.get(eq(AnalyticsConstants.WORKER_CONTEXT_VARIABLE_NAME))).thenReturn(workerContext);
+ when(jobDataMap.get(eq(AnalyticsConstants.DMAAP_PUBLISHER_VARIABLE_NAME))).thenReturn(publisher);
+ when(jobDataMap.get(AnalyticsConstants.DMAAP_METRICS_VARIABLE_NAME)).thenReturn(metrics);
+ when(jobExecutionContext.getMergedJobDataMap()).thenReturn(jobDataMap);
+
+
+ publisherJob = new TCADMaaPMRPublisherJob();
+ }
+
+ @Test
+ public void testExecuteWhenNoAlertsFoundInAlertsTable() throws Exception {
+ doNothing().when(workerContext).execute(any(TxRunnable.class));
+ publisherJob.execute(jobExecutionContext);
+ verify(metrics, times(1))
+ .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_NO_NEW_ALERTS_LOOKUP_METRIC), eq(1));
+ }
+
+ @Test
+ public void testExecuteWhenAlertsWereFoundInAlertsTable() throws Exception {
+
+ final DMaaPMRPublisherResponse publisherResponse = mock(DMaaPMRPublisherResponse.class);
+ when(publisherResponse.getResponseCode()).thenReturn(200);
+ when(publisherResponse.getResponseMessage()).thenReturn("success");
+ when(publisherResponse.getPendingMessagesCount()).thenReturn(0);
+ when(publisher.publish(ArgumentMatchers.<String>anyList())).thenReturn(publisherResponse);
+
+ final TCAVESAlertEntity tcavesAlertEntity = mock(TCAVESAlertEntity.class);
+ when(tcavesAlertEntity.getAlertMessage()).thenReturn("testAlertMessage");
+ Map<String, TCAVESAlertEntity> alertEntityMap = new HashMap<>();
+ alertEntityMap.put("key1", tcavesAlertEntity);
+ final TCATestDMaaPMRPublisherJob testPublisherJob = new TCATestDMaaPMRPublisherJob(alertEntityMap);
+ testPublisherJob.execute(jobExecutionContext);
+ verify(metrics, times(1))
+ .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_NEW_ALERTS_METRIC), eq(1));
+ verify(metrics, times(1))
+ .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_SUCCESSFUL_DMAAP_RESPONSE_METRIC), eq(1));
+ }
+
+ @Test
+ public void testExecuteWhenAlertsWereFoundButPublisherReturnedNon200ResponseCode() throws Exception {
+
+ final DMaaPMRPublisherResponse publisherResponse = mock(DMaaPMRPublisherResponse.class);
+ when(publisherResponse.getResponseCode()).thenReturn(500);
+ when(publisherResponse.getResponseMessage()).thenReturn("failed");
+ when(publisherResponse.getPendingMessagesCount()).thenReturn(0);
+ when(publisher.publish(ArgumentMatchers.<String>anyList())).thenReturn(publisherResponse);
+
+ final TCAVESAlertEntity tcavesAlertEntity = mock(TCAVESAlertEntity.class);
+ when(tcavesAlertEntity.getAlertMessage()).thenReturn("testAlertMessage");
+ Map<String, TCAVESAlertEntity> alertEntityMap = new HashMap<>();
+ alertEntityMap.put("key1", tcavesAlertEntity);
+ final TCATestDMaaPMRPublisherJob testPublisherJob = new TCATestDMaaPMRPublisherJob(alertEntityMap);
+ testPublisherJob.execute(jobExecutionContext);
+ verify(metrics, times(1))
+ .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_NEW_ALERTS_METRIC), eq(1));
+ verify(metrics, times(1))
+ .count(eq(CDAPMetricsConstants.TCA_PUBLISHER_UNSUCCESSFUL_DMAAP_RESPONSE_METRIC), eq(1));
+ }
+
+
+}
diff --git a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRSubscriberJobTest.java b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRSubscriberJobTest.java index d28dff0..7e47aca 100644 --- a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRSubscriberJobTest.java +++ b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPMRSubscriberJobTest.java @@ -1,135 +1,135 @@ -/* - * ===============================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.openecomp.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.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants; -import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest; -import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants; -import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.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); - } - - - -} +/*
+ * ===============================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.openecomp.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.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants;
+import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
+import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
+import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse;
+import org.openecomp.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);
+ }
+
+
+
+}
diff --git a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPPublisherWorkerTest.java b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPPublisherWorkerTest.java index 2324b38..eab9b39 100644 --- a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPPublisherWorkerTest.java +++ b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPPublisherWorkerTest.java @@ -1,87 +1,87 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker; - -import co.cask.cdap.api.app.ApplicationSpecification; -import co.cask.cdap.api.worker.WorkerConfigurer; -import co.cask.cdap.api.worker.WorkerContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants; -import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException; -import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest; - -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 12/20/2016. - */ -public class TCADMaaPPublisherWorkerTest extends BaseAnalyticsCDAPTCAUnitTest { - - private static final String VES_ALERTS_TABLE_NAME = "vesAlertsTable"; - - private WorkerConfigurer workerConfigurer; - private WorkerContext workerContext; - private TCADMaaPPublisherWorker publisherWorker; - private ApplicationSpecification mockApplicationSpecification; - - @Before - public void before() throws Exception { - workerConfigurer = mock(WorkerConfigurer.class); - workerContext = mock(WorkerContext.class); - doNothing().when(workerConfigurer).setName(anyString()); - doNothing().when(workerConfigurer).setDescription(anyString()); - mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class); - when(workerContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification); - publisherWorker = new TCADMaaPPublisherWorker(VES_ALERTS_TABLE_NAME); - - } - - @Test - public void testConfigure() throws Exception { - publisherWorker.configure(workerConfigurer); - verify(workerConfigurer, times(1)) - .setName(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_PUBLISHER_WORKER)); - verify(workerConfigurer, times(1)) - .setDescription(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_PUBLISHER_DESCRIPTION_WORKER)); - } - - @Test(expected = CDAPSettingsException.class) - public void testInitializeWhenSettingsHaveErrors() throws Exception { - when(mockApplicationSpecification.getConfiguration()).thenReturn("{}"); - publisherWorker.initialize(workerContext); - } - - @Test - public void testInitializeWhenSettingsAreValid() throws Exception { - when(workerContext.getRuntimeArguments()).thenReturn(getPreferenceMap()); - when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION)); - publisherWorker.initialize(workerContext); - } - -} +/*
+ * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker;
+
+import co.cask.cdap.api.app.ApplicationSpecification;
+import co.cask.cdap.api.worker.WorkerConfigurer;
+import co.cask.cdap.api.worker.WorkerContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
+import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 12/20/2016.
+ */
+public class TCADMaaPPublisherWorkerTest extends BaseAnalyticsCDAPTCAUnitTest {
+
+ private static final String VES_ALERTS_TABLE_NAME = "vesAlertsTable";
+
+ private WorkerConfigurer workerConfigurer;
+ private WorkerContext workerContext;
+ private TCADMaaPPublisherWorker publisherWorker;
+ private ApplicationSpecification mockApplicationSpecification;
+
+ @Before
+ public void before() throws Exception {
+ workerConfigurer = mock(WorkerConfigurer.class);
+ workerContext = mock(WorkerContext.class);
+ doNothing().when(workerConfigurer).setName(anyString());
+ doNothing().when(workerConfigurer).setDescription(anyString());
+ mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class);
+ when(workerContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification);
+ publisherWorker = new TCADMaaPPublisherWorker(VES_ALERTS_TABLE_NAME);
+
+ }
+
+ @Test
+ public void testConfigure() throws Exception {
+ publisherWorker.configure(workerConfigurer);
+ verify(workerConfigurer, times(1))
+ .setName(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_PUBLISHER_WORKER));
+ verify(workerConfigurer, times(1))
+ .setDescription(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_PUBLISHER_DESCRIPTION_WORKER));
+ }
+
+ @Test(expected = CDAPSettingsException.class)
+ public void testInitializeWhenSettingsHaveErrors() throws Exception {
+ when(mockApplicationSpecification.getConfiguration()).thenReturn("{}");
+ publisherWorker.initialize(workerContext);
+ }
+
+ @Test
+ public void testInitializeWhenSettingsAreValid() throws Exception {
+ when(workerContext.getRuntimeArguments()).thenReturn(getPreferenceMap());
+ when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION));
+ publisherWorker.initialize(workerContext);
+ }
+
+}
diff --git a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPSubscriberWorkerTest.java b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPSubscriberWorkerTest.java index e5b1f9a..e3ed9cc 100644 --- a/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPSubscriberWorkerTest.java +++ b/dcae-analytics-cdap-tca/src/test/java/org/openecomp/dcae/apod/analytics/cdap/tca/worker/TCADMaaPSubscriberWorkerTest.java @@ -1,88 +1,88 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker; - -import co.cask.cdap.api.app.ApplicationSpecification; -import co.cask.cdap.api.worker.WorkerConfigurer; -import co.cask.cdap.api.worker.WorkerContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants; -import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException; -import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest; - -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 12/20/2016. - */ -public class TCADMaaPSubscriberWorkerTest extends BaseAnalyticsCDAPTCAUnitTest { - - private static final String TEST_SUBSCRIBER_OUTPUT_STREAM_NAME = "testSubscriberOutputStream"; - - private WorkerConfigurer workerConfigurer; - private WorkerContext workerContext; - private TCADMaaPSubscriberWorker subscriberWorker; - private ApplicationSpecification mockApplicationSpecification; - - @Before - public void before() throws Exception { - workerConfigurer = mock(WorkerConfigurer.class); - workerContext = mock(WorkerContext.class); - mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class); - when(workerContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification); - doNothing().when(workerConfigurer).setName(anyString()); - doNothing().when(workerConfigurer).setDescription(anyString()); - subscriberWorker = - new TCADMaaPSubscriberWorker(TEST_SUBSCRIBER_OUTPUT_STREAM_NAME); - - } - - @Test - public void testConfigure() throws Exception { - subscriberWorker.configure(workerConfigurer); - verify(workerConfigurer, times(1)) - .setName(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_SUBSCRIBER_WORKER)); - verify(workerConfigurer, times(1)) - .setDescription(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_SUBSCRIBER_DESCRIPTION_WORKER)); - } - - @Test(expected = CDAPSettingsException.class) - public void testInitializeWhenSettingsHaveErrors() throws Exception { - when(mockApplicationSpecification.getConfiguration()).thenReturn("{}"); - subscriberWorker.initialize(workerContext); - } - - @Test - public void testInitializeWhenSettingsAreValid() throws Exception { - when(workerContext.getRuntimeArguments()).thenReturn(getPreferenceMap()); - when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION)); - subscriberWorker.initialize(workerContext); - } - -} +/*
+ * ===============================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.openecomp.dcae.apod.analytics.cdap.tca.worker;
+
+import co.cask.cdap.api.app.ApplicationSpecification;
+import co.cask.cdap.api.worker.WorkerConfigurer;
+import co.cask.cdap.api.worker.WorkerContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
+import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 12/20/2016.
+ */
+public class TCADMaaPSubscriberWorkerTest extends BaseAnalyticsCDAPTCAUnitTest {
+
+ private static final String TEST_SUBSCRIBER_OUTPUT_STREAM_NAME = "testSubscriberOutputStream";
+
+ private WorkerConfigurer workerConfigurer;
+ private WorkerContext workerContext;
+ private TCADMaaPSubscriberWorker subscriberWorker;
+ private ApplicationSpecification mockApplicationSpecification;
+
+ @Before
+ public void before() throws Exception {
+ workerConfigurer = mock(WorkerConfigurer.class);
+ workerContext = mock(WorkerContext.class);
+ mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class);
+ when(workerContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification);
+ doNothing().when(workerConfigurer).setName(anyString());
+ doNothing().when(workerConfigurer).setDescription(anyString());
+ subscriberWorker =
+ new TCADMaaPSubscriberWorker(TEST_SUBSCRIBER_OUTPUT_STREAM_NAME);
+
+ }
+
+ @Test
+ public void testConfigure() throws Exception {
+ subscriberWorker.configure(workerConfigurer);
+ verify(workerConfigurer, times(1))
+ .setName(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_SUBSCRIBER_WORKER));
+ verify(workerConfigurer, times(1))
+ .setDescription(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_SUBSCRIBER_DESCRIPTION_WORKER));
+ }
+
+ @Test(expected = CDAPSettingsException.class)
+ public void testInitializeWhenSettingsHaveErrors() throws Exception {
+ when(mockApplicationSpecification.getConfiguration()).thenReturn("{}");
+ subscriberWorker.initialize(workerContext);
+ }
+
+ @Test
+ public void testInitializeWhenSettingsAreValid() throws Exception {
+ when(workerContext.getRuntimeArguments()).thenReturn(getPreferenceMap());
+ when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION));
+ subscriberWorker.initialize(workerContext);
+ }
+
+}
|