update the package name
[dmaap/messagerouter/dmaapclient.git] / src / main / java / org / onap / dmaap / mr / tools / ValidatorUtil.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T 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 package org.onap.dmaap.mr.tools;
23
24 import java.util.Properties;
25
26 import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
27
28 public class ValidatorUtil {
29
30         public  static void validatePublisher(Properties props) {
31                 String transportType = props.getProperty("TransportType");
32                 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(transportType)) {
33                         validateForDME2(props);
34                 } else {
35                          validateForNonDME2(props);
36                 }
37                 String maxBatchSize  = props.getProperty("maxBatchSize");
38                 if (maxBatchSize == null || maxBatchSize.isEmpty()) {
39                         throw new IllegalArgumentException ( "maxBatchSize is needed" );
40                 }
41                 String maxAgeMs  = props.getProperty("maxAgeMs");
42                 if (maxAgeMs == null || maxAgeMs.isEmpty()) {
43                         throw new IllegalArgumentException ( "maxAgeMs is needed" );
44                 }
45                 String messageSentThreadOccurance  = props.getProperty("MessageSentThreadOccurance");
46                 if (messageSentThreadOccurance == null || messageSentThreadOccurance.isEmpty()) {
47                         throw new IllegalArgumentException ( "MessageSentThreadOccurance is needed" );
48                 }
49                 
50         }
51
52         public  static void validateSubscriber(Properties props) {
53                 String transportType = props.getProperty("TransportType");
54                 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(transportType)) {
55                         validateForDME2(props);
56                 } else {
57                          validateForNonDME2(props);
58                 }
59                 String group  = props.getProperty("group");
60                 if (group == null || group.isEmpty()) {
61                         throw new IllegalArgumentException ( "group is needed" );
62                 }
63                 String id  = props.getProperty("id");
64                 if (id == null || id.isEmpty()) {
65                         throw new IllegalArgumentException ( "Consumer (Id)  is needed" );
66                 }
67         }
68         
69         private  static void validateForDME2(Properties props) {
70                 String serviceName  = props.getProperty("ServiceName");
71                 if (serviceName == null || serviceName.isEmpty()) {
72                         throw new IllegalArgumentException ( "Servicename is needed" );
73                 }
74                 String topic  = props.getProperty("topic");
75                 if (topic == null || topic.isEmpty()) {
76                         throw new IllegalArgumentException ( "topic is needed" );
77                 }
78                 String username  = props.getProperty("username");
79                 if (username == null || username.isEmpty()) {
80                         throw new IllegalArgumentException ( "username is needed" );
81                 }
82                 String password  = props.getProperty("password");
83                 if (password == null || password.isEmpty()) {
84                         throw new IllegalArgumentException ( "password is needed" );
85                 }
86                 String dME2preferredRouterFilePath  = props.getProperty("DME2preferredRouterFilePath");
87                 if (dME2preferredRouterFilePath == null || dME2preferredRouterFilePath.isEmpty()) {
88                         throw new IllegalArgumentException ( "DME2preferredRouterFilePath is needed" );
89                 }
90                 String partner  = props.getProperty("Partner");
91                 String routeOffer  = props.getProperty("routeOffer");
92                 if ((partner == null || partner.isEmpty()) && (routeOffer == null || routeOffer.isEmpty())) {
93                         throw new IllegalArgumentException ( "Partner or  routeOffer is needed" );
94                 }
95                 String protocol  = props.getProperty("Protocol");
96                 if (protocol == null || protocol.isEmpty()) {
97                         throw new IllegalArgumentException ( "Protocol is needed" );
98                 }
99                 String methodType  = props.getProperty("MethodType");
100                 if (methodType == null || methodType.isEmpty()) {
101                         throw new IllegalArgumentException ( "MethodType is needed" );
102                 }
103                 String contenttype  = props.getProperty("contenttype");
104                 if (contenttype == null || contenttype.isEmpty()) {
105                         throw new IllegalArgumentException ( "contenttype is needed" );
106                 }
107                 String latitude  = props.getProperty("Latitude");
108                 if (latitude == null || latitude.isEmpty()) {
109                         throw new IllegalArgumentException ( "Latitude is needed" );
110                 }
111                 String longitude  = props.getProperty("Longitude");
112                 if (longitude == null || longitude.isEmpty()) {
113                         throw new IllegalArgumentException ( "Longitude is needed" );
114                 }
115                 String aftEnv  = props.getProperty("AFT_ENVIRONMENT");
116                 if (aftEnv == null || aftEnv.isEmpty()) {
117                         throw new IllegalArgumentException ( "AFT_ENVIRONMENT is needed" );
118                 }
119                 String version  = props.getProperty("Version");
120                 if (version == null || version.isEmpty()) {
121                         throw new IllegalArgumentException ( "Version is needed" );
122                 }
123                 String environment  = props.getProperty("Environment");
124                 if (environment == null || environment.isEmpty()) {
125                         throw new IllegalArgumentException ( "Environment is needed" );
126                 }
127                 String subContextPath  = props.getProperty("SubContextPath");
128                 if (subContextPath == null || subContextPath.isEmpty()) {
129                         throw new IllegalArgumentException ( "SubContextPath is needed" );
130                 }
131                 String sessionstickinessrequired  = props.getProperty("sessionstickinessrequired");
132                 if (sessionstickinessrequired == null || sessionstickinessrequired.isEmpty()) {
133                         throw new IllegalArgumentException ( "sessionstickinessrequired  is needed" );
134                 }
135         }
136         
137         private  static void validateForNonDME2(Properties props) {
138                 String transportType = props.getProperty("TransportType");
139                 String host  = props.getProperty("host");
140                 if (host == null || host.isEmpty()) {
141                         throw new IllegalArgumentException ( "Servicename is needed" );
142                 }
143                 String topic  = props.getProperty("topic");
144                 if (topic == null || topic.isEmpty()) {
145                         throw new IllegalArgumentException ( "topic is needed" );
146                 }
147                 String contenttype  = props.getProperty("contenttype");
148                 if (contenttype == null || contenttype.isEmpty()) {
149                         throw new IllegalArgumentException ( "contenttype is needed" );
150                 }
151                 if (!ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(transportType)){
152                 String username  = props.getProperty("username");
153                 if (username == null || username.isEmpty()) {
154                         throw new IllegalArgumentException ( "username is needed" );
155                 }
156                 String password  = props.getProperty("password");
157                 if (password == null || password.isEmpty()) {
158                         throw new IllegalArgumentException ( "password is needed" );
159                 }
160                 }
161                 if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(transportType)) {
162                         String authKey  = props.getProperty("authKey");
163                         if (authKey == null || authKey.isEmpty()) {
164                                 throw new IllegalArgumentException ( "authKey is needed" );
165                         }
166                         String authDate  = props.getProperty("authDate");
167                         if (authDate == null || authDate.isEmpty()) {
168                                 throw new IllegalArgumentException ( "authDate is needed" );
169                         }
170                         
171                 }
172         }       
173         
174 }