Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-dmaap / src / test / java / org / onap / dcae / apod / analytics / dmaap / it / BaseAnalyticsDMaaPIT.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.onap.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;
24 import org.onap.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig;
25 import org.onap.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse;
26 import org.onap.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;
27 import org.onap.dcae.apod.analytics.test.BaseDCAEAnalyticsIT;
28
29 import java.util.List;
30
31 import static com.google.common.collect.ImmutableList.of;
32
33 /**
34  * Base class for all DCAE DMaaP Integration Tests
35  * <p>
36  * @author Rajiv Singla . Creation Date: 10/13/2016.
37  */
38 public abstract class BaseAnalyticsDMaaPIT extends BaseDCAEAnalyticsIT {
39
40     // Integration Test Settings
41     protected static final String HOST_NAME = "mrlocal-mtnjftle01.homer.com";
42     protected static final Integer PORT_NUMBER = 3905;
43     protected static final String TOPIC_NAME = "com.dcae.dmaap.mtnje2.DcaeTestVESPub";
44
45     protected static final String USERNAME = "USER";
46     protected static final String PASSWORD = "PASSWORD";
47     protected static final String HTTP_PROTOCOL = "https";
48     protected static final String CONTENT_TYPE = "application/json";
49
50     protected static final int PUBLISHER_MAX_BATCH_QUEUE_SIZE = 20;
51     protected static final int PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 200;
52
53     protected static final String SUBSCRIBER_CONSUMER_ID = "123";
54     protected static final String SUBSCRIBER_CONSUMER_GROUP_NAME = "testGonsumerName-" + SUBSCRIBER_CONSUMER_ID;
55     protected static final int SUBSCRIBER_TIMEOUT_MS = 2000;
56     protected static final int SUBSCRIBER_MESSAGE_LIMIT = 20;
57
58     /**
59      * Creates Sample Publisher settings for integration testing purposes
60      *
61      * @return DMaaP MR Publisher Config
62      */
63     protected static DMaaPMRPublisherConfig getPublisherConfig() {
64         return new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME)
65                 .setPortNumber(PORT_NUMBER)
66                 .setProtocol(HTTP_PROTOCOL)
67                 .setContentType(CONTENT_TYPE)
68                 .setUserName(USERNAME)
69                 .setUserPassword(PASSWORD)
70                 .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE)
71                 .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE)
72                 .build();
73     }
74
75     /**
76      * Creates Sample Subscriber settings for integration testing purposes
77      *
78      * @return DMaaP MR Subscriber Config
79      */
80     protected static DMaaPMRSubscriberConfig getSubscriberConfig(String consumerId) {
81         return new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME)
82                 .setPortNumber(PORT_NUMBER)
83                 .setProtocol(HTTP_PROTOCOL)
84                 .setContentType(CONTENT_TYPE)
85                 .setUserName(USERNAME)
86                 .setUserPassword(PASSWORD)
87                 .setConsumerGroup(SUBSCRIBER_CONSUMER_GROUP_NAME)
88                 .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID)
89                 .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS)
90                 .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build();
91     }
92
93     /**
94      * Publishes 2 sample message to DMaaP Topic for integration test purposes
95      *
96      * @param dMaaPMRPublisher DMaaP MR Publisher
97      * @return DMaaP MR Publisher Response
98      */
99     protected static DMaaPMRPublisherResponse publishTwoSampleMessages(DMaaPMRPublisher dMaaPMRPublisher) {
100         return dMaaPMRPublisher.publish(getTwoSampleMessage());
101     }
102
103     protected static List<String> getTwoSampleMessage() {
104         String message1 = "{ \"message\" : \"Test Message1\"}";
105         String message2 = "{ \"message\" : \"Test Message2\"}";
106         return of(message1, message2);
107     }
108
109 }