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.test.dme2;
24 import com.att.aft.dme2.api.DME2Client;
25 import com.att.aft.dme2.api.DME2Exception;
26 import com.att.aft.dme2.internal.jackson.map.ObjectMapper;
28 import java.net.URISyntaxException;
29 import java.util.HashMap;
30 import java.util.Properties;
31 import junit.framework.TestCase;
32 import org.apache.logging.log4j.LogManager;
33 import org.apache.logging.log4j.Logger;
35 public class DME2TopicTest extends TestCase {
37 private String latitude;
38 private String longitude;
39 private String version;
40 private String serviceName;
42 private String partner;
43 private String protocol;
44 private String methodTypeGet;
45 private String methodTypePost;
46 private String methodTypeDelete;
47 private String methodTypePut;
50 private String password;
51 private String contenttype;
52 private String subContextPathGetAllTopic;
53 private String subContextPathGetOneTopic;
54 private String SubContextPathCreateTopic;
55 private String SubContextPathGetPublisherl;
56 private String SubContextPathGetPublisher;
57 private String SubContextPathGetPermitPublisher;
58 private String SubContextPathGetConsumer;
59 private String SubContextPathGetPermitConsumer;
60 private static final Logger LOGGER = LogManager.getLogger(DME2TopicTest.class);
62 public void createTopic(String url, Properties props, HashMap<String, String> mapData) {
63 LOGGER.info("create topic method starts");
64 if (!topicExist(url, props, mapData)) {
65 LOGGER.info("creating a new topic");
67 DME2Client sender = new DME2Client(new URI(url), 5000L);
68 sender.setAllowAllHttpReturnCodes(true);
69 sender.setMethod(props.getProperty("MethodTypePost"));
70 sender.setSubContext(props.getProperty("SubContextPathCreateTopic"));
71 TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("newTopic"),
72 props.getProperty("topicDescription"),
73 Integer.parseInt(props.getProperty("partition")),
74 Integer.parseInt(props.getProperty("replication")), Boolean.valueOf(props
75 .getProperty("txenabled")));
76 String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean);
77 sender.setPayload(jsonStringApiBean);
78 sender.addHeader("content-type", props.getProperty("contenttype"));
79 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
80 LOGGER.info("creating Topic");
81 String reply = sender.sendAndWait(5000L);
82 assertTrue(LoadPropertyFile.isValidJsonString(reply));
83 LOGGER.info("response =" + reply);
84 } catch (DME2Exception e) {
86 } catch (URISyntaxException e) {
88 } catch (Exception e) {
94 public boolean topicExist(String url, Properties props, HashMap<String, String> mapData) {
95 boolean topicExist = false;
97 LOGGER.info("Checking topic exists or not");
98 DME2Client sender = new DME2Client(new URI(url), 5000L);
99 sender.setAllowAllHttpReturnCodes(true);
100 sender.setMethod(props.getProperty("MethodTypeGet"));
101 String subcontextPath =
102 props.getProperty("subContextPathGetOneTopic") + props.getProperty("newTopic");
103 sender.setSubContext(subcontextPath);
104 sender.setPayload("");
105 sender.addHeader("content-type", props.getProperty("contenttype"));
106 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
107 String reply = sender.sendAndWait(5000L);
108 topicExist = LoadPropertyFile.isValidJsonString(reply);
109 LOGGER.info("Topic exist =" + topicExist);
110 } catch (DME2Exception e) {
112 } catch (URISyntaxException e) {
114 } catch (Exception e) {
120 public void testAllTopics() {
121 LOGGER.info("Test case get all topics initiated");
122 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
123 latitude = props.getProperty("Latitude");
124 longitude = props.getProperty("Longitude");
125 version = props.getProperty("Version");
126 serviceName = props.getProperty("ServiceName");
127 env = props.getProperty("Environment");
128 partner = props.getProperty("Partner");
129 subContextPathGetAllTopic = props.getProperty("subContextPathGetAllTopic");
130 protocol = props.getProperty("Protocol");
131 methodTypeGet = props.getProperty("MethodTypeGet");
132 user = props.getProperty("user");
133 password = props.getProperty("password");
134 contenttype = props.getProperty("contenttype");
136 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
138 + "envContext=" + env + "/" + "partner=" + partner;
139 LoadPropertyFile.loadAFTProperties(latitude, longitude); // } else {
140 HashMap<String, String> hm = new HashMap<String, String>();
141 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
142 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
143 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
145 DME2Client sender = new DME2Client(new URI(url), 5000L);
146 sender.setAllowAllHttpReturnCodes(true);
147 sender.setMethod(methodTypeGet);
148 sender.setSubContext(subContextPathGetAllTopic);
149 sender.setPayload("");
151 sender.addHeader("Content-Type", contenttype);
152 sender.setCredentials(user, password);
153 sender.setHeaders(hm);
155 LOGGER.info("Retrieving all topics");
156 String reply = sender.sendAndWait(5000L);
157 assertTrue(LoadPropertyFile.isValidJsonString(reply));
158 LOGGER.info("All Topics details = " + reply);
160 } catch (DME2Exception e) {
162 } catch (URISyntaxException e) {
164 } catch (Exception e) {
169 public void testOneTopic() {
170 LOGGER.info("Test case get one topic initiated");
171 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
172 latitude = props.getProperty("Latitude");
173 longitude = props.getProperty("Longitude");
174 version = props.getProperty("Version");
175 serviceName = props.getProperty("ServiceName");
176 env = props.getProperty("Environment");
177 partner = props.getProperty("Partner");
178 subContextPathGetOneTopic = props.getProperty("subContextPathGetOneTopic");
179 protocol = props.getProperty("Protocol");
180 methodTypeGet = props.getProperty("MethodTypeGet");
181 user = props.getProperty("user");
182 password = props.getProperty("password");
183 contenttype = props.getProperty("contenttype");
185 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
187 + "envContext=" + env + "/" + "partner=" + partner;
188 LoadPropertyFile.loadAFTProperties(latitude, longitude);
190 HashMap<String, String> hm = new HashMap<String, String>();
191 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
192 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
193 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
194 System.out.println("Retrieving topic detail");
195 if (!topicExist(url, props, hm)) {
196 createTopic(url, props, hm);
202 public void createTopicForDeletion(String url, Properties props,
203 HashMap<String, String> mapData) {
204 LOGGER.info("create topic method starts");
205 LOGGER.info("creating a new topic for deletion");
207 DME2Client sender = new DME2Client(new URI(url), 5000L);
208 sender.setAllowAllHttpReturnCodes(true);
209 sender.setMethod(props.getProperty("MethodTypePost"));
210 sender.setSubContext(props.getProperty("SubContextPathCreateTopic"));
211 TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("deleteTopic"),
212 props.getProperty("topicDescription"),
213 Integer.parseInt(props.getProperty("partition")),
214 Integer.parseInt(props.getProperty("replication")),
215 Boolean.valueOf(props.getProperty("txenabled")));
216 String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean);
217 sender.setPayload(jsonStringApiBean);
218 sender.addHeader("content-type", props.getProperty("contenttype"));
219 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
221 LOGGER.info("creating Topic");
222 String reply = sender.sendAndWait(5000L);
223 assertTrue(LoadPropertyFile.isValidJsonString(reply));
224 LOGGER.info("response =" + reply);
225 } catch (DME2Exception e) {
227 } catch (URISyntaxException e) {
229 } catch (Exception e) {
234 public boolean topicExistForDeletion(String url, Properties props,
235 HashMap<String, String> mapData) {
236 boolean topicExist = false;
238 LOGGER.info("Checking topic exists for deletion");
239 DME2Client sender = new DME2Client(new URI(url), 5000L);
240 sender.setAllowAllHttpReturnCodes(true);
241 sender.setMethod(props.getProperty("MethodTypeGet"));
242 String subcontextPath =
243 props.getProperty("subContextPathGetOneTopic") + props.getProperty("deleteTopic");
244 sender.setSubContext(subcontextPath);
245 sender.setPayload("");
246 sender.addHeader("content-type", props.getProperty("contenttype"));
247 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
248 String reply = sender.sendAndWait(5000L);
249 topicExist = LoadPropertyFile.isValidJsonString(reply);
250 LOGGER.info("Topic exist for deletion=" + topicExist);
251 } catch (DME2Exception e) {
253 } catch (URISyntaxException e) {
255 } catch (Exception e) {
261 public void testDeleteTopic() {
262 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
263 latitude = props.getProperty("Latitude");
264 longitude = props.getProperty("Longitude");
265 version = props.getProperty("Version");
266 serviceName = props.getProperty("ServiceName");
267 env = props.getProperty("Environment");
268 partner = props.getProperty("Partner");
269 SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic");
270 protocol = props.getProperty("Protocol");
271 methodTypePost = props.getProperty("MethodTypeDelete");
272 user = props.getProperty("user");
273 password = props.getProperty("password");
274 contenttype = props.getProperty("contenttypejson");
276 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
278 + "envContext=" + env + "/" + "partner=" + partner;
279 LoadPropertyFile.loadAFTProperties(latitude, longitude);
280 HashMap<String, String> hm = new HashMap<String, String>();
281 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
282 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
283 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
284 System.out.println("deleteing topic");
285 if (!topicExistForDeletion(url, props, hm)) {
286 createTopicForDeletion(url, props, hm);
287 deleteTopic(url, props, hm);
289 deleteTopic(url, props, hm);
293 public void deleteTopic(String url, Properties props, HashMap<String, String> mapData) {
295 DME2Client sender = new DME2Client(new URI(url), 5000L);
296 sender.setAllowAllHttpReturnCodes(true);
297 sender.setMethod(props.getProperty("MethodTypeDelete"));
298 String subsontextPathDelete = props.getProperty("subContextPathGetOneTopic")
299 + props.getProperty("deleteTopic");
300 sender.setSubContext(subsontextPathDelete);
301 sender.setPayload("");
302 sender.addHeader("content-type", props.getProperty("contenttype"));
303 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
304 System.out.println("Deleting Topic " + props.getProperty("deleteTopic"));
305 String reply = sender.sendAndWait(5000L);
306 assertNotNull(reply);
307 System.out.println("response =" + reply);
308 } catch (DME2Exception e) {
310 } catch (URISyntaxException e) {
312 } catch (Exception e) {
317 public void testGetProducersTopics() {
318 LOGGER.info("Test case get list of producers on topic");
319 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
320 latitude = props.getProperty("Latitude");
321 longitude = props.getProperty("Longitude");
322 version = props.getProperty("Version");
323 serviceName = props.getProperty("ServiceName");
324 env = props.getProperty("Environment");
325 partner = props.getProperty("Partner");
326 SubContextPathGetPublisher = props.getProperty("SubContextPathGetPublisher");
327 protocol = props.getProperty("Protocol");
328 methodTypeGet = props.getProperty("MethodTypeGet");
329 user = props.getProperty("user");
330 password = props.getProperty("password");
331 contenttype = props.getProperty("contenttype");
333 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
335 + "envContext=" + env + "/" + "partner=" + partner;
336 LoadPropertyFile.loadAFTProperties(latitude, longitude);
338 HashMap<String, String> hm = new HashMap<String, String>();
339 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
340 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
341 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
343 DME2Client sender = new DME2Client(new URI(url), 5000L);
344 sender.setAllowAllHttpReturnCodes(true);
345 sender.setMethod(methodTypeGet);
346 sender.setSubContext(SubContextPathGetPublisher);
347 sender.setPayload("");
349 sender.addHeader("Content-Type", contenttype);
350 sender.setCredentials(user, password);
351 sender.setHeaders(hm);
353 LOGGER.info("Retrieving List of publishers");
354 String reply = sender.sendAndWait(5000L);
355 assertTrue(LoadPropertyFile.isValidJsonString(reply));
356 LOGGER.info("All Publishers details = " + reply);
357 } catch (DME2Exception e) {
359 } catch (URISyntaxException e) {
361 } catch (Exception e) {
366 public void testGetConsumersTopics() {
367 LOGGER.info("Test case get list of consumers on topic ");
368 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
369 latitude = props.getProperty("Latitude");
370 longitude = props.getProperty("Longitude");
371 version = props.getProperty("Version");
372 serviceName = props.getProperty("ServiceName");
373 env = props.getProperty("Environment");
374 partner = props.getProperty("Partner");
375 SubContextPathGetConsumer = props.getProperty("SubContextPathGetConsumer");
376 protocol = props.getProperty("Protocol");
377 methodTypeGet = props.getProperty("MethodTypeGet");
378 user = props.getProperty("user");
379 password = props.getProperty("password");
380 contenttype = props.getProperty("contenttype");
382 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
384 + "envContext=" + env + "/" + "partner=" + partner;
385 LoadPropertyFile.loadAFTProperties(latitude, longitude);
387 HashMap<String, String> hm = new HashMap<String, String>();
388 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
389 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
390 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
392 DME2Client sender = new DME2Client(new URI(url), 5000L);
393 sender.setAllowAllHttpReturnCodes(true);
394 sender.setMethod(methodTypeGet);
395 sender.setSubContext(SubContextPathGetConsumer);
396 sender.setPayload("");
398 sender.addHeader("Content-Type", contenttype);
399 sender.setCredentials(user, password);
400 sender.setHeaders(hm);
402 LOGGER.info("Retrieving consumer details on topics");
403 String reply = sender.sendAndWait(5000L);
404 assertTrue(LoadPropertyFile.isValidJsonString(reply));
405 System.out.println("Reply from server = " + reply);
406 } catch (DME2Exception e) {
408 } catch (URISyntaxException e) {
410 } catch (Exception e) {
415 public void testCreateTopic() {
416 LOGGER.info("Test case create topic starts");
417 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
418 latitude = props.getProperty("Latitude");
419 longitude = props.getProperty("Longitude");
420 version = props.getProperty("Version");
421 serviceName = props.getProperty("ServiceName");
422 env = props.getProperty("Environment");
423 partner = props.getProperty("Partner");
424 SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic");
425 protocol = props.getProperty("Protocol");
426 methodTypePost = props.getProperty("MethodTypePost");
427 user = props.getProperty("user");
428 password = props.getProperty("password");
429 contenttype = props.getProperty("contenttypejson");
431 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
433 + "envContext=" + env + "/" + "partner=" + partner;
434 LoadPropertyFile.loadAFTProperties(latitude, longitude);
435 HashMap<String, String> hm = new HashMap<String, String>();
436 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
437 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
438 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
439 createTopic(url, props, hm);