added couple of cases for ValidatorUtil.java
[dmaap/messagerouter/dmaapclient.git] / src / test / java / com / att / nsa / mr / tools / ValidatorUtilTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018 Nokia
6  * ================================================================================
7  * Modifications Copyright © 2018 IBM.
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  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 /**
24  * @author marcin.migdal@nokia.com
25  */
26 package com.att.nsa.mr.tools;
27
28 import static org.junit.Assert.assertEquals;
29
30 import java.util.Properties;
31
32 import org.junit.Test;
33
34 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
35
36 public class ValidatorUtilTest {
37
38     @Test
39     public void testValidateForDME2WithNullServiceName() {
40         Properties props = new Properties();
41         props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
42         try{
43             ValidatorUtil.validatePublisher(props);
44         } catch(IllegalArgumentException e) {
45             assertEquals(e.getMessage(), "Servicename is needed");
46         }
47         
48     }
49     
50     @Test
51     public void testValidateForDME2WithNullTopic() {
52         Properties props = new Properties();
53         props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
54         props.setProperty("ServiceName", "ServiceName");
55         try{
56             ValidatorUtil.validatePublisher(props);
57         } catch(IllegalArgumentException e) {
58             assertEquals(e.getMessage(), "topic is needed");
59         }
60         
61     }
62     
63     @Test
64     public void testValidateForDME2WithNullUserName() {
65         Properties props = new Properties();
66         props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
67         props.setProperty("ServiceName", "ServiceName");
68         props.setProperty("topic", "topic");
69         try{
70             ValidatorUtil.validatePublisher(props);
71         } catch(IllegalArgumentException e) {
72             assertEquals(e.getMessage(), "username is needed");
73         }
74         
75     }
76     
77     @Test
78     public void testValidateForDME2WithNullPassword() {
79         Properties props = new Properties();
80         props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue());
81         props.setProperty("ServiceName", "ServiceName");
82         props.setProperty("topic", "topic");
83         props.setProperty("username", "username");
84         
85         try{
86             ValidatorUtil.validatePublisher(props);
87         } catch(IllegalArgumentException e) {
88             assertEquals(e.getMessage(), "password is needed");
89         }
90         
91     }
92     
93     
94     
95     
96     @Test
97     public void testValidateForNonDME2WithNullServiceName() {
98         Properties props = new Properties();
99         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
100         try{
101             ValidatorUtil.validatePublisher(props);
102         } catch(IllegalArgumentException e) {
103             assertEquals(e.getMessage(), "Servicename is needed");
104         }
105         
106     }
107     
108     @Test
109     public void testValidateForNonDME2WithNullTopic() {
110         Properties props = new Properties();
111         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
112         props.setProperty("host", "ServiceName");
113         try{
114             ValidatorUtil.validatePublisher(props);
115         } catch(IllegalArgumentException e) {
116             assertEquals(e.getMessage(), "topic is needed");
117         }
118         
119     }
120     
121     @Test
122     public void testValidateForNonDME2WithNullContenttype() {
123         Properties props = new Properties();
124         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
125         props.setProperty("host", "ServiceName");
126         props.setProperty("topic", "topic");
127         try{
128             ValidatorUtil.validatePublisher(props);
129         } catch(IllegalArgumentException e) {
130             assertEquals(e.getMessage(), "contenttype is needed");
131         }
132         
133     }
134
135     
136     @Test
137     public void testValidateForNonDME2WithNullUserName() {
138         Properties props = new Properties();
139         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
140         props.setProperty("host", "ServiceName");
141         props.setProperty("topic", "topic");
142         props.setProperty("contenttype", "contenttype");
143         try{
144             ValidatorUtil.validatePublisher(props);
145         } catch(IllegalArgumentException e) {
146             assertEquals(e.getMessage(), "username is needed");
147         }
148         
149     }
150     
151     @Test
152     public void testValidateForNonDME2WithNullPassword() {
153         Properties props = new Properties();
154         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
155         props.setProperty("host", "ServiceName");
156         props.setProperty("topic", "topic");
157         props.setProperty("username", "username");
158         props.setProperty("contenttype", "contenttype");
159         
160         try{
161             ValidatorUtil.validatePublisher(props);
162         } catch(IllegalArgumentException e) {
163             assertEquals(e.getMessage(), "password is needed");
164         }
165         
166     }
167     
168     @Test
169     public void testValidateForNonDME2WithAuthKey() {
170         Properties props = new Properties();
171         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
172         props.setProperty("host", "ServiceName");
173         props.setProperty("topic", "topic");
174         props.setProperty("username", "username");
175         props.setProperty("contenttype", "contenttype");
176         props.setProperty("password", "password");
177         
178         try{
179             ValidatorUtil.validatePublisher(props);
180         } catch(IllegalArgumentException e) {
181             assertEquals(e.getMessage(), "authKey is needed");
182         }
183         
184     }
185     
186     @Test
187     public void testValidateForNonDME2WithAuthDate() {
188         Properties props = new Properties();
189         props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue());
190         props.setProperty("host", "ServiceName");
191         props.setProperty("topic", "topic");
192         props.setProperty("username", "username");
193         props.setProperty("contenttype", "contenttype");
194         props.setProperty("password", "password");
195         props.setProperty("authKey", "authKey");
196         
197         try{
198             ValidatorUtil.validatePublisher(props);
199         } catch(IllegalArgumentException e) {
200             assertEquals(e.getMessage(), "authDate is needed");
201         }
202         
203     }
204     
205     
206     
207     
208 }