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 DME2AdminTest extends TestCase {
36 private static final Logger LOGGER = LogManager.getLogger(DME2AdminTest.class);
40 protected Properties props;
42 protected HashMap<String, String> hm;
44 protected String methodType;
46 protected String contentType;
48 protected String user;
50 protected String password;
53 protected void setUp() throws Exception {
55 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1");
56 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
57 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");
58 this.props = LoadPropertyFile.getPropertyFileDataProducer();
59 String latitude = props.getProperty("Latitude");
60 String longitude = props.getProperty("Longitude");
61 String version = props.getProperty("Version");
62 String serviceName = props.getProperty("ServiceName");
63 serviceName = "mr/admin";
64 String env = props.getProperty("Environment");
65 String partner = props.getProperty("Partner");
66 String protocol = props.getProperty("Protocol");
68 methodType = props.getProperty("MethodTypeGet");
69 contentType = props.getProperty("contenttype");
70 user = props.getProperty("user");
71 password = props.getProperty("password");
73 protocol + "://" + serviceName + "?" + "version=" + version + "&" + "envContext=" + env
75 + "routeOffer=" + partner + "&partner=BOT_R";
76 LoadPropertyFile.loadAFTProperties(latitude, longitude);
77 hm = new HashMap<String, String>();
78 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
79 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
80 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");
83 public void testGetConsumerCache() {
84 LOGGER.info("test case consumer cache started");
85 String subContextPath = props.getProperty("SubContextPathGetAdminConsumerCache");
87 DME2Client sender = new DME2Client(new URI(url), 5000L);
88 sender.setAllowAllHttpReturnCodes(true);
89 sender.setMethod(methodType);
90 sender.setSubContext(subContextPath);
91 sender.setPayload("");
92 sender.addHeader("Content-Type", contentType);
94 sender.addHeader("X-CambriaAuth", "user1:7J49YriFlyRgebyOsSJhZvY/C60=");
95 sender.addHeader("X-X-CambriaDate", "2016-10-18T09:56:04-05:00");
97 //sender.setCredentials(user, password);
98 sender.setHeaders(hm);
99 LOGGER.info("Getting consumer Cache");
100 String reply = sender.sendAndWait(5000L);
101 System.out.println(reply);
102 assertTrue(LoadPropertyFile.isValidJsonString(reply));
103 assertNotNull(reply);
104 LOGGER.info("response from consumer cache=" + reply);
105 } catch (DME2Exception e) {
107 } catch (URISyntaxException e) {
109 } catch (Exception e) {
114 public void ttestDropConsumerCache() {
115 LOGGER.info("Drom consumer cache initiated");
116 String subContextPath = props.getProperty("SubContextPathDropAdminConsumerCache");
118 DME2Client sender = new DME2Client(new URI(url), 5000L);
119 sender.setAllowAllHttpReturnCodes(true);
120 sender.setMethod(methodType);
121 sender.setSubContext(subContextPath);
122 sender.setPayload("");
123 sender.addHeader("Content-Type", contentType);
124 sender.setCredentials(user, password);
125 sender.setHeaders(hm);
127 LOGGER.info("Dropping consumer cache...........");
128 String reply = sender.sendAndWait(5000L);
130 // assertTrue(LoadPropertyFile.isValidJsonString(reply));
131 assertNotNull(reply);
132 LOGGER.info("response =" + reply);
133 } catch (DME2Exception e) {
135 } catch (URISyntaxException e) {
137 } catch (Exception e) {