baa54405bc0683a898049c236812d89373204d40
[dmaap/messagerouter/dmaapclient.git] / src / test / java / org / onap / dmaap / mr / tools / ValidatorUtilTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
11  *  
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=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22
23 package org.onap.dmaap.mr.tools;
24
25 import static org.junit.Assert.assertEquals;
26
27 import java.util.Properties;
28
29 import org.junit.Test;
30
31 import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
32
33 public class ValidatorUtilTest {
34
35     @Test
36     public void testValidateForDME2WithNullServiceName() {
37         Properties props = new Properties();
38         props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
39         try{
40             ValidatorUtil.validatePublisher(props);
41         } catch(IllegalArgumentException e) {
42             assertEquals(e.getMessage(), "Servicename is needed");
43         }
44
45     }
46     
47     @Test
48     public void testValidateForDME2WithNullTopic() {
49         Properties props = new Properties();
50         props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
51         props.setProperty("ServiceName", "ServiceName");
52         try{
53             ValidatorUtil.validatePublisher(props);
54         } catch(IllegalArgumentException e) {
55             assertEquals(e.getMessage(), "topic is needed");
56         }
57         
58     }
59     
60     @Test
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");
66         try{
67             ValidatorUtil.validatePublisher(props);
68         } catch(IllegalArgumentException e) {
69             assertEquals(e.getMessage(), "username is needed");
70         }
71         
72     }
73     
74     @Test
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");
81         
82         try{
83             ValidatorUtil.validatePublisher(props);
84         } catch(IllegalArgumentException e) {
85             assertEquals(e.getMessage(), "password is needed");
86         }
87         
88     }
89     
90     
91     
92     
93     @Test
94     public void testValidateForNonDME2WithNullServiceName() {
95         Properties props = new Properties();
96         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
97         try{
98             ValidatorUtil.validatePublisher(props);
99         } catch(IllegalArgumentException e) {
100             assertEquals(e.getMessage(), "Servicename is needed");
101         }
102         
103     }
104     
105     @Test
106     public void testValidateForNonDME2WithNullTopic() {
107         Properties props = new Properties();
108         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
109         props.setProperty("host", "ServiceName");
110         try{
111             ValidatorUtil.validatePublisher(props);
112         } catch(IllegalArgumentException e) {
113             assertEquals(e.getMessage(), "topic is needed");
114         }
115         
116     }
117     
118     @Test
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");
124         try{
125             ValidatorUtil.validatePublisher(props);
126         } catch(IllegalArgumentException e) {
127             assertEquals(e.getMessage(), "contenttype is needed");
128         }
129         
130     }
131
132     
133     @Test
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");
140         try{
141             ValidatorUtil.validatePublisher(props);
142         } catch(IllegalArgumentException e) {
143             assertEquals(e.getMessage(), "username is needed");
144         }
145         
146     }
147     
148     @Test
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");
156         
157         try{
158             ValidatorUtil.validatePublisher(props);
159         } catch(IllegalArgumentException e) {
160             assertEquals(e.getMessage(), "password is needed");
161         }
162         
163     }
164     
165     @Test
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");
174         
175         try{
176             ValidatorUtil.validatePublisher(props);
177         } catch(IllegalArgumentException e) {
178             assertEquals(e.getMessage(), "authKey is needed");
179         }
180         
181     }
182     
183     @Test
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");
193         
194         
195         try{
196             ValidatorUtil.validatePublisher(props);
197         } catch(IllegalArgumentException e) {
198             assertEquals(e.getMessage(), "authDate is needed");
199         }
200     }
201     
202     @Test
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");
213         
214         try{
215             ValidatorUtil.validatePublisher(props);
216         } catch(IllegalArgumentException e) {
217             assertEquals(e.getMessage(), "maxBatchSize is needed");
218         }
219     }
220         
221         
222         @Test
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");
234             
235             try{
236                 ValidatorUtil.validatePublisher(props);
237             } catch(IllegalArgumentException e) {
238                 assertEquals(e.getMessage(), "maxAgeMs is needed");
239             }
240             
241      
242         
243     }
244         
245         @Test
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");
258             
259             try{
260                 ValidatorUtil.validatePublisher(props);
261             } catch(IllegalArgumentException e) {
262                 assertEquals(e.getMessage(), "MessageSentThreadOccurance is needed");
263             }
264             
265         }
266             
267             
268             @Test
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");
281                 
282                 try{
283                     ValidatorUtil.validateSubscriber(props);
284                 } catch(IllegalArgumentException e) {
285                     assertEquals(e.getMessage(), "group is needed");
286                 }
287      }
288             
289             @Test
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");
303                 
304                 try{
305                     ValidatorUtil.validateSubscriber(props);
306                 } catch(IllegalArgumentException e) {
307                     assertEquals(e.getMessage(), "Consumer (Id)  is needed");
308                 }
309      }
310
311     
312     
313     
314     
315 }