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