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 com.att.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;
38 import com.att.mr.test.dmaap.DmaapAdminTest;
40 public class DME2TopicTest extends TestCase {
41 private String latitude;
42 private String longitude;
43 private String version;
44 private String serviceName;
46 private String partner;
47 private String protocol;
48 private String methodTypeGet;
49 private String methodTypePost;
50 private String methodTypeDelete;
51 private String methodTypePut;
54 private String password;
55 private String contenttype;
56 private String subContextPathGetAllTopic;
57 private String subContextPathGetOneTopic;
58 private String SubContextPathCreateTopic;
59 private String SubContextPathGetPublisherl;
60 private String SubContextPathGetPublisher;
61 private String SubContextPathGetPermitPublisher;
62 private String SubContextPathGetConsumer;
63 private String SubContextPathGetPermitConsumer;
64 private static final Logger LOGGER = Logger.getLogger(DME2TopicTest.class);
66 public void createTopic(String url, Properties props, HashMap<String, String> mapData) {
67 LOGGER.info("create topic method starts");
68 if (!topicExist(url, props, mapData)) {
69 LOGGER.info("creating a new topic");
71 DME2Client sender = new DME2Client(new URI(url), 5000L);
72 sender.setAllowAllHttpReturnCodes(true);
73 sender.setMethod(props.getProperty("MethodTypePost"));
74 sender.setSubContext(props.getProperty("SubContextPathCreateTopic"));
75 TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("newTopic"),
76 props.getProperty("topicDescription"), Integer.parseInt(props.getProperty("partition")),
77 Integer.parseInt(props.getProperty("replication")), Boolean.valueOf(props
78 .getProperty("txenabled")));
79 String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean);
80 sender.setPayload(jsonStringApiBean);
81 sender.addHeader("content-type", props.getProperty("contenttype"));
82 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
84 LOGGER.info("creating Topic");
85 String reply = sender.sendAndWait(5000L);
86 assertTrue(LoadPropertyFile.isValidJsonString(reply));
87 LOGGER.info("response =" + reply);
89 } catch (DME2Exception e) {
91 } catch (URISyntaxException e) {
93 } catch (Exception e) {
99 public boolean topicExist(String url, Properties props, HashMap<String, String> mapData) {
100 boolean topicExist = false;
102 LOGGER.info("Checking topic exists or not");
103 DME2Client sender = new DME2Client(new URI(url), 5000L);
104 sender.setAllowAllHttpReturnCodes(true);
105 sender.setMethod(props.getProperty("MethodTypeGet"));
106 String subcontextPath = props.getProperty("subContextPathGetOneTopic") + props.getProperty("newTopic");
107 sender.setSubContext(subcontextPath);
108 sender.setPayload("");
109 sender.addHeader("content-type", props.getProperty("contenttype"));
110 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
111 String reply = sender.sendAndWait(5000L);
112 topicExist = LoadPropertyFile.isValidJsonString(reply);
113 LOGGER.info("Topic exist =" + topicExist);
114 } catch (DME2Exception e) {
116 } catch (URISyntaxException e) {
118 } catch (Exception e) {
124 public void testAllTopics() {
125 LOGGER.info("Test case get all topics initiated");
126 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
127 latitude = props.getProperty("Latitude");
128 longitude = props.getProperty("Longitude");
129 version = props.getProperty("Version");
130 serviceName = props.getProperty("ServiceName");
131 env = props.getProperty("Environment");
132 partner = props.getProperty("Partner");
133 subContextPathGetAllTopic = props.getProperty("subContextPathGetAllTopic");
134 protocol = props.getProperty("Protocol");
135 methodTypeGet = props.getProperty("MethodTypeGet");
136 user = props.getProperty("user");
137 password = props.getProperty("password");
138 contenttype = props.getProperty("contenttype");
140 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
141 + "envContext=" + env + "/" + "partner=" + partner;
142 LoadPropertyFile.loadAFTProperties(latitude, longitude); // } else {
143 HashMap<String, String> hm = new HashMap<String, String>();
144 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
145 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
146 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
149 DME2Client sender = new DME2Client(new URI(url), 5000L);
150 sender.setAllowAllHttpReturnCodes(true);
151 sender.setMethod(methodTypeGet);
152 sender.setSubContext(subContextPathGetAllTopic);
153 sender.setPayload("");
155 sender.addHeader("Content-Type", contenttype);
156 sender.setCredentials(user, password);
157 sender.setHeaders(hm);
159 LOGGER.info("Retrieving all topics");
160 String reply = sender.sendAndWait(5000L);
161 assertTrue(LoadPropertyFile.isValidJsonString(reply));
162 LOGGER.info("All Topics details = " + reply);
164 } catch (DME2Exception e) {
166 } catch (URISyntaxException e) {
168 } catch (Exception e) {
173 public void testOneTopic() {
174 LOGGER.info("Test case get one topic initiated");
175 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
176 latitude = props.getProperty("Latitude");
177 longitude = props.getProperty("Longitude");
178 version = props.getProperty("Version");
179 serviceName = props.getProperty("ServiceName");
180 env = props.getProperty("Environment");
181 partner = props.getProperty("Partner");
182 subContextPathGetOneTopic = props.getProperty("subContextPathGetOneTopic");
183 protocol = props.getProperty("Protocol");
184 methodTypeGet = props.getProperty("MethodTypeGet");
185 user = props.getProperty("user");
186 password = props.getProperty("password");
187 contenttype = props.getProperty("contenttype");
189 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
190 + "envContext=" + env + "/" + "partner=" + partner;
191 LoadPropertyFile.loadAFTProperties(latitude, longitude);
193 HashMap<String, String> hm = new HashMap<String, String>();
194 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
195 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
196 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
197 System.out.println("Retrieving topic detail");
198 if (!topicExist(url, props, hm)) {
199 createTopic(url, props, hm);
205 public void createTopicForDeletion(String url, Properties props, HashMap<String, String> mapData) {
206 LOGGER.info("create topic method starts");
208 LOGGER.info("creating a new topic for deletion");
210 DME2Client sender = new DME2Client(new URI(url), 5000L);
211 sender.setAllowAllHttpReturnCodes(true);
212 sender.setMethod(props.getProperty("MethodTypePost"));
213 sender.setSubContext(props.getProperty("SubContextPathCreateTopic"));
214 TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("deleteTopic"),
215 props.getProperty("topicDescription"), Integer.parseInt(props.getProperty("partition")),
216 Integer.parseInt(props.getProperty("replication")), Boolean.valueOf(props.getProperty("txenabled")));
217 String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean);
218 sender.setPayload(jsonStringApiBean);
219 sender.addHeader("content-type", props.getProperty("contenttype"));
220 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
222 LOGGER.info("creating Topic");
223 String reply = sender.sendAndWait(5000L);
224 assertTrue(LoadPropertyFile.isValidJsonString(reply));
225 LOGGER.info("response =" + reply);
227 } catch (DME2Exception e) {
229 } catch (URISyntaxException e) {
231 } catch (Exception e) {
237 public boolean topicExistForDeletion(String url, Properties props, HashMap<String, String> mapData) {
238 boolean topicExist = false;
240 LOGGER.info("Checking topic exists for deletion");
241 DME2Client sender = new DME2Client(new URI(url), 5000L);
242 sender.setAllowAllHttpReturnCodes(true);
243 sender.setMethod(props.getProperty("MethodTypeGet"));
244 String subcontextPath = props.getProperty("subContextPathGetOneTopic") + props.getProperty("deleteTopic");
245 sender.setSubContext(subcontextPath);
246 sender.setPayload("");
247 sender.addHeader("content-type", props.getProperty("contenttype"));
248 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
249 String reply = sender.sendAndWait(5000L);
250 topicExist = LoadPropertyFile.isValidJsonString(reply);
251 LOGGER.info("Topic exist for deletion=" + topicExist);
252 } catch (DME2Exception e) {
254 } catch (URISyntaxException e) {
256 } catch (Exception e) {
262 public void testDeleteTopic() {
263 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
264 latitude = props.getProperty("Latitude");
265 longitude = props.getProperty("Longitude");
266 version = props.getProperty("Version");
267 serviceName = props.getProperty("ServiceName");
268 env = props.getProperty("Environment");
269 partner = props.getProperty("Partner");
270 SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic");
271 protocol = props.getProperty("Protocol");
272 methodTypePost = props.getProperty("MethodTypeDelete");
273 user = props.getProperty("user");
274 password = props.getProperty("password");
275 contenttype = props.getProperty("contenttypejson");
276 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
277 + "envContext=" + env + "/" + "partner=" + partner;
278 LoadPropertyFile.loadAFTProperties(latitude, longitude);
279 HashMap<String, String> hm = new HashMap<String, String>();
280 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
281 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
282 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
283 System.out.println("deleteing topic");
284 if (!topicExistForDeletion(url, props, hm)) {
285 createTopicForDeletion(url, props, hm);
286 deleteTopic(url, props, hm);
288 deleteTopic(url, props, hm);
292 public void deleteTopic(String url, Properties props, HashMap<String, String> mapData) {
294 DME2Client sender = new DME2Client(new URI(url), 5000L);
295 sender.setAllowAllHttpReturnCodes(true);
296 sender.setMethod(props.getProperty("MethodTypeDelete"));
297 String subsontextPathDelete = props.getProperty("subContextPathGetOneTopic")
298 + props.getProperty("deleteTopic");
299 sender.setSubContext(subsontextPathDelete);
300 sender.setPayload("");
301 sender.addHeader("content-type", props.getProperty("contenttype"));
302 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
303 System.out.println("Deleting Topic " + props.getProperty("deleteTopic"));
304 String reply = sender.sendAndWait(5000L);
305 assertNotNull(reply);
306 System.out.println("response =" + reply);
307 } catch (DME2Exception e) {
309 } catch (URISyntaxException e) {
311 } catch (Exception e) {
316 public void testGetProducersTopics() {
317 LOGGER.info("Test case get list of producers on topic");
318 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
319 latitude = props.getProperty("Latitude");
320 longitude = props.getProperty("Longitude");
321 version = props.getProperty("Version");
322 serviceName = props.getProperty("ServiceName");
323 env = props.getProperty("Environment");
324 partner = props.getProperty("Partner");
325 SubContextPathGetPublisher = props.getProperty("SubContextPathGetPublisher");
326 protocol = props.getProperty("Protocol");
327 methodTypeGet = props.getProperty("MethodTypeGet");
328 user = props.getProperty("user");
329 password = props.getProperty("password");
330 contenttype = props.getProperty("contenttype");
332 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
333 + "envContext=" + env + "/" + "partner=" + partner;
334 LoadPropertyFile.loadAFTProperties(latitude, longitude);
336 HashMap<String, String> hm = new HashMap<String, String>();
337 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
338 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
339 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
342 DME2Client sender = new DME2Client(new URI(url), 5000L);
343 sender.setAllowAllHttpReturnCodes(true);
344 sender.setMethod(methodTypeGet);
345 sender.setSubContext(SubContextPathGetPublisher);
346 sender.setPayload("");
348 sender.addHeader("Content-Type", contenttype);
349 sender.setCredentials(user, password);
350 sender.setHeaders(hm);
352 LOGGER.info("Retrieving List of publishers");
353 String reply = sender.sendAndWait(5000L);
354 assertTrue(LoadPropertyFile.isValidJsonString(reply));
355 LOGGER.info("All Publishers details = " + reply);
357 } catch (DME2Exception e) {
359 } catch (URISyntaxException e) {
361 } catch (Exception e) {
366 // permitting a producer on topic is not applicable
367 // public void testPermitProducersTopics() {
368 // LOGGER.info("Test case ");
369 // Properties props = LoadPropertyFile.getPropertyFileDataProducer();
370 // latitude = props.getProperty("Latitude");
371 // longitude = props.getProperty("Longitude");
372 // version = props.getProperty("Version");
373 // serviceName = props.getProperty("ServiceName");
374 // env = props.getProperty("Environment");
375 // partner = props.getProperty("Partner");
376 // SubContextPathGetPermitPublisher =
377 // props.getProperty("SubContextPathGetPermitPublisher");
378 // protocol = props.getProperty("Protocol");
379 // methodTypePut = props.getProperty("MethodTypePut");
380 // user = props.getProperty("user");
381 // password = props.getProperty("password");
382 // contenttype = props.getProperty("contenttype");
384 // String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/"
385 // + "version=" + version + "/"
386 // + "envContext=" + env + "/" + "partner=" + partner;
387 // LoadPropertyFile.loadAFTProperties(latitude, longitude);
389 // HashMap<String, String> hm = new HashMap<String, String>();
390 // hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
391 // hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
392 // hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
395 // DME2Client sender = new DME2Client(new URI(url), 5000L);
396 // sender.setAllowAllHttpReturnCodes(true);
397 // sender.setMethod(methodTypePut);
398 // sender.setSubContext(SubContextPathGetPermitPublisher);
399 // sender.setPayload("");
401 // sender.addHeader("Content-Type", contenttype);
402 // sender.setCredentials(user, password);
403 // sender.setHeaders(hm);
405 // System.out.println("Permitting a producer on topic");
406 // String reply = sender.sendAndWait(5000L);
407 // System.out.println("Reply from server = " + reply);
409 // } catch (DME2Exception e) {
410 // e.printStackTrace();
411 // } catch (URISyntaxException e) {
412 // e.printStackTrace();
413 // } catch (Exception e) {
414 // e.printStackTrace();
418 public void testGetConsumersTopics() {
419 LOGGER.info("Test case get list of consumers on topic ");
420 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
421 latitude = props.getProperty("Latitude");
422 longitude = props.getProperty("Longitude");
423 version = props.getProperty("Version");
424 serviceName = props.getProperty("ServiceName");
425 env = props.getProperty("Environment");
426 partner = props.getProperty("Partner");
427 SubContextPathGetConsumer = props.getProperty("SubContextPathGetConsumer");
428 protocol = props.getProperty("Protocol");
429 methodTypeGet = props.getProperty("MethodTypeGet");
430 user = props.getProperty("user");
431 password = props.getProperty("password");
432 contenttype = props.getProperty("contenttype");
434 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
435 + "envContext=" + env + "/" + "partner=" + partner;
436 LoadPropertyFile.loadAFTProperties(latitude, longitude);
438 HashMap<String, String> hm = new HashMap<String, String>();
439 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
440 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
441 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
444 DME2Client sender = new DME2Client(new URI(url), 5000L);
445 sender.setAllowAllHttpReturnCodes(true);
446 sender.setMethod(methodTypeGet);
447 sender.setSubContext(SubContextPathGetConsumer);
448 sender.setPayload("");
450 sender.addHeader("Content-Type", contenttype);
451 sender.setCredentials(user, password);
452 sender.setHeaders(hm);
454 LOGGER.info("Retrieving consumer details on topics");
455 String reply = sender.sendAndWait(5000L);
456 assertTrue(LoadPropertyFile.isValidJsonString(reply));
457 System.out.println("Reply from server = " + reply);
459 } catch (DME2Exception e) {
461 } catch (URISyntaxException e) {
463 } catch (Exception e) {
468 public void testCreateTopic() {
469 LOGGER.info("Test case create topic starts");
470 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
471 latitude = props.getProperty("Latitude");
472 longitude = props.getProperty("Longitude");
473 version = props.getProperty("Version");
474 serviceName = props.getProperty("ServiceName");
475 env = props.getProperty("Environment");
476 partner = props.getProperty("Partner");
477 SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic");
478 protocol = props.getProperty("Protocol");
479 methodTypePost = props.getProperty("MethodTypePost");
480 user = props.getProperty("user");
481 password = props.getProperty("password");
482 contenttype = props.getProperty("contenttypejson");
484 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
485 + "envContext=" + env + "/" + "partner=" + partner;
486 LoadPropertyFile.loadAFTProperties(latitude, longitude);
487 HashMap<String, String> hm = new HashMap<String, String>();
488 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
489 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
490 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
492 createTopic(url, props, hm);
494 // permitting a consumer on topic is not applicable
495 // public void testPermitConsumerTopics() {
496 // Properties props = LoadPropertyFile.getPropertyFileDataProducer();
497 // latitude = props.getProperty("Latitude");
498 // longitude = props.getProperty("Longitude");
499 // version = props.getProperty("Version");
500 // serviceName = props.getProperty("ServiceName");
501 // env = props.getProperty("Environment");
502 // partner = props.getProperty("Partner");
503 // SubContextPathGetPermitConsumer =
504 // props.getProperty("SubContextPathGetPermitConsumer");
505 // protocol = props.getProperty("Protocol");
506 // methodTypePut = props.getProperty("MethodTypePut");
507 // user = props.getProperty("user");
508 // password = props.getProperty("password");
509 // contenttype = props.getProperty("contenttype");
511 // String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/"
512 // + "version=" + version + "/"
513 // + "envContext=" + env + "/" + "partner=" + partner;
514 // LoadPropertyFile.loadAFTProperties(latitude, longitude);
516 // HashMap<String, String> hm = new HashMap<String, String>();
517 // hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
518 // hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
519 // hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
522 // DME2Client sender = new DME2Client(new URI(url), 5000L);
523 // sender.setAllowAllHttpReturnCodes(true);
524 // sender.setMethod(methodTypePut);
525 // sender.setSubContext(SubContextPathGetPermitConsumer);
526 // sender.setPayload("");
528 // sender.addHeader("Content-Type", contenttype);
529 // sender.setCredentials(user, password);
530 // sender.setHeaders(hm);
532 // System.out.println("Permitting a consumer on topic");
533 // String reply = sender.sendAndWait(5000L);
534 // assertNotNull(reply);
535 // System.out.println("Reply from server = " + reply);
537 // } catch (DME2Exception e) {
538 // e.printStackTrace();
539 // } catch (URISyntaxException e) {
540 // e.printStackTrace();
541 // } catch (Exception e) {
542 // e.printStackTrace();