[DMaap-msgrtr] Update Security Vulnerabilities
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / test / dme2 / DME2ConsumerTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
11  *
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=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *
21  *******************************************************************************/
22 package org.onap.dmaap.mr.test.dme2;
23
24 import com.att.aft.dme2.api.DME2Client;
25 import com.att.aft.dme2.api.DME2Exception;
26 import java.net.URI;
27 import java.net.URISyntaxException;
28 import java.util.HashMap;
29 import java.util.Properties;
30 import junit.framework.TestCase;
31 import org.apache.logging.log4j.LogManager;
32 import org.apache.logging.log4j.Logger;
33
34 public class DME2ConsumerTest extends TestCase {
35
36     private static final Logger LOGGER = LogManager.getLogger(DME2ConsumerTest.class);
37
38     public void testConsumer() {
39         LOGGER.info("Test case subcribing initiated");
40
41         Properties props = LoadPropertyFile.getPropertyFileDataProducer();
42         String latitude = props.getProperty("Latitude");
43         String longitude = props.getProperty("Longitude");
44         String version = props.getProperty("Version");
45         String serviceName = props.getProperty("ServiceName");
46         String env = props.getProperty("Environment");
47         String partner = props.getProperty("Partner");
48         String protocol = props.getProperty("Protocol");
49         String methodType = props.getProperty("MethodTypeGet");
50         String user = props.getProperty("user");
51         String password = props.getProperty("password");
52         String contenttype = props.getProperty("contenttype");
53         String url =
54             protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
55                 + "/"
56                 + "envContext=" + env + "/" + "partner=" + partner;
57         LoadPropertyFile.loadAFTProperties(latitude, longitude);
58         HashMap<String, String> hm = new HashMap<String, String>();
59         hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
60         hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
61         hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
62         try {
63             DME2Client sender = new DME2Client(new URI(url), 5000L);
64             sender.setAllowAllHttpReturnCodes(true);
65             sender.setMethod(methodType);
66             String subContextPathConsumer =
67                 props.getProperty("SubContextPathConsumer") + props.getProperty("newTopic")
68                     + "/" + props.getProperty("group") + "/" + props.getProperty("id");
69             sender.setSubContext(subContextPathConsumer);
70             sender.setPayload("");
71
72             sender.addHeader("Content-Type", contenttype);
73             sender.setCredentials(user, password);
74             sender.setHeaders(hm);
75
76             LOGGER.info("Consuming Message");
77             String reply = sender.sendAndWait(5000L);
78
79             assertNotNull(reply);
80             LOGGER.info("Message received = " + reply);
81         } catch (DME2Exception e) {
82             e.printStackTrace();
83         } catch (URISyntaxException e) {
84             e.printStackTrace();
85         } catch (Exception e) {
86             e.printStackTrace();
87         }
88     }
89 }