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;
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;
34 public class DME2MetricsTest extends TestCase {
36 private static final Logger LOGGER = LogManager.getLogger(DME2MetricsTest.class);
38 public void testGetMetrics() {
39 LOGGER.info("Test case get metrics initiated...");
40 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
41 String latitude = props.getProperty("Latitude");
42 String longitude = props.getProperty("Longitude");
43 String version = props.getProperty("Version");
44 String serviceName = props.getProperty("ServiceName");
45 String env = props.getProperty("Environment");
46 String partner = props.getProperty("Partner");
47 String subContextPath = props.getProperty("SubContextPathGetMetrics");
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");
54 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
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");
63 DME2Client sender = new DME2Client(new URI(url), 5000L);
64 sender.setAllowAllHttpReturnCodes(true);
65 sender.setMethod(methodType);
66 sender.setSubContext(subContextPath);
67 sender.setPayload("");
68 sender.addHeader("Content-Type", contenttype);
69 sender.setCredentials(user, password);
70 sender.setHeaders(hm);
71 LOGGER.info("Getting Metrics Details");
72 String reply = sender.sendAndWait(5000L);
73 assertTrue(LoadPropertyFile.isValidJsonString(reply));
74 LOGGER.info("response =" + reply);
75 } catch (DME2Exception e) {
77 } catch (URISyntaxException e) {
79 } catch (Exception e) {
84 public void testGetMetricsByName() {
85 LOGGER.info("Test case get metrics by name initiated");
86 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
87 String latitude = props.getProperty("Latitude");
88 String longitude = props.getProperty("Longitude");
89 String version = props.getProperty("Version");
90 String serviceName = props.getProperty("ServiceName");
91 String env = props.getProperty("Environment");
92 String partner = props.getProperty("Partner");
93 String subContextPath = props.getProperty("SubContextPathGetMetricsByName");
94 String protocol = props.getProperty("Protocol");
95 String methodType = props.getProperty("MethodTypeGet");
96 String user = props.getProperty("user");
97 String password = props.getProperty("password");
98 String contenttype = props.getProperty("contenttype");
100 protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version
102 + "envContext=" + env + "/" + "partner=" + partner;
103 LoadPropertyFile.loadAFTProperties(latitude, longitude);
104 HashMap<String, String> hm = new HashMap<String, String>();
105 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
106 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
107 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
109 DME2Client sender = new DME2Client(new URI(url), 5000L);
110 sender.setAllowAllHttpReturnCodes(true);
111 sender.setMethod(methodType);
112 sender.setSubContext(subContextPath);
113 sender.setPayload("");
114 sender.addHeader("Content-Type", contenttype);
115 sender.setCredentials(user, password);
116 sender.setHeaders(hm);
117 LOGGER.info("Getting Metrics By name");
118 String reply = sender.sendAndWait(5000L);
119 assertTrue(LoadPropertyFile.isValidJsonString(reply));
120 LOGGER.info("response =" + reply);
121 } catch (DME2Exception e) {
123 } catch (URISyntaxException e) {
125 } catch (Exception e) {