-/*
- * ===============================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.common.utils;
-
-import co.cask.cdap.api.metrics.Metrics;
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatchers;
-import org.mockito.Mockito;
-import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
-import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants;
-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 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.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-/**
- * @author Rajiv Singla . Creation Date: 2/6/2017.
- */
-public class DMaaPMRUtilsTest extends BaseAnalyticsCDAPCommonUnitTest {
-
- private DMaaPMRSubscriber subscriber;
- private Metrics metrics;
-
-
- @Before
- public void before() throws Exception {
- metrics = mock(Metrics.class);
- doNothing().when(metrics).count(anyString(), anyInt());
- subscriber = mock(DMaaPMRSubscriber.class);
- }
-
- @Test
- public void testGetSubscriberMessagesWhenMessagesAreFound() 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);
- DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);
- verify(metrics, Mockito.times(1)).count(ArgumentMatchers.eq(CDAPMetricsConstants
- .DMAAP_MR_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC), eq(2));
- }
-
- @Test
- public void testSubscriberMessagesWhenSubscriberResponseCodeIsNull() throws Exception {
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
- when(subscriberResponse.getResponseCode()).thenReturn(null);
- when(subscriber.fetchMessages()).thenReturn(subscriberResponse);
- DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);
- }
-
- @Test
- public void testSubscriberMessagesWhenNoMessagesFound() 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);
- DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);
- verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants
- .DMAAP_MR_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC), eq(1));
- }
-
-
- @Test
- public void testWhenSubscriberReturnNonSuccessfulReturnCode() throws Exception {
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
- when(subscriberResponse.getResponseCode()).thenReturn(500);
- when(subscriber.fetchMessages()).thenReturn(subscriberResponse);
- DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);
- verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants
- .DMAAP_MR_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC), eq(1));
- }
-
- @Test
- public void testWhenSubscriberThrowsException() throws Exception {
- final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);
- when(subscriberResponse.getResponseCode()).thenReturn(500);
- when(subscriber.fetchMessages()).thenThrow(DCAEAnalyticsRuntimeException.class);
- DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);
- }
-
-}
+/*\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.common.utils;\r
+\r
+import co.cask.cdap.api.metrics.Metrics;\r
+import com.google.common.collect.ImmutableList;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.ArgumentMatchers;\r
+import org.mockito.Mockito;\r
+import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;\r
+import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants;\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
+\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.mock;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+/**\r
+ * @author Rajiv Singla . Creation Date: 2/6/2017.\r
+ */\r
+public class DMaaPMRUtilsTest extends BaseAnalyticsCDAPCommonUnitTest {\r
+\r
+ private DMaaPMRSubscriber subscriber;\r
+ private Metrics metrics;\r
+\r
+\r
+ @Before\r
+ public void before() throws Exception {\r
+ metrics = mock(Metrics.class);\r
+ doNothing().when(metrics).count(anyString(), anyInt());\r
+ subscriber = mock(DMaaPMRSubscriber.class);\r
+ }\r
+\r
+ @Test\r
+ public void testGetSubscriberMessagesWhenMessagesAreFound() 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
+ DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);\r
+ verify(metrics, Mockito.times(1)).count(ArgumentMatchers.eq(CDAPMetricsConstants\r
+ .DMAAP_MR_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC), eq(2));\r
+ }\r
+\r
+ @Test\r
+ public void testSubscriberMessagesWhenSubscriberResponseCodeIsNull() throws Exception {\r
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
+ when(subscriberResponse.getResponseCode()).thenReturn(null);\r
+ when(subscriber.fetchMessages()).thenReturn(subscriberResponse);\r
+ DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);\r
+ }\r
+\r
+ @Test\r
+ public void testSubscriberMessagesWhenNoMessagesFound() 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
+ DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);\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 testWhenSubscriberReturnNonSuccessfulReturnCode() throws Exception {\r
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
+ when(subscriberResponse.getResponseCode()).thenReturn(500);\r
+ when(subscriber.fetchMessages()).thenReturn(subscriberResponse);\r
+ DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);\r
+ verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants\r
+ .DMAAP_MR_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC), eq(1));\r
+ }\r
+\r
+ @Test\r
+ public void testWhenSubscriberThrowsException() throws Exception {\r
+ final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class);\r
+ when(subscriberResponse.getResponseCode()).thenReturn(500);\r
+ when(subscriber.fetchMessages()).thenThrow(DCAEAnalyticsRuntimeException.class);\r
+ DMaaPMRUtils.getSubscriberMessages(subscriber, metrics);\r
+ }\r
+\r
+}\r