2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.common.endpoints.event.comm.bus;
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;
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;
40 * Base class for DmaapTopicXxxFactory tests.
42 * @param <T> type of topic managed by the factory
44 public abstract class DmaapTopicFactoryTestBase<T extends Topic> extends BusTopicFactoryTestBase<T> {
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";
54 public void testBuildProperties() {
56 super.testBuildProperties();
58 // check properties specific to DMaaP/DME2
61 assertEquals(1, buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build()).size());
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());
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));
80 public void testBuildProperties_Variations() {
81 super.testBuildProperties_Variations();
83 // check "additional" properties
84 expectNullAddProp(PROPERTY_DMAAP_DME2_EP_CONN_TIMEOUT_SUFFIX,
85 PolicyEndPointProperties.DME2_EP_CONN_TIMEOUT_PROPERTY);
87 expectNullAddProp(PROPERTY_DMAAP_DME2_EP_READ_TIMEOUT_MS_SUFFIX,
88 PolicyEndPointProperties.DME2_READ_TIMEOUT_PROPERTY);
90 expectNullAddProp(PROPERTY_DMAAP_DME2_ROUNDTRIP_TIMEOUT_MS_SUFFIX,
91 PolicyEndPointProperties.DME2_ROUNDTRIP_TIMEOUT_PROPERTY);
93 expectNullAddProp(PROPERTY_DMAAP_DME2_ROUTE_OFFER_SUFFIX, PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY);
95 expectNullAddProp(PROPERTY_DMAAP_DME2_SESSION_STICKINESS_REQUIRED_SUFFIX,
96 PolicyEndPointProperties.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY);
98 expectNullAddProp(PROPERTY_DMAAP_DME2_SUB_CONTEXT_PATH_SUFFIX,
99 PolicyEndPointProperties.DME2_SUBCONTEXT_PATH_PROPERTY);
101 expectNullAddProp(PROPERTY_DMAAP_DME2_VERSION_SUFFIX, PolicyEndPointProperties.DME2_VERSION_PROPERTY);
105 public void testBuildListOfStringString() {
106 super.testBuildListOfStringString();
108 // check parameters that were used
109 BusTopicParams params = getLastParams();
110 assertEquals(false, params.isAllowSelfSignedCerts());
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.
120 public void testGet_Ex() {
122 assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> getTopic(null));
125 assertThatIllegalArgumentException().as("empty topic").isThrownBy(() -> getTopic(""));
129 buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
131 assertThatIllegalStateException().as("unknown topic").isThrownBy(() -> getTopic(TOPIC2));