ba52f1911f3023356c30eff37768491ae0853899
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2018 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.policy.common.endpoints.event.comm.bus;
22
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
28 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
29
30 /**
31  * Base class for BusTopicXxxTest classes.
32  */
33 public class BusTopicTestBase {
34
35     public static final String MY_AFT_ENV = "my-aft-env";
36     public static final String MY_API_KEY = "my-api-key";
37     public static final String MY_API_SECRET = "my-api-secret";
38     public static final String MY_BASE_PATH = "my-base";
39     public static final String MY_CLIENT_NAME = "my-client";
40     public static final String MY_CONS_GROUP = "my-cons-group";
41     public static final String MY_CONS_INST = "my-cons-inst";
42     public static final String MY_ENV = "my-env";
43     public static final int MY_FETCH_LIMIT = 100;
44     public static final int MY_FETCH_TIMEOUT = 101;
45     public static final String MY_HOST = "my-host";
46     public static final String MY_LAT = "my-lat";
47     public static final String MY_LONG = "my-long";
48     public static final String MY_PARTNER = "my-partner";
49     public static final String MY_PASSWD = "my-pass";
50     public static final int MY_PORT = 102;
51     public static final String MY_TOPIC = "my-topic";
52     public static final String MY_USERNAME = "my-user";
53
54     public static final String MY_MESSAGE = "my-message";
55     public static final String MY_PARTITION = "my-partition";
56     public static final String MY_MESSAGE2 = "my-message-2";
57     public static final String MY_PARTITION2 = "my-partition-2";
58
59     public static final String ROUTE_PROP = "routeOffer";
60     public static final String MY_ROUTE = "my-route";
61
62     /**
63      * Message used within exceptions that are expected.
64      */
65     public static final String EXPECTED = "expected exception";
66
67     /**
68      * Additional properties to be added to the parameter builder.
69      */
70     protected Map<String, String> addProps;
71
72     /**
73      * Servers to be added to the parameter builder.
74      */
75     protected List<String> servers;
76
77     /**
78      * Parameter builder used to build topic parameters.
79      */
80     protected TopicParamsBuilder builder;
81
82     /**
83      * Initializes {@link #addProps}, {@link #servers}, and {@link #builder}.
84      */
85     public void setUp() {
86         addProps = new TreeMap<>();
87         addProps.put("my-key-A", "my-value-A");
88         addProps.put("my-key-B", "my-value-B");
89
90         servers = Arrays.asList("svra", "svrb");
91
92         builder = makeBuilder();
93     }
94
95     /**
96      * Makes a fully populated parameter builder.
97      * 
98      * @return a new parameter builder
99      */
100     public TopicParamsBuilder makeBuilder() {
101         return makeBuilder(addProps, servers);
102     }
103
104     /**
105      * Makes a fully populated parameter builder.
106      * 
107      * @param addProps additional properties to be added to the builder
108      * @param servers servers to be added to the builder
109      * @return a new parameter builder
110      */
111     public TopicParamsBuilder makeBuilder(Map<String, String> addProps, List<String> servers) {
112
113         return BusTopicParams.builder().additionalProps(addProps).aftEnvironment(MY_AFT_ENV).allowSelfSignedCerts(true)
114                         .apiKey(MY_API_KEY).apiSecret(MY_API_SECRET).basePath(MY_BASE_PATH).clientName(MY_CLIENT_NAME)
115                         .consumerGroup(MY_CONS_GROUP).consumerInstance(MY_CONS_INST).environment(MY_ENV)
116                         .fetchLimit(MY_FETCH_LIMIT).fetchTimeout(MY_FETCH_TIMEOUT).hostname(MY_HOST).latitude(MY_LAT)
117                         .longitude(MY_LONG).managed(true).partitionId(MY_PARTITION).partner(MY_PARTNER)
118                         .password(MY_PASSWD).port(MY_PORT).servers(servers).topic(MY_TOPIC).useHttps(true)
119                         .userName(MY_USERNAME);
120     }
121 }