1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
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 *******************************************************************************/
22 package org.onap.dmaap.mr.tools;
24 import java.util.Properties;
26 import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
28 public class ValidatorUtil {
30 public static void validatePublisher(Properties props) {
31 String transportType = props.getProperty("TransportType");
32 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(transportType)) {
33 validateForDME2(props);
35 validateForNonDME2(props);
37 String maxBatchSize = props.getProperty("maxBatchSize");
38 if (maxBatchSize == null || maxBatchSize.isEmpty()) {
39 throw new IllegalArgumentException ( "maxBatchSize is needed" );
41 String maxAgeMs = props.getProperty("maxAgeMs");
42 if (maxAgeMs == null || maxAgeMs.isEmpty()) {
43 throw new IllegalArgumentException ( "maxAgeMs is needed" );
45 String messageSentThreadOccurance = props.getProperty("MessageSentThreadOccurance");
46 if (messageSentThreadOccurance == null || messageSentThreadOccurance.isEmpty()) {
47 throw new IllegalArgumentException ( "MessageSentThreadOccurance is needed" );
52 public static void validateSubscriber(Properties props) {
53 String transportType = props.getProperty("TransportType");
54 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(transportType)) {
55 validateForDME2(props);
57 validateForNonDME2(props);
59 String group = props.getProperty("group");
60 if (group == null || group.isEmpty()) {
61 throw new IllegalArgumentException ( "group is needed" );
63 String id = props.getProperty("id");
64 if (id == null || id.isEmpty()) {
65 throw new IllegalArgumentException ( "Consumer (Id) is needed" );
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" );
74 String topic = props.getProperty("topic");
75 if (topic == null || topic.isEmpty()) {
76 throw new IllegalArgumentException ( "topic is needed" );
78 String username = props.getProperty("username");
79 if (username == null || username.isEmpty()) {
80 throw new IllegalArgumentException ( "username is needed" );
82 String password = props.getProperty("password");
83 if (password == null || password.isEmpty()) {
84 throw new IllegalArgumentException ( "password is needed" );
86 String dME2preferredRouterFilePath = props.getProperty("DME2preferredRouterFilePath");
87 if (dME2preferredRouterFilePath == null || dME2preferredRouterFilePath.isEmpty()) {
88 throw new IllegalArgumentException ( "DME2preferredRouterFilePath is needed" );
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" );
95 String protocol = props.getProperty("Protocol");
96 if (protocol == null || protocol.isEmpty()) {
97 throw new IllegalArgumentException ( "Protocol is needed" );
99 String methodType = props.getProperty("MethodType");
100 if (methodType == null || methodType.isEmpty()) {
101 throw new IllegalArgumentException ( "MethodType is needed" );
103 String contenttype = props.getProperty("contenttype");
104 if (contenttype == null || contenttype.isEmpty()) {
105 throw new IllegalArgumentException ( "contenttype is needed" );
107 String latitude = props.getProperty("Latitude");
108 if (latitude == null || latitude.isEmpty()) {
109 throw new IllegalArgumentException ( "Latitude is needed" );
111 String longitude = props.getProperty("Longitude");
112 if (longitude == null || longitude.isEmpty()) {
113 throw new IllegalArgumentException ( "Longitude is needed" );
115 String aftEnv = props.getProperty("AFT_ENVIRONMENT");
116 if (aftEnv == null || aftEnv.isEmpty()) {
117 throw new IllegalArgumentException ( "AFT_ENVIRONMENT is needed" );
119 String version = props.getProperty("Version");
120 if (version == null || version.isEmpty()) {
121 throw new IllegalArgumentException ( "Version is needed" );
123 String environment = props.getProperty("Environment");
124 if (environment == null || environment.isEmpty()) {
125 throw new IllegalArgumentException ( "Environment is needed" );
127 String subContextPath = props.getProperty("SubContextPath");
128 if (subContextPath == null || subContextPath.isEmpty()) {
129 throw new IllegalArgumentException ( "SubContextPath is needed" );
131 String sessionstickinessrequired = props.getProperty("sessionstickinessrequired");
132 if (sessionstickinessrequired == null || sessionstickinessrequired.isEmpty()) {
133 throw new IllegalArgumentException ( "sessionstickinessrequired is needed" );
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" );
143 String topic = props.getProperty("topic");
144 if (topic == null || topic.isEmpty()) {
145 throw new IllegalArgumentException ( "topic is needed" );
147 String contenttype = props.getProperty("contenttype");
148 if (contenttype == null || contenttype.isEmpty()) {
149 throw new IllegalArgumentException ( "contenttype is needed" );
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" );
156 String password = props.getProperty("password");
157 if (password == null || password.isEmpty()) {
158 throw new IllegalArgumentException ( "password is needed" );
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" );
166 String authDate = props.getProperty("authDate");
167 if (authDate == null || authDate.isEmpty()) {
168 throw new IllegalArgumentException ( "authDate is needed" );