[DMaap-msgrtr] Update Security Vulnerabilities
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / test / dme2 / DME2AdminTest.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 java.net.URI;
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;
33
34 public class DME2AdminTest extends TestCase {
35
36     private static final Logger LOGGER = LogManager.getLogger(DME2AdminTest.class);
37
38     protected String url;
39
40     protected Properties props;
41
42     protected HashMap<String, String> hm;
43
44     protected String methodType;
45
46     protected String contentType;
47
48     protected String user;
49
50     protected String password;
51
52     @Override
53     protected void setUp() throws Exception {
54         super.setUp();
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");
67
68         methodType = props.getProperty("MethodTypeGet");
69         contentType = props.getProperty("contenttype");
70         user = props.getProperty("user");
71         password = props.getProperty("password");
72         this.url =
73             protocol + "://" + serviceName + "?" + "version=" + version + "&" + "envContext=" + env
74                 + "&"
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");
81     }
82
83     public void testGetConsumerCache() {
84         LOGGER.info("test case consumer cache started");
85         String subContextPath = props.getProperty("SubContextPathGetAdminConsumerCache");
86         try {
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);
93
94             sender.addHeader("X-CambriaAuth", "user1:7J49YriFlyRgebyOsSJhZvY/C60=");
95             sender.addHeader("X-X-CambriaDate", "2016-10-18T09:56:04-05:00");
96
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) {
106             e.printStackTrace();
107         } catch (URISyntaxException e) {
108             e.printStackTrace();
109         } catch (Exception e) {
110             e.printStackTrace();
111         }
112     }
113
114     public void ttestDropConsumerCache() {
115         LOGGER.info("Drom consumer cache initiated");
116         String subContextPath = props.getProperty("SubContextPathDropAdminConsumerCache");
117         try {
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);
126
127             LOGGER.info("Dropping consumer cache...........");
128             String reply = sender.sendAndWait(5000L);
129
130             // assertTrue(LoadPropertyFile.isValidJsonString(reply));
131             assertNotNull(reply);
132             LOGGER.info("response =" + reply);
133         } catch (DME2Exception e) {
134             e.printStackTrace();
135         } catch (URISyntaxException e) {
136             e.printStackTrace();
137         } catch (Exception e) {
138             e.printStackTrace();
139         }
140     }
141 }