2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.dmaap.it;
\r
23 import org.junit.After;
\r
24 import org.junit.Before;
\r
25 import org.junit.Ignore;
\r
26 import org.junit.Test;
\r
27 import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory;
\r
28 import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse;
\r
29 import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse;
\r
30 import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;
\r
31 import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber;
\r
33 import java.util.LinkedList;
\r
34 import java.util.List;
\r
35 import java.util.UUID;
\r
37 import static org.junit.Assert.assertTrue;
\r
40 * @author Rajiv Singla . Creation Date: 10/13/2016.
\r
43 public class DMaaPMRSubscriberImplIT extends BaseAnalyticsDMaaPIT {
\r
45 private DMaaPMRPublisher dMaaPMRPublisher;
\r
46 private DMaaPMRSubscriber dMaaPMRSubscriber;
\r
49 public void before() throws Exception {
\r
50 String randomConsumerID = UUID.randomUUID().toString();
\r
51 DMaaPMRFactory dMaaPMRFactory = DMaaPMRFactory.create();
\r
52 dMaaPMRSubscriber = dMaaPMRFactory.createSubscriber(getSubscriberConfig(randomConsumerID));
\r
53 dMaaPMRPublisher = dMaaPMRFactory.createPublisher(getPublisherConfig());
\r
57 public void after() throws Exception {
\r
58 dMaaPMRSubscriber.close();
\r
59 dMaaPMRPublisher.close();
\r
64 public void testFetchMessages() throws Exception {
\r
66 // This call is used to just register a brand new subscriber with DMaaP
\r
67 DMaaPMRSubscriberResponse subscriberRegistrationResponse = dMaaPMRSubscriber.fetchMessages();
\r
68 assertTrue("Subscriber Registration Response code must be 200 confirming subscriber was registered " +
\r
69 "successfully", subscriberRegistrationResponse.getResponseCode() == 200);
\r
70 assertTrue("Subscriber Registration Response must not contain any messages", subscriberRegistrationResponse
\r
71 .getFetchedMessages().size() == 0);
\r
73 // Force push couple of test messages
\r
74 DMaaPMRPublisherResponse publisherResponse = dMaaPMRPublisher.forcePublish(getTwoSampleMessage());
\r
75 assertTrue("Message must be posted successfully before subscriber can fetch it", publisherResponse
\r
76 .getResponseCode() == 200);
\r
78 // Now fetch messages from DMaaP
\r
79 DMaaPMRSubscriberResponse subscriberResponse = dMaaPMRSubscriber.fetchMessages();
\r
80 List<String> messageList = new LinkedList<>();
\r
81 for (String message : subscriberResponse.getFetchedMessages()) {
\r
82 messageList.add(message);
\r
84 assertTrue("Subscriber message count must be 2", messageList.size() == 2);
\r