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;
25 import java.net.URISyntaxException;
26 import java.util.HashMap;
27 import java.util.Properties;
29 import javax.ws.rs.client.Entity;
31 import org.apache.log4j.Logger;
33 import junit.framework.TestCase;
35 import com.att.aft.dme2.api.DME2Client;
36 import com.att.aft.dme2.api.DME2Exception;
37 import com.att.aft.dme2.internal.jackson.map.ObjectMapper;
39 public class DME2TopicTest extends TestCase {
40 private String latitude;
41 private String longitude;
42 private String version;
43 private String serviceName;
45 private String partner;
46 private String protocol;
47 private String methodTypeGet;
48 private String methodTypePost;
49 private String methodTypeDelete;
50 private String methodTypePut;
53 private String password;
54 private String contenttype;
55 private String subContextPathGetAllTopic;
56 private String subContextPathGetOneTopic;
57 private String SubContextPathCreateTopic;
58 private String SubContextPathGetPublisherl;
59 private String SubContextPathGetPublisher;
60 private String SubContextPathGetPermitPublisher;
61 private String SubContextPathGetConsumer;
62 private String SubContextPathGetPermitConsumer;
63 private static final Logger LOGGER = Logger.getLogger(DME2TopicTest.class);
65 public void createTopic(String url, Properties props, HashMap<String, String> mapData) {
66 LOGGER.info("create topic method starts");
67 if (!topicExist(url, props, mapData)) {
68 LOGGER.info("creating a new topic");
70 DME2Client sender = new DME2Client(new URI(url), 5000L);
71 sender.setAllowAllHttpReturnCodes(true);
72 sender.setMethod(props.getProperty("MethodTypePost"));
73 sender.setSubContext(props.getProperty("SubContextPathCreateTopic"));
74 TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("newTopic"),
75 props.getProperty("topicDescription"), Integer.parseInt(props.getProperty("partition")),
76 Integer.parseInt(props.getProperty("replication")), Boolean.valueOf(props
77 .getProperty("txenabled")));
78 String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean);
79 sender.setPayload(jsonStringApiBean);
80 sender.addHeader("content-type", props.getProperty("contenttype"));
81 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
83 LOGGER.info("creating Topic");
84 String reply = sender.sendAndWait(5000L);
85 assertTrue(LoadPropertyFile.isValidJsonString(reply));
86 LOGGER.info("response =" + reply);
88 } catch (DME2Exception e) {
90 } catch (URISyntaxException e) {
92 } catch (Exception e) {
98 public boolean topicExist(String url, Properties props, HashMap<String, String> mapData) {
99 boolean topicExist = false;
101 LOGGER.info("Checking topic exists or not");
102 DME2Client sender = new DME2Client(new URI(url), 5000L);
103 sender.setAllowAllHttpReturnCodes(true);
104 sender.setMethod(props.getProperty("MethodTypeGet"));
105 String subcontextPath = props.getProperty("subContextPathGetOneTopic") + props.getProperty("newTopic");
106 sender.setSubContext(subcontextPath);
107 sender.setPayload("");
108 sender.addHeader("content-type", props.getProperty("contenttype"));
109 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
110 String reply = sender.sendAndWait(5000L);
111 topicExist = LoadPropertyFile.isValidJsonString(reply);
112 LOGGER.info("Topic exist =" + topicExist);
113 } catch (DME2Exception e) {
115 } catch (URISyntaxException e) {
117 } catch (Exception e) {
123 public void testAllTopics() {
124 LOGGER.info("Test case get all topics initiated");
125 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
126 latitude = props.getProperty("Latitude");
127 longitude = props.getProperty("Longitude");
128 version = props.getProperty("Version");
129 serviceName = props.getProperty("ServiceName");
130 env = props.getProperty("Environment");
131 partner = props.getProperty("Partner");
132 subContextPathGetAllTopic = props.getProperty("subContextPathGetAllTopic");
133 protocol = props.getProperty("Protocol");
134 methodTypeGet = props.getProperty("MethodTypeGet");
135 user = props.getProperty("user");
136 password = props.getProperty("password");
137 contenttype = props.getProperty("contenttype");
139 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
140 + "envContext=" + env + "/" + "partner=" + partner;
141 LoadPropertyFile.loadAFTProperties(latitude, longitude); // } else {
142 HashMap<String, String> hm = new HashMap<String, String>();
143 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
144 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
145 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
148 DME2Client sender = new DME2Client(new URI(url), 5000L);
149 sender.setAllowAllHttpReturnCodes(true);
150 sender.setMethod(methodTypeGet);
151 sender.setSubContext(subContextPathGetAllTopic);
152 sender.setPayload("");
154 sender.addHeader("Content-Type", contenttype);
155 sender.setCredentials(user, password);
156 sender.setHeaders(hm);
158 LOGGER.info("Retrieving all topics");
159 String reply = sender.sendAndWait(5000L);
160 assertTrue(LoadPropertyFile.isValidJsonString(reply));
161 LOGGER.info("All Topics details = " + reply);
163 } catch (DME2Exception e) {
165 } catch (URISyntaxException e) {
167 } catch (Exception e) {
172 public void testOneTopic() {
173 LOGGER.info("Test case get one topic initiated");
174 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
175 latitude = props.getProperty("Latitude");
176 longitude = props.getProperty("Longitude");
177 version = props.getProperty("Version");
178 serviceName = props.getProperty("ServiceName");
179 env = props.getProperty("Environment");
180 partner = props.getProperty("Partner");
181 subContextPathGetOneTopic = props.getProperty("subContextPathGetOneTopic");
182 protocol = props.getProperty("Protocol");
183 methodTypeGet = props.getProperty("MethodTypeGet");
184 user = props.getProperty("user");
185 password = props.getProperty("password");
186 contenttype = props.getProperty("contenttype");
188 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
189 + "envContext=" + env + "/" + "partner=" + partner;
190 LoadPropertyFile.loadAFTProperties(latitude, longitude);
192 HashMap<String, String> hm = new HashMap<String, String>();
193 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
194 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
195 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
196 System.out.println("Retrieving topic detail");
197 if (!topicExist(url, props, hm)) {
198 createTopic(url, props, hm);
204 public void createTopicForDeletion(String url, Properties props, HashMap<String, String> mapData) {
205 LOGGER.info("create topic method starts");
207 LOGGER.info("creating a new topic for deletion");
209 DME2Client sender = new DME2Client(new URI(url), 5000L);
210 sender.setAllowAllHttpReturnCodes(true);
211 sender.setMethod(props.getProperty("MethodTypePost"));
212 sender.setSubContext(props.getProperty("SubContextPathCreateTopic"));
213 TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("deleteTopic"),
214 props.getProperty("topicDescription"), Integer.parseInt(props.getProperty("partition")),
215 Integer.parseInt(props.getProperty("replication")), 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);
226 } catch (DME2Exception e) {
228 } catch (URISyntaxException e) {
230 } catch (Exception e) {
236 public boolean topicExistForDeletion(String url, Properties props, HashMap<String, String> mapData) {
237 boolean topicExist = false;
239 LOGGER.info("Checking topic exists for deletion");
240 DME2Client sender = new DME2Client(new URI(url), 5000L);
241 sender.setAllowAllHttpReturnCodes(true);
242 sender.setMethod(props.getProperty("MethodTypeGet"));
243 String subcontextPath = 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");
275 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
276 + "envContext=" + env + "/" + "partner=" + partner;
277 LoadPropertyFile.loadAFTProperties(latitude, longitude);
278 HashMap<String, String> hm = new HashMap<String, String>();
279 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
280 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
281 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
282 System.out.println("deleteing topic");
283 if (!topicExistForDeletion(url, props, hm)) {
284 createTopicForDeletion(url, props, hm);
285 deleteTopic(url, props, hm);
287 deleteTopic(url, props, hm);
291 public void deleteTopic(String url, Properties props, HashMap<String, String> mapData) {
293 DME2Client sender = new DME2Client(new URI(url), 5000L);
294 sender.setAllowAllHttpReturnCodes(true);
295 sender.setMethod(props.getProperty("MethodTypeDelete"));
296 String subsontextPathDelete = props.getProperty("subContextPathGetOneTopic")
297 + props.getProperty("deleteTopic");
298 sender.setSubContext(subsontextPathDelete);
299 sender.setPayload("");
300 sender.addHeader("content-type", props.getProperty("contenttype"));
301 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
302 System.out.println("Deleting Topic " + props.getProperty("deleteTopic"));
303 String reply = sender.sendAndWait(5000L);
304 assertNotNull(reply);
305 System.out.println("response =" + reply);
306 } catch (DME2Exception e) {
308 } catch (URISyntaxException e) {
310 } catch (Exception e) {
315 public void testGetProducersTopics() {
316 LOGGER.info("Test case get list of producers on topic");
317 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
318 latitude = props.getProperty("Latitude");
319 longitude = props.getProperty("Longitude");
320 version = props.getProperty("Version");
321 serviceName = props.getProperty("ServiceName");
322 env = props.getProperty("Environment");
323 partner = props.getProperty("Partner");
324 SubContextPathGetPublisher = props.getProperty("SubContextPathGetPublisher");
325 protocol = props.getProperty("Protocol");
326 methodTypeGet = props.getProperty("MethodTypeGet");
327 user = props.getProperty("user");
328 password = props.getProperty("password");
329 contenttype = props.getProperty("contenttype");
331 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
332 + "envContext=" + env + "/" + "partner=" + partner;
333 LoadPropertyFile.loadAFTProperties(latitude, longitude);
335 HashMap<String, String> hm = new HashMap<String, String>();
336 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
337 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
338 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
341 DME2Client sender = new DME2Client(new URI(url), 5000L);
342 sender.setAllowAllHttpReturnCodes(true);
343 sender.setMethod(methodTypeGet);
344 sender.setSubContext(SubContextPathGetPublisher);
345 sender.setPayload("");
347 sender.addHeader("Content-Type", contenttype);
348 sender.setCredentials(user, password);
349 sender.setHeaders(hm);
351 LOGGER.info("Retrieving List of publishers");
352 String reply = sender.sendAndWait(5000L);
353 assertTrue(LoadPropertyFile.isValidJsonString(reply));
354 LOGGER.info("All Publishers details = " + reply);
356 } catch (DME2Exception e) {
358 } catch (URISyntaxException e) {
360 } catch (Exception e) {
365 // permitting a producer on topic is not applicable
366 // public void testPermitProducersTopics() {
367 // LOGGER.info("Test case ");
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 // SubContextPathGetPermitPublisher =
376 // props.getProperty("SubContextPathGetPermitPublisher");
377 // protocol = props.getProperty("Protocol");
378 // methodTypePut = props.getProperty("MethodTypePut");
379 // user = props.getProperty("user");
380 // password = props.getProperty("password");
381 // contenttype = props.getProperty("contenttype");
383 // String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/"
384 // + "version=" + version + "/"
385 // + "envContext=" + env + "/" + "partner=" + partner;
386 // LoadPropertyFile.loadAFTProperties(latitude, longitude);
388 // HashMap<String, String> hm = new HashMap<String, String>();
389 // hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
390 // hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
391 // hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
394 // DME2Client sender = new DME2Client(new URI(url), 5000L);
395 // sender.setAllowAllHttpReturnCodes(true);
396 // sender.setMethod(methodTypePut);
397 // sender.setSubContext(SubContextPathGetPermitPublisher);
398 // sender.setPayload("");
400 // sender.addHeader("Content-Type", contenttype);
401 // sender.setCredentials(user, password);
402 // sender.setHeaders(hm);
404 // System.out.println("Permitting a producer on topic");
405 // String reply = sender.sendAndWait(5000L);
406 // System.out.println("Reply from server = " + reply);
408 // } catch (DME2Exception e) {
409 // e.printStackTrace();
410 // } catch (URISyntaxException e) {
411 // e.printStackTrace();
412 // } catch (Exception e) {
413 // e.printStackTrace();
417 public void testGetConsumersTopics() {
418 LOGGER.info("Test case get list of consumers on topic ");
419 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
420 latitude = props.getProperty("Latitude");
421 longitude = props.getProperty("Longitude");
422 version = props.getProperty("Version");
423 serviceName = props.getProperty("ServiceName");
424 env = props.getProperty("Environment");
425 partner = props.getProperty("Partner");
426 SubContextPathGetConsumer = props.getProperty("SubContextPathGetConsumer");
427 protocol = props.getProperty("Protocol");
428 methodTypeGet = props.getProperty("MethodTypeGet");
429 user = props.getProperty("user");
430 password = props.getProperty("password");
431 contenttype = props.getProperty("contenttype");
433 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
434 + "envContext=" + env + "/" + "partner=" + partner;
435 LoadPropertyFile.loadAFTProperties(latitude, longitude);
437 HashMap<String, String> hm = new HashMap<String, String>();
438 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
439 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
440 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
443 DME2Client sender = new DME2Client(new URI(url), 5000L);
444 sender.setAllowAllHttpReturnCodes(true);
445 sender.setMethod(methodTypeGet);
446 sender.setSubContext(SubContextPathGetConsumer);
447 sender.setPayload("");
449 sender.addHeader("Content-Type", contenttype);
450 sender.setCredentials(user, password);
451 sender.setHeaders(hm);
453 LOGGER.info("Retrieving consumer details on topics");
454 String reply = sender.sendAndWait(5000L);
455 assertTrue(LoadPropertyFile.isValidJsonString(reply));
456 System.out.println("Reply from server = " + reply);
458 } catch (DME2Exception e) {
460 } catch (URISyntaxException e) {
462 } catch (Exception e) {
467 public void testCreateTopic() {
468 LOGGER.info("Test case create topic starts");
469 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
470 latitude = props.getProperty("Latitude");
471 longitude = props.getProperty("Longitude");
472 version = props.getProperty("Version");
473 serviceName = props.getProperty("ServiceName");
474 env = props.getProperty("Environment");
475 partner = props.getProperty("Partner");
476 SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic");
477 protocol = props.getProperty("Protocol");
478 methodTypePost = props.getProperty("MethodTypePost");
479 user = props.getProperty("user");
480 password = props.getProperty("password");
481 contenttype = props.getProperty("contenttypejson");
483 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
484 + "envContext=" + env + "/" + "partner=" + partner;
485 LoadPropertyFile.loadAFTProperties(latitude, longitude);
486 HashMap<String, String> hm = new HashMap<String, String>();
487 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
488 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
489 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
491 createTopic(url, props, hm);
493 // permitting a consumer on topic is not applicable
494 // public void testPermitConsumerTopics() {
495 // Properties props = LoadPropertyFile.getPropertyFileDataProducer();
496 // latitude = props.getProperty("Latitude");
497 // longitude = props.getProperty("Longitude");
498 // version = props.getProperty("Version");
499 // serviceName = props.getProperty("ServiceName");
500 // env = props.getProperty("Environment");
501 // partner = props.getProperty("Partner");
502 // SubContextPathGetPermitConsumer =
503 // props.getProperty("SubContextPathGetPermitConsumer");
504 // protocol = props.getProperty("Protocol");
505 // methodTypePut = props.getProperty("MethodTypePut");
506 // user = props.getProperty("user");
507 // password = props.getProperty("password");
508 // contenttype = props.getProperty("contenttype");
510 // String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/"
511 // + "version=" + version + "/"
512 // + "envContext=" + env + "/" + "partner=" + partner;
513 // LoadPropertyFile.loadAFTProperties(latitude, longitude);
515 // HashMap<String, String> hm = new HashMap<String, String>();
516 // hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
517 // hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
518 // hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
521 // DME2Client sender = new DME2Client(new URI(url), 5000L);
522 // sender.setAllowAllHttpReturnCodes(true);
523 // sender.setMethod(methodTypePut);
524 // sender.setSubContext(SubContextPathGetPermitConsumer);
525 // sender.setPayload("");
527 // sender.addHeader("Content-Type", contenttype);
528 // sender.setCredentials(user, password);
529 // sender.setHeaders(hm);
531 // System.out.println("Permitting a consumer on topic");
532 // String reply = sender.sendAndWait(5000L);
533 // assertNotNull(reply);
534 // System.out.println("Reply from server = " + reply);
536 // } catch (DME2Exception e) {
537 // e.printStackTrace();
538 // } catch (URISyntaxException e) {
539 // e.printStackTrace();
540 // } catch (Exception e) {
541 // e.printStackTrace();