Test cases added 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 }