TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-dmaap / src / test / java / org / onap / dcae / apod / analytics / dmaap / it / DMaaPMRSubscriberImplIT.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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===========================================
19  */
20
21 package org.onap.dcae.apod.analytics.dmaap.it;
22
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;
32
33 import java.util.LinkedList;
34 import java.util.List;
35 import java.util.UUID;
36
37 import static org.junit.Assert.assertTrue;
38
39 /**
40  * @author Rajiv Singla . Creation Date: 10/13/2016.
41  */
42 @Ignore
43 public class DMaaPMRSubscriberImplIT extends BaseAnalyticsDMaaPIT {
44
45     private DMaaPMRPublisher dMaaPMRPublisher;
46     private DMaaPMRSubscriber dMaaPMRSubscriber;
47
48     @Before
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());
54     }
55
56     @After
57     public void after() throws Exception {
58         dMaaPMRSubscriber.close();
59         dMaaPMRPublisher.close();
60     }
61
62
63     @Test
64     public void testFetchMessages() throws Exception {
65
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);
72
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);
77
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);
83         }
84         assertTrue("Subscriber message count must be 2", messageList.size() == 2);
85     }
86
87 }