-/*
- * ===============================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.dmaap.service.subscriber;
-
-import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
-import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest;
-import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig;
-import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse;
-
-import java.io.IOException;
-import java.util.Random;
-import java.util.UUID;
-
-import static org.hamcrest.CoreMatchers.isA;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.mockito.BDDMockito.given;
-
-/**
- * @author Rajiv Singla . Creation Date: 10/21/2016.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class DMaaPMRSubscriberImplTest extends BaseAnalyticsDMaaPUnitTest {
-
- @Mock
- private CloseableHttpClient closeableHttpClient;
-
- private String consumerGroup, consumerId;
-
- @Before
- public void setUp() throws Exception {
- Random random = new Random(10000L);
- consumerGroup = "Test-Consumer-Group" + Long.toString(random.nextLong());
- consumerId = UUID.randomUUID().toString();
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- @Test
- public void testSubscriberSuccessfullyReceiveDmaapMessage() throws Exception {
-
- String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," +
- "{\"message\":\"I'm Object 2 Message\"}]";
- Mockito.when(
- closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))
- .thenReturn(new ImmutablePair<>(200, testMessages));
-
- DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(
- getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);
- DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();
- assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200));
- assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2));
- }
-
- @Test
- public void testSubscriberSuccessfullyReceiveDmaapMessageWithNoUsername() throws Exception {
-
- DMaaPMRSubscriberConfig dmaapMRSubscriberConfig = new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME)
- .setPortNumber(PORT_NUMBER)
- .setProtocol(HTTP_PROTOCOL)
- .setContentType(CONTENT_TYPE)
- .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME)
- .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID)
- .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS)
- .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build();
-
- String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," +
- "{\"message\":\"I'm Object 2 Message\"}]";
- Mockito.when(
- closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))
- .thenReturn(new ImmutablePair<>(200, testMessages));
-
- DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(
- dmaapMRSubscriberConfig, closeableHttpClient);
- DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();
- assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200));
- assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2));
- }
-
- @Test
- public void testSubscriberSuccessfullyReceiveNoDmaapMessage() throws Exception {
- Mockito.when(
- closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))
- .thenReturn(new ImmutablePair<>(200, null));
-
- DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(
- getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);
- DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();
- assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200));
- assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0));
- }
-
- @Test
- public void testSubscriberSuccessfullyReceiveErrorMessage() throws Exception {
- Mockito.when(
- closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))
- .thenReturn(new ImmutablePair<>(400, "Bad Request"));
-
- DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(
- getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);
- DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();
- assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(400));
- assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0));
- }
-
- @Rule
- public ExpectedException httpIOException = ExpectedException.none();
-
- @Test
- public void testSubscriberSuccessfullyReceiveException() throws Exception {
-
- httpIOException.expect(DCAEAnalyticsRuntimeException.class);
- httpIOException.expectCause(isA(IOException.class));
-
- given(closeableHttpClient.execute(
- Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).willThrow(IOException.class);
-
- DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(
- getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);
- dmaapMRSubscriberImpl.fetchMessages();
- }
-
-}
+/*\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.dmaap.service.subscriber;\r
+\r
+import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;\r
+import org.apache.commons.lang3.tuple.ImmutablePair;\r
+import org.apache.http.client.ResponseHandler;\r
+import org.apache.http.client.methods.HttpUriRequest;\r
+import org.apache.http.impl.client.CloseableHttpClient;\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.junit.MockitoJUnitRunner;\r
+import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;\r
+import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest;\r
+import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig;\r
+import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse;\r
+\r
+import java.io.IOException;\r
+import java.util.Random;\r
+import java.util.UUID;\r
+\r
+import static org.hamcrest.CoreMatchers.isA;\r
+import static org.hamcrest.MatcherAssert.assertThat;\r
+import static org.hamcrest.core.Is.is;\r
+import static org.mockito.BDDMockito.given;\r
+\r
+/**\r
+ * @author Rajiv Singla . Creation Date: 10/21/2016.\r
+ */\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class DMaaPMRSubscriberImplTest extends BaseAnalyticsDMaaPUnitTest {\r
+\r
+ @Mock\r
+ private CloseableHttpClient closeableHttpClient;\r
+\r
+ private String consumerGroup, consumerId;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ Random random = new Random(10000L);\r
+ consumerGroup = "Test-Consumer-Group" + Long.toString(random.nextLong());\r
+ consumerId = UUID.randomUUID().toString();\r
+ }\r
+\r
+ @After\r
+ public void tearDown() throws Exception {\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testSubscriberSuccessfullyReceiveDmaapMessage() throws Exception {\r
+\r
+ String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," +\r
+ "{\"message\":\"I'm Object 2 Message\"}]";\r
+ Mockito.when(\r
+ closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))\r
+ .thenReturn(new ImmutablePair<>(200, testMessages));\r
+\r
+ DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(\r
+ getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);\r
+ DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();\r
+ assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200));\r
+ assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2));\r
+ }\r
+\r
+ @Test\r
+ public void testSubscriberSuccessfullyReceiveDmaapMessageWithNoUsername() throws Exception {\r
+\r
+ DMaaPMRSubscriberConfig dmaapMRSubscriberConfig = new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME)\r
+ .setPortNumber(PORT_NUMBER)\r
+ .setProtocol(HTTP_PROTOCOL)\r
+ .setContentType(CONTENT_TYPE)\r
+ .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME)\r
+ .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID)\r
+ .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS)\r
+ .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build();\r
+\r
+ String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," +\r
+ "{\"message\":\"I'm Object 2 Message\"}]";\r
+ Mockito.when(\r
+ closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))\r
+ .thenReturn(new ImmutablePair<>(200, testMessages));\r
+\r
+ DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(\r
+ dmaapMRSubscriberConfig, closeableHttpClient);\r
+ DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();\r
+ assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200));\r
+ assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2));\r
+ }\r
+\r
+ @Test\r
+ public void testSubscriberSuccessfullyReceiveNoDmaapMessage() throws Exception {\r
+ Mockito.when(\r
+ closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))\r
+ .thenReturn(new ImmutablePair<>(200, null));\r
+\r
+ DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(\r
+ getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);\r
+ DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();\r
+ assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200));\r
+ assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0));\r
+ }\r
+\r
+ @Test\r
+ public void testSubscriberSuccessfullyReceiveErrorMessage() throws Exception {\r
+ Mockito.when(\r
+ closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)))\r
+ .thenReturn(new ImmutablePair<>(400, "Bad Request"));\r
+\r
+ DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(\r
+ getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);\r
+ DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages();\r
+ assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(400));\r
+ assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0));\r
+ }\r
+\r
+ @Rule\r
+ public ExpectedException httpIOException = ExpectedException.none();\r
+\r
+ @Test\r
+ public void testSubscriberSuccessfullyReceiveException() throws Exception {\r
+\r
+ httpIOException.expect(DCAEAnalyticsRuntimeException.class);\r
+ httpIOException.expectCause(isA(IOException.class));\r
+\r
+ given(closeableHttpClient.execute(\r
+ Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).willThrow(IOException.class);\r
+\r
+ DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl(\r
+ getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient);\r
+ dmaapMRSubscriberImpl.fetchMessages();\r
+ }\r
+\r
+}\r