bump the version
[dmaap/messagerouter/msgrtr.git] / src / test / java / com / att / mr / test / dme2 / DME2MetricsTest.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 com.att.mr.test.dme2;
23
24 import java.net.URI;
25 import java.net.URISyntaxException;
26 import java.util.HashMap;
27 import java.util.Properties;
28
29 import org.apache.log4j.Logger;
30
31 import junit.framework.TestCase;
32
33 import com.att.aft.dme2.api.DME2Client;
34 import com.att.aft.dme2.api.DME2Exception;
35 import com.att.mr.test.dmaap.DmaapAdminTest;
36
37 public class DME2MetricsTest extends TestCase {
38         private static final Logger LOGGER = Logger.getLogger(DME2MetricsTest.class);
39
40         public void testGetMetrics() {
41                 LOGGER.info("Test case get metrics initiated...");
42                 
43                 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
44                 String latitude = props.getProperty("Latitude");
45                 String longitude = props.getProperty("Longitude");
46                 String version = props.getProperty("Version");
47                 String serviceName = props.getProperty("ServiceName");
48                 String env = props.getProperty("Environment");
49                 String partner = props.getProperty("Partner");
50                 String subContextPath = props.getProperty("SubContextPathGetMetrics");
51                 String protocol = props.getProperty("Protocol");
52                 String methodType = props.getProperty("MethodTypeGet");
53                 String user = props.getProperty("user");
54                 String password = props.getProperty("password");
55                 String contenttype = props.getProperty("contenttype");
56                 String url = 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");
63
64                 try {
65                         DME2Client sender = new DME2Client(new URI(url), 5000L);
66                         sender.setAllowAllHttpReturnCodes(true);
67                         sender.setMethod(methodType);
68                         sender.setSubContext(subContextPath);
69                         sender.setPayload("");
70                         sender.addHeader("Content-Type", contenttype);
71                         sender.setCredentials(user, password);
72                         sender.setHeaders(hm);
73
74                         LOGGER.info("Getting Metrics Details");
75                         String reply = sender.sendAndWait(5000L);
76                         assertTrue(LoadPropertyFile.isValidJsonString(reply));
77                         LOGGER.info("response =" + reply);
78
79                 } catch (DME2Exception e) {
80                         e.printStackTrace();
81                 } catch (URISyntaxException e) {
82                         e.printStackTrace();
83                 } catch (Exception e) {
84                         e.printStackTrace();
85                 }
86         }
87
88         public void testGetMetricsByName() {
89                 LOGGER.info("Test case get metrics by name initiated");
90                 Properties props = LoadPropertyFile.getPropertyFileDataProducer();
91                 String latitude = props.getProperty("Latitude");
92                 String longitude = props.getProperty("Longitude");
93                 String version = props.getProperty("Version");
94                 String serviceName = props.getProperty("ServiceName");
95                 String env = props.getProperty("Environment");
96                 String partner = props.getProperty("Partner");
97                 String subContextPath = props.getProperty("SubContextPathGetMetricsByName");
98                 String protocol = props.getProperty("Protocol");
99                 String methodType = props.getProperty("MethodTypeGet");
100                 String user = props.getProperty("user");
101                 String password = props.getProperty("password");
102                 String contenttype = props.getProperty("contenttype");
103                 String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/"
104                                 + "envContext=" + env + "/" + "partner=" + partner;
105                 LoadPropertyFile.loadAFTProperties(latitude, longitude);
106                 HashMap<String, String> hm = new HashMap<String, String>();
107                 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
108                 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
109                 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
110                 try {
111                         DME2Client sender = new DME2Client(new URI(url), 5000L);
112                         sender.setAllowAllHttpReturnCodes(true);
113                         sender.setMethod(methodType);
114                         sender.setSubContext(subContextPath);
115                         sender.setPayload("");
116                         sender.addHeader("Content-Type", contenttype);
117                         sender.setCredentials(user, password);
118                         sender.setHeaders(hm);
119
120                         LOGGER.info("Getting Metrics By name");
121                         String reply = sender.sendAndWait(5000L);
122                         assertTrue(LoadPropertyFile.isValidJsonString(reply));
123                         LOGGER.info("response =" + reply);
124
125                 } catch (DME2Exception e) {
126                         e.printStackTrace();
127                 } catch (URISyntaxException e) {
128                         e.printStackTrace();
129                 } catch (Exception e) {
130                         e.printStackTrace();
131                 }
132         }
133 }