1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 IBM Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2021 Orange.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 *******************************************************************************/
25 package org.onap.dmaap.mr.tools;
27 import org.junit.Test;
28 import org.onap.dmaap.mr.client.ProtocolType;
30 import java.util.Properties;
32 import static org.junit.Assert.*;
34 public class ValidatorUtilTest {
37 public void testValidateForDME2WithNullServiceName() {
38 Properties props = new Properties();
39 props.setProperty("TransportType", ProtocolType.DME2.getValue());
41 ValidatorUtil.validatePublisher(props);
43 } catch (IllegalArgumentException e) {
44 assertEquals("ServiceName is needed", e.getMessage());
50 public void testValidateForDME2WithNullTopic() {
51 Properties props = new Properties();
52 props.setProperty("TransportType", ProtocolType.DME2.getValue());
53 props.setProperty("ServiceName", "ServiceName");
55 ValidatorUtil.validatePublisher(props);
57 } catch (IllegalArgumentException e) {
58 assertEquals("topic is needed", e.getMessage());
64 public void testValidateForDME2WithNullUserName() {
65 Properties props = new Properties();
66 props.setProperty("TransportType", ProtocolType.DME2.getValue());
67 props.setProperty("ServiceName", "ServiceName");
68 props.setProperty("topic", "topic");
70 ValidatorUtil.validatePublisher(props);
72 } catch (IllegalArgumentException e) {
73 assertEquals("username is needed", e.getMessage());
79 public void testValidateForDME2WithNullPassword() {
80 Properties props = new Properties();
81 props.setProperty("TransportType", ProtocolType.DME2.getValue());
82 props.setProperty("ServiceName", "ServiceName");
83 props.setProperty("topic", "topic");
84 props.setProperty("username", "username");
87 ValidatorUtil.validatePublisher(props);
89 } catch (IllegalArgumentException e) {
90 assertEquals("password is needed", e.getMessage());
97 public void testValidateForNonDME2WithNullServiceName() {
98 Properties props = new Properties();
99 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
101 ValidatorUtil.validatePublisher(props);
103 } catch (IllegalArgumentException e) {
104 assertEquals("host is needed", e.getMessage());
110 public void testValidateForNonDME2WithNullTopic() {
111 Properties props = new Properties();
112 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
113 props.setProperty("host", "ServiceName");
115 ValidatorUtil.validatePublisher(props);
117 } catch (IllegalArgumentException e) {
118 assertEquals("topic is needed", e.getMessage());
124 public void testValidateForNonDME2WithNullContenttype() {
125 Properties props = new Properties();
126 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
127 props.setProperty("host", "ServiceName");
128 props.setProperty("topic", "topic");
130 ValidatorUtil.validatePublisher(props);
132 } catch (IllegalArgumentException e) {
133 assertEquals("contenttype is needed", e.getMessage());
140 public void testValidateForNonDME2WithNullUserName() {
141 Properties props = new Properties();
142 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
143 props.setProperty("host", "ServiceName");
144 props.setProperty("topic", "topic");
145 props.setProperty("contenttype", "contenttype");
147 ValidatorUtil.validatePublisher(props);
149 } catch (IllegalArgumentException e) {
150 assertEquals("username is needed", e.getMessage());
156 public void testValidateForNonDME2WithNullPassword() {
157 Properties props = new Properties();
158 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
159 props.setProperty("host", "ServiceName");
160 props.setProperty("topic", "topic");
161 props.setProperty("username", "username");
162 props.setProperty("contenttype", "contenttype");
165 ValidatorUtil.validatePublisher(props);
167 } catch (IllegalArgumentException e) {
168 assertEquals("password is needed", e.getMessage());
174 public void testValidateForNonDME2WithAuthKey() {
175 Properties props = new Properties();
176 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
177 props.setProperty("host", "ServiceName");
178 props.setProperty("topic", "topic");
179 props.setProperty("username", "username");
180 props.setProperty("contenttype", "contenttype");
181 props.setProperty("password", "password");
184 ValidatorUtil.validatePublisher(props);
186 } catch (IllegalArgumentException e) {
187 assertEquals("authKey is needed", e.getMessage());
193 public void testValidateForNonDME2WithOutAuthDate() {
194 Properties props = new Properties();
195 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
196 props.setProperty("host", "ServiceName");
197 props.setProperty("topic", "topic");
198 props.setProperty("username", "username");
199 props.setProperty("contenttype", "contenttype");
200 props.setProperty("password", "password");
201 props.setProperty("authKey", "authKey");
205 ValidatorUtil.validatePublisher(props);
207 } catch (IllegalArgumentException e) {
208 assertEquals("authDate is needed", e.getMessage());
213 public void testValidateForNonDME2WithAuthDate() {
214 Properties props = new Properties();
215 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
216 props.setProperty("host", "ServiceName");
217 props.setProperty("topic", "topic");
218 props.setProperty("username", "username");
219 props.setProperty("contenttype", "contenttype");
220 props.setProperty("password", "password");
221 props.setProperty("authKey", "authKey");
222 props.setProperty("authDate", "authDate");
225 ValidatorUtil.validatePublisher(props);
227 } catch (IllegalArgumentException e) {
228 assertEquals("maxBatchSize is needed", e.getMessage());
234 public void testValidateForNonDME2WithMaxAgeMs() {
235 Properties props = new Properties();
236 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
237 props.setProperty("host", "ServiceName");
238 props.setProperty("topic", "topic");
239 props.setProperty("username", "username");
240 props.setProperty("contenttype", "contenttype");
241 props.setProperty("password", "password");
242 props.setProperty("authKey", "authKey");
243 props.setProperty("authDate", "authDate");
244 props.setProperty("maxBatchSize", "maxBatchSize");
247 ValidatorUtil.validatePublisher(props);
249 } catch (IllegalArgumentException e) {
250 assertEquals("maxAgeMs is needed", e.getMessage());
257 public void testValidateForNonDME2WithMessageSentThreadOccurrence() {
258 Properties props = new Properties();
259 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
260 props.setProperty("host", "ServiceName");
261 props.setProperty("topic", "topic");
262 props.setProperty("username", "username");
263 props.setProperty("contenttype", "contenttype");
264 props.setProperty("password", "password");
265 props.setProperty("authKey", "authKey");
266 props.setProperty("authDate", "authDate");
267 props.setProperty("maxBatchSize", "maxBatchSize");
268 props.setProperty("maxAgeMs", "maxAgeMs");
271 ValidatorUtil.validatePublisher(props);
273 } catch (IllegalArgumentException e) {
274 assertEquals("MessageSentThreadOccurrence is needed", e.getMessage());
281 public void testValidateSubscriberWithoutGroup() {
282 Properties props = new Properties();
283 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
284 props.setProperty("host", "ServiceName");
285 props.setProperty("topic", "topic");
286 props.setProperty("username", "username");
287 props.setProperty("contenttype", "contenttype");
288 props.setProperty("password", "password");
289 props.setProperty("authKey", "authKey");
290 props.setProperty("authDate", "authDate");
291 props.setProperty("maxBatchSize", "maxBatchSize");
292 props.setProperty("maxAgeMs", "maxAgeMs");
295 ValidatorUtil.validateSubscriber(props);
297 } catch (IllegalArgumentException e) {
298 assertEquals("group is needed", e.getMessage());
303 public void testValidateSubscriberWithoutCustomer() {
304 Properties props = new Properties();
305 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
306 props.setProperty("host", "ServiceName");
307 props.setProperty("topic", "topic");
308 props.setProperty("username", "username");
309 props.setProperty("contenttype", "contenttype");
310 props.setProperty("password", "password");
311 props.setProperty("authKey", "authKey");
312 props.setProperty("authDate", "authDate");
313 props.setProperty("maxBatchSize", "maxBatchSize");
314 props.setProperty("maxAgeMs", "maxAgeMs");
315 props.setProperty("group", "group");
318 ValidatorUtil.validateSubscriber(props);
320 } catch (IllegalArgumentException e) {
321 assertEquals("Consumer (id) is needed", e.getMessage());
326 public void testValidatePublisher() {
327 Properties props = new Properties();
328 props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue());
329 props.setProperty("host", "ServiceName");
330 props.setProperty("topic", "topic");
331 props.setProperty("username", "username");
332 props.setProperty("contenttype", "contenttype");
333 props.setProperty("password", "password");
334 props.setProperty("authKey", "authKey");
335 props.setProperty("authDate", "authDate");
336 props.setProperty("maxBatchSize", "maxBatchSize");
337 props.setProperty("maxAgeMs", "maxAgeMs");
338 props.setProperty("MessageSentThreadOccurrence", "10");
341 ValidatorUtil.validatePublisher(props);
342 } catch (IllegalArgumentException e) {
347 props.remove("MessageSentThreadOccurrence");
348 props.setProperty("MessageSentThreadOccurance", "10");
350 ValidatorUtil.validatePublisher(props);
351 } catch (IllegalArgumentException e) {