1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 IBM 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 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
23 package com.att.nsa.mr.tools;
25 import static org.junit.Assert.assertEquals;
27 import java.util.Properties;
29 import org.junit.Test;
31 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
33 public class ValidatorUtilTest {
36 public void testValidateForDME2WithNullServiceName() {
37 Properties props = new Properties();
38 props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
40 ValidatorUtil.validatePublisher(props);
41 } catch(IllegalArgumentException e) {
42 assertEquals(e.getMessage(), "Servicename is needed");
48 public void testValidateForDME2WithNullTopic() {
49 Properties props = new Properties();
50 props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
51 props.setProperty("ServiceName", "ServiceName");
53 ValidatorUtil.validatePublisher(props);
54 } catch(IllegalArgumentException e) {
55 assertEquals(e.getMessage(), "topic is needed");
61 public void testValidateForDME2WithNullUserName() {
62 Properties props = new Properties();
63 props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
64 props.setProperty("ServiceName", "ServiceName");
65 props.setProperty("topic", "topic");
67 ValidatorUtil.validatePublisher(props);
68 } catch(IllegalArgumentException e) {
69 assertEquals(e.getMessage(), "username is needed");
75 public void testValidateForDME2WithNullPassword() {
76 Properties props = new Properties();
77 props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
78 props.setProperty("ServiceName", "ServiceName");
79 props.setProperty("topic", "topic");
80 props.setProperty("username", "username");
83 ValidatorUtil.validatePublisher(props);
84 } catch(IllegalArgumentException e) {
85 assertEquals(e.getMessage(), "password is needed");
94 public void testValidateForNonDME2WithNullServiceName() {
95 Properties props = new Properties();
96 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
98 ValidatorUtil.validatePublisher(props);
99 } catch(IllegalArgumentException e) {
100 assertEquals(e.getMessage(), "Servicename is needed");
106 public void testValidateForNonDME2WithNullTopic() {
107 Properties props = new Properties();
108 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
109 props.setProperty("host", "ServiceName");
111 ValidatorUtil.validatePublisher(props);
112 } catch(IllegalArgumentException e) {
113 assertEquals(e.getMessage(), "topic is needed");
119 public void testValidateForNonDME2WithNullContenttype() {
120 Properties props = new Properties();
121 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
122 props.setProperty("host", "ServiceName");
123 props.setProperty("topic", "topic");
125 ValidatorUtil.validatePublisher(props);
126 } catch(IllegalArgumentException e) {
127 assertEquals(e.getMessage(), "contenttype is needed");
134 public void testValidateForNonDME2WithNullUserName() {
135 Properties props = new Properties();
136 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
137 props.setProperty("host", "ServiceName");
138 props.setProperty("topic", "topic");
139 props.setProperty("contenttype", "contenttype");
141 ValidatorUtil.validatePublisher(props);
142 } catch(IllegalArgumentException e) {
143 assertEquals(e.getMessage(), "username is needed");
149 public void testValidateForNonDME2WithNullPassword() {
150 Properties props = new Properties();
151 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
152 props.setProperty("host", "ServiceName");
153 props.setProperty("topic", "topic");
154 props.setProperty("username", "username");
155 props.setProperty("contenttype", "contenttype");
158 ValidatorUtil.validatePublisher(props);
159 } catch(IllegalArgumentException e) {
160 assertEquals(e.getMessage(), "password is needed");
166 public void testValidateForNonDME2WithAuthKey() {
167 Properties props = new Properties();
168 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
169 props.setProperty("host", "ServiceName");
170 props.setProperty("topic", "topic");
171 props.setProperty("username", "username");
172 props.setProperty("contenttype", "contenttype");
173 props.setProperty("password", "password");
176 ValidatorUtil.validatePublisher(props);
177 } catch(IllegalArgumentException e) {
178 assertEquals(e.getMessage(), "authKey is needed");
184 public void testValidateForNonDME2WithOutAuthDate() {
185 Properties props = new Properties();
186 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
187 props.setProperty("host", "ServiceName");
188 props.setProperty("topic", "topic");
189 props.setProperty("username", "username");
190 props.setProperty("contenttype", "contenttype");
191 props.setProperty("password", "password");
192 props.setProperty("authKey", "authKey");
196 ValidatorUtil.validatePublisher(props);
197 } catch(IllegalArgumentException e) {
198 assertEquals(e.getMessage(), "authDate is needed");
203 public void testValidateForNonDME2WithAuthDate() {
204 Properties props = new Properties();
205 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
206 props.setProperty("host", "ServiceName");
207 props.setProperty("topic", "topic");
208 props.setProperty("username", "username");
209 props.setProperty("contenttype", "contenttype");
210 props.setProperty("password", "password");
211 props.setProperty("authKey", "authKey");
212 props.setProperty("authDate", "authDate");
215 ValidatorUtil.validatePublisher(props);
216 } catch(IllegalArgumentException e) {
217 assertEquals(e.getMessage(), "maxBatchSize is needed");
223 public void testValidateForNonDME2WithMaxAgeMs() {
224 Properties props = new Properties();
225 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
226 props.setProperty("host", "ServiceName");
227 props.setProperty("topic", "topic");
228 props.setProperty("username", "username");
229 props.setProperty("contenttype", "contenttype");
230 props.setProperty("password", "password");
231 props.setProperty("authKey", "authKey");
232 props.setProperty("authDate", "authDate");
233 props.setProperty("maxBatchSize", "maxBatchSize");
236 ValidatorUtil.validatePublisher(props);
237 } catch(IllegalArgumentException e) {
238 assertEquals(e.getMessage(), "maxAgeMs is needed");
246 public void testValidateForNonDME2WithMessageSentThreadOccurance() {
247 Properties props = new Properties();
248 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
249 props.setProperty("host", "ServiceName");
250 props.setProperty("topic", "topic");
251 props.setProperty("username", "username");
252 props.setProperty("contenttype", "contenttype");
253 props.setProperty("password", "password");
254 props.setProperty("authKey", "authKey");
255 props.setProperty("authDate", "authDate");
256 props.setProperty("maxBatchSize", "maxBatchSize");
257 props.setProperty("maxAgeMs", "maxAgeMs");
260 ValidatorUtil.validatePublisher(props);
261 } catch(IllegalArgumentException e) {
262 assertEquals(e.getMessage(), "MessageSentThreadOccurance is needed");
269 public void testValidateSubscriberWithoutGroup() {
270 Properties props = new Properties();
271 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
272 props.setProperty("host", "ServiceName");
273 props.setProperty("topic", "topic");
274 props.setProperty("username", "username");
275 props.setProperty("contenttype", "contenttype");
276 props.setProperty("password", "password");
277 props.setProperty("authKey", "authKey");
278 props.setProperty("authDate", "authDate");
279 props.setProperty("maxBatchSize", "maxBatchSize");
280 props.setProperty("maxAgeMs", "maxAgeMs");
283 ValidatorUtil.validateSubscriber(props);
284 } catch(IllegalArgumentException e) {
285 assertEquals(e.getMessage(), "group is needed");
290 public void testValidateSubscriberWithoutCustomer() {
291 Properties props = new Properties();
292 props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
293 props.setProperty("host", "ServiceName");
294 props.setProperty("topic", "topic");
295 props.setProperty("username", "username");
296 props.setProperty("contenttype", "contenttype");
297 props.setProperty("password", "password");
298 props.setProperty("authKey", "authKey");
299 props.setProperty("authDate", "authDate");
300 props.setProperty("maxBatchSize", "maxBatchSize");
301 props.setProperty("maxAgeMs", "maxAgeMs");
302 props.setProperty("group", "group");
305 ValidatorUtil.validateSubscriber(props);
306 } catch(IllegalArgumentException e) {
307 assertEquals(e.getMessage(), "Consumer (Id) is needed");