92d5a8659bf6a8a8caf234a0256c62ac74bba5fd
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2018-2019 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 static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
24 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
25 import static org.junit.Assert.assertEquals;
26 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_EP_CONN_TIMEOUT_SUFFIX;
27 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_EP_READ_TIMEOUT_MS_SUFFIX;
28 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_ROUNDTRIP_TIMEOUT_MS_SUFFIX;
29 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_ROUTE_OFFER_SUFFIX;
30 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_SESSION_STICKINESS_REQUIRED_SUFFIX;
31 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_SUB_CONTEXT_PATH_SUFFIX;
32 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_DME2_VERSION_SUFFIX;
33
34 import java.util.Map;
35 import org.onap.policy.common.endpoints.event.comm.Topic;
36 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
37 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
38
39 /**
40  * Base class for DmaapTopicXxxFactory tests.
41  *
42  * @param <T> type of topic managed by the factory
43  */
44 public abstract class DmaapTopicFactoryTestBase<T extends Topic> extends BusTopicFactoryTestBase<T> {
45
46     public static final String MY_CONN_TIMEOUT = "200";
47     public static final String MY_READ_TIMEOUT = "201";
48     public static final String MY_ROUNDTRIP_TIMEOUT = "202";
49     public static final String MY_STICKINESS = "true";
50     public static final String MY_SUBCONTEXT = "my-subcontext";
51     public static final String MY_DME_VERSION = "my-version";
52
53     @Override
54     public void testBuildProperties() {
55
56         super.testBuildProperties();
57
58         // check properties specific to DMaaP/DME2
59         initFactory();
60
61         assertEquals(1, buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build()).size());
62
63         BusTopicParams params = getLastParams();
64         assertEquals(MY_ENV, params.getEnvironment());
65         assertEquals(MY_LAT, params.getLatitude());
66         assertEquals(MY_LONG, params.getLongitude());
67         assertEquals(MY_PARTNER, params.getPartner());
68
69         Map<String, String> add = params.getAdditionalProps();
70         assertEquals(MY_CONN_TIMEOUT, add.get(PolicyEndPointProperties.DME2_EP_CONN_TIMEOUT_PROPERTY));
71         assertEquals(MY_READ_TIMEOUT, add.get(PolicyEndPointProperties.DME2_READ_TIMEOUT_PROPERTY));
72         assertEquals(MY_ROUNDTRIP_TIMEOUT, add.get(PolicyEndPointProperties.DME2_ROUNDTRIP_TIMEOUT_PROPERTY));
73         assertEquals(MY_ROUTE, add.get(PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY));
74         assertEquals(MY_STICKINESS, add.get(PolicyEndPointProperties.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY));
75         assertEquals(MY_SUBCONTEXT, add.get(PolicyEndPointProperties.DME2_SUBCONTEXT_PATH_PROPERTY));
76         assertEquals(MY_DME_VERSION, add.get(PolicyEndPointProperties.DME2_VERSION_PROPERTY));
77     }
78
79     @Override
80     public void testBuildProperties_Variations() {
81         super.testBuildProperties_Variations();
82
83         // check "additional" properties
84         expectNullAddProp(PROPERTY_DMAAP_DME2_EP_CONN_TIMEOUT_SUFFIX,
85                         PolicyEndPointProperties.DME2_EP_CONN_TIMEOUT_PROPERTY);
86
87         expectNullAddProp(PROPERTY_DMAAP_DME2_EP_READ_TIMEOUT_MS_SUFFIX,
88                         PolicyEndPointProperties.DME2_READ_TIMEOUT_PROPERTY);
89
90         expectNullAddProp(PROPERTY_DMAAP_DME2_ROUNDTRIP_TIMEOUT_MS_SUFFIX,
91                         PolicyEndPointProperties.DME2_ROUNDTRIP_TIMEOUT_PROPERTY);
92
93         expectNullAddProp(PROPERTY_DMAAP_DME2_ROUTE_OFFER_SUFFIX, PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY);
94
95         expectNullAddProp(PROPERTY_DMAAP_DME2_SESSION_STICKINESS_REQUIRED_SUFFIX,
96                         PolicyEndPointProperties.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY);
97
98         expectNullAddProp(PROPERTY_DMAAP_DME2_SUB_CONTEXT_PATH_SUFFIX,
99                         PolicyEndPointProperties.DME2_SUBCONTEXT_PATH_PROPERTY);
100
101         expectNullAddProp(PROPERTY_DMAAP_DME2_VERSION_SUFFIX, PolicyEndPointProperties.DME2_VERSION_PROPERTY);
102     }
103
104     @Override
105     public void testBuildListOfStringString() {
106         super.testBuildListOfStringString();
107
108         // check parameters that were used
109         BusTopicParams params = getLastParams();
110         assertEquals(false, params.isAllowSelfSignedCerts());
111     }
112
113     /**
114      * Tests exception cases with get(topic).  DMaaP topics are special in that they
115      * throw IllegalArgumentException, even for an unknown topic name; all of the
116      * other Topic Factory classes throw IllegalStateException, thus we override
117      * the default test method.
118      */
119     @Override
120     public void testGet_Ex() {
121         // null topic
122         assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> getTopic(null));
123
124         // empty topic
125         assertThatIllegalArgumentException().as("empty topic").isThrownBy(() -> getTopic(""));
126
127         // unknown topic
128         initFactory();
129         buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
130
131         assertThatIllegalStateException().as("unknown topic").isThrownBy(() -> getTopic(TOPIC2));
132     }
133 }