Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-dmaap / src / test / java / org / openecomp / dcae / apod / analytics / dmaap / BaseAnalyticsDMaaPUnitTest.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.openecomp.dcae.apod.analytics.dmaap;
22
23 import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;
24 import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig;
25 import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;
26
27 import java.util.List;
28
29 import static com.google.common.collect.ImmutableList.of;
30
31 /**
32  * @author Rajiv Singla . Creation Date: 10/14/2016.
33  */
34 public abstract class BaseAnalyticsDMaaPUnitTest extends BaseDCAEAnalyticsUnitTest {
35
36     // Unit Test Settings
37     protected static final String HOST_NAME = "testHostName";
38     protected static final Integer PORT_NUMBER = 8080;
39     protected static final String TOPIC_NAME = "testTopicName";
40     protected static final String USERNAME = "testUserName";
41     protected static final String PASSWORD = "testPassword";
42     protected static final String HTTP_PROTOCOL = "https";
43     protected static final String CONTENT_TYPE = "application/json";
44
45     protected static final int PUBLISHER_MAX_BATCH_QUEUE_SIZE = 200;
46     protected static final int PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 2000;
47
48     protected static final String SUBSCRIBER_CONSUMER_ID = "123";
49     protected static final String SUBSCRIBER_CONSUMER_GROUP_NAME = "testGonsumerName-" + SUBSCRIBER_CONSUMER_ID;
50     protected static final int SUBSCRIBER_TIMEOUT_MS = 2000;
51     protected static final int SUBSCRIBER_MESSAGE_LIMIT = 20;
52
53     /**
54      * Creates Sample Publisher settings for unit testing purposes
55      *
56      * @return sample publisher settings for testing
57      */
58     protected static DMaaPMRPublisherConfig getPublisherConfig() {
59         return new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME)
60                 .setPortNumber(PORT_NUMBER)
61                 .setProtocol(HTTP_PROTOCOL)
62                 .setUserName(USERNAME)
63                 .setUserPassword(PASSWORD)
64                 .setContentType(CONTENT_TYPE)
65                 .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE)
66                 .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE).build();
67     }
68
69     /**
70      * Creates Sample Subscriber settings for unit testing purposes
71      *
72      * @return sample subscriber settings for testing
73      */
74     protected static DMaaPMRSubscriberConfig getSubscriberConfig(String consumerId, String consumerGroup) {
75         return new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME)
76                 .setPortNumber(PORT_NUMBER)
77                 .setUserName(USERNAME)
78                 .setUserPassword(PASSWORD)
79                 .setProtocol(HTTP_PROTOCOL)
80                 .setContentType(CONTENT_TYPE)
81                 .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME)
82                 .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID)
83                 .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS)
84                 .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build();
85     }
86
87     /**
88      * Creates two sample message for publishing
89      *
90      * @return sample publish message list
91      */
92     protected static List<String> getTwoSampleMessages() {
93         String message1 = "{ \"message\" : \"Test Message1\"}";
94         String message2 = "{ \"message\" : \"Test Message2\"}";
95         return of(message1, message2);
96     }
97
98
99 }