DMAAP-MR - Merge MR repos
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / mr / test / dme2 / DME2ConsumerFilterTest.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 junit.framework.TestCase;
27 import org.apache.logging.log4j.LogManager;
28 import org.apache.logging.log4j.Logger;
29
30 import java.net.URI;
31 import java.net.URISyntaxException;
32 import java.net.URLEncoder;
33 import java.util.HashMap;
34 import java.util.Properties;
35
36 public class DME2ConsumerFilterTest extends TestCase {
37
38     private static final Logger LOGGER = LogManager.getLogger(DME2ConsumerFilterTest.class);
39
40     public void testConsumerFilter() {
41         LOGGER.info("Test case consumer filter initiated");
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");
50         String methodType = props.getProperty("MethodTypeGet");
51         String user = props.getProperty("user");
52         String password = props.getProperty("password");
53         String contenttype = props.getProperty("contenttype");
54         String url =
55             protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
56                 + "/"
57                 + "envContext=" + env + "/" + "partner=" + partner;
58         LoadPropertyFile.loadAFTProperties(latitude, longitude);
59         HashMap<String, String> hm = new HashMap<String, String>();
60         hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
61         hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
62         hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
63
64         try {
65             DME2Client sender = new DME2Client(new URI(url), 5000L);
66             sender.setAllowAllHttpReturnCodes(true);
67             sender.setMethod(methodType);
68             String subContextPathConsumer =
69                 props.getProperty("SubContextPathConsumer") + props.getProperty("newTopic")
70                     + "/" + props.getProperty("group") + "/" + props.getProperty("id") + "?"
71                     + props.getProperty("filterType");
72
73             sender.setSubContext(URLEncoder.encode(subContextPathConsumer, "UTF-8"));
74             sender.setPayload("");
75
76             sender.addHeader("Content-Type", contenttype);
77             sender.setCredentials(user, password);
78             sender.setHeaders(hm);
79             LOGGER.info("Consuming Message for Filter");
80             String reply = sender.sendAndWait(5000L);
81             assertNotNull(reply);
82             LOGGER.info("Message received = " + reply);
83         } catch (DME2Exception e) {
84             e.printStackTrace();
85         } catch (URISyntaxException e) {
86             e.printStackTrace();
87         } catch (Exception e) {
88             e.printStackTrace();
89         }
90     }
91 }