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;
27 import junit.framework.TestCase;
28 import org.apache.logging.log4j.LogManager;
29 import org.apache.logging.log4j.Logger;
32 import java.net.URISyntaxException;
33 import java.util.HashMap;
34 import java.util.Properties;
36 public class DME2ProducerTest extends TestCase {
38 private static final Logger LOGGER = LogManager.getLogger(DME2ProducerTest.class);
40 public void testProducer() {
41 DME2TopicTest topicTestObj = new DME2TopicTest();
42 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
43 String latitude = props.getProperty("Latitude");
44 String longitude = props.getProperty("Longitude");
45 String version = props.getProperty("Version");
46 String serviceName = props.getProperty("ServiceName");
47 String env = props.getProperty("Environment");
48 String partner = props.getProperty("Partner");
49 String protocol = props.getProperty("Protocol");
51 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
53 + "envContext=" + env + "/" + "partner=" + partner;
54 LoadPropertyFile.loadAFTProperties(latitude, longitude);
55 HashMap<String, String> hm = new HashMap<String, String>();
56 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
57 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
58 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
59 // checking whether topic exist or not
60 if (!topicTestObj.topicExist(url, props, hm)) {
61 // if topic doesn't exist then create the topic
62 topicTestObj.createTopic(url, props, hm);
63 // after creating the topic publish on that topic
64 publishMessage(url, props, hm);
66 // if topic already exist start publishing on the topic
67 publishMessage(url, props, hm);
72 public void publishMessage(String url, Properties props, HashMap<String, String> mapData) {
74 LOGGER.info("Call to publish message ");
75 DME2Client sender = new DME2Client(new URI(url), 5000L);
76 sender.setAllowAllHttpReturnCodes(true);
77 sender.setMethod(props.getProperty("MethodTypePost"));
78 String subcontextpathPublish =
79 props.getProperty("SubContextPathproducer") + props.getProperty("newTopic");
80 sender.setSubContext(subcontextpathPublish);
81 String jsonStringApiBean = new ObjectMapper()
82 .writeValueAsString(new ApiKeyBean("example@att.com",
84 sender.setPayload(jsonStringApiBean);
86 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
87 sender.addHeader("content-type", props.getProperty("contenttype"));
88 LOGGER.info("Publishing message");
89 String reply = sender.sendAndWait(5000L);
90 // assertTrue(LoadPropertyFile.isValidJsonString(reply));
92 LOGGER.info("response =" + reply);
93 } catch (DME2Exception e) {
95 } catch (URISyntaxException e) {
97 } catch (Exception e) {