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 junit.framework.TestCase;
27 import org.apache.logging.log4j.LogManager;
28 import org.apache.logging.log4j.Logger;
31 import java.net.URISyntaxException;
32 import java.util.HashMap;
33 import java.util.Properties;
35 public class DME2MetricsTest extends TestCase {
37 private static final Logger LOGGER = LogManager.getLogger(DME2MetricsTest.class);
39 public void testGetMetrics() {
40 LOGGER.info("Test case get metrics initiated...");
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 subContextPath = props.getProperty("SubContextPathGetMetrics");
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");
55 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
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");
64 DME2Client sender = new DME2Client(new URI(url), 5000L);
65 sender.setAllowAllHttpReturnCodes(true);
66 sender.setMethod(methodType);
67 sender.setSubContext(subContextPath);
68 sender.setPayload("");
69 sender.addHeader("Content-Type", contenttype);
70 sender.setCredentials(user, password);
71 sender.setHeaders(hm);
72 LOGGER.info("Getting Metrics Details");
73 String reply = sender.sendAndWait(5000L);
74 assertTrue(LoadPropertyFile.isValidJsonString(reply));
75 LOGGER.info("response =" + reply);
76 } catch (DME2Exception e) {
78 } catch (URISyntaxException e) {
80 } catch (Exception e) {
85 public void testGetMetricsByName() {
86 LOGGER.info("Test case get metrics by name initiated");
87 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
88 String latitude = props.getProperty("Latitude");
89 String longitude = props.getProperty("Longitude");
90 String version = props.getProperty("Version");
91 String serviceName = props.getProperty("ServiceName");
92 String env = props.getProperty("Environment");
93 String partner = props.getProperty("Partner");
94 String subContextPath = props.getProperty("SubContextPathGetMetricsByName");
95 String protocol = props.getProperty("Protocol");
96 String methodType = props.getProperty("MethodTypeGet");
97 String user = props.getProperty("user");
98 String password = props.getProperty("password");
99 String contenttype = props.getProperty("contenttype");
101 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
103 + "envContext=" + env + "/" + "partner=" + partner;
104 LoadPropertyFile.loadAFTProperties(latitude, longitude);
105 HashMap<String, String> hm = new HashMap<String, String>();
106 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
107 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
108 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
110 DME2Client sender = new DME2Client(new URI(url), 5000L);
111 sender.setAllowAllHttpReturnCodes(true);
112 sender.setMethod(methodType);
113 sender.setSubContext(subContextPath);
114 sender.setPayload("");
115 sender.addHeader("Content-Type", contenttype);
116 sender.setCredentials(user, password);
117 sender.setHeaders(hm);
118 LOGGER.info("Getting Metrics By name");
119 String reply = sender.sendAndWait(5000L);
120 assertTrue(LoadPropertyFile.isValidJsonString(reply));
121 LOGGER.info("response =" + reply);
122 } catch (DME2Exception e) {
124 } catch (URISyntaxException e) {
126 } catch (Exception e) {