3222046a8f5fe49490834b306cd7727313aa01ba
[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 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.ibm.disthub2.impl.client.PropSchema;
36
37 public class DME2AdminTest extends TestCase {
38         private static final Logger LOGGER = Logger.getLogger(DME2AdminTest.class);
39
40         protected String url;
41         
42         protected Properties props;
43         
44         protected HashMap<String, String> hm;
45         
46         protected String methodType;
47         
48         protected String contentType;
49         
50         protected String user;
51         
52         protected String password;
53         
54         @Override
55         protected void setUp() throws Exception {
56                 super.setUp();
57                 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1");
58                 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
59                 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");
60                 this.props = LoadPropertyFile.getPropertyFileDataProducer();
61                 String latitude = props.getProperty("Latitude");
62                 String longitude = props.getProperty("Longitude");
63                 String version = props.getProperty("Version");
64                 String serviceName = props.getProperty("ServiceName");
65                 serviceName = "dmaap-v1.dev.dmaap.dt.saat.acsi.att.com/admin";
66                 String env = props.getProperty("Environment");
67                 String partner = props.getProperty("Partner");
68                 String protocol = props.getProperty("Protocol");
69                 
70                 methodType = props.getProperty("MethodTypeGet");
71                 contentType = props.getProperty("contenttype");
72                 user = props.getProperty("user");
73                 password = props.getProperty("password");
74                 
75                 
76                 this.url = protocol + "://" + serviceName + "?" + "version=" + version + "&" + "envContext=" + env + "&"
77                                 + "routeOffer=" + partner + "&partner=BOT_R";
78                 LoadPropertyFile.loadAFTProperties(latitude, longitude);
79                 hm = new HashMap<String, String>();
80                 hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
81                 hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
82                 hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000");             
83         }
84         
85         public void testGetConsumerCache() {
86                 LOGGER.info("test case consumer cache started");
87                 
88                 String subContextPath = props.getProperty("SubContextPathGetAdminConsumerCache");
89                 try {
90                         DME2Client sender = new DME2Client(new URI(url), 5000L);
91                         sender.setAllowAllHttpReturnCodes(true);
92                         sender.setMethod(methodType);
93                         sender.setSubContext(subContextPath);
94                         sender.setPayload("");
95                         sender.addHeader("Content-Type", contentType);
96                         
97                         sender.addHeader("X-CambriaAuth", "user1:7J49YriFlyRgebyOsSJhZvY/C60=");
98                         sender.addHeader("X-X-CambriaDate", "2016-10-18T09:56:04-05:00");
99                         
100                         //sender.setCredentials(user, password);
101                         sender.setHeaders(hm);
102                         LOGGER.info("Getting consumer Cache");
103                         String reply = sender.sendAndWait(5000L);
104                         System.out.println(reply);
105                         assertTrue(LoadPropertyFile.isValidJsonString(reply));
106                         assertNotNull(reply);
107                         LOGGER.info("response from consumer cache=" + reply);
108
109                 } catch (DME2Exception e) {
110                         e.printStackTrace();
111                 } catch (URISyntaxException e) {
112                         e.printStackTrace();
113                 } catch (Exception e) {
114                         e.printStackTrace();
115                 }
116         }
117
118         public void ttestDropConsumerCache() {
119                 LOGGER.info("Drom consumer cache initiated");
120
121                 String subContextPath = props.getProperty("SubContextPathDropAdminConsumerCache");
122
123                 try {
124                         DME2Client sender = new DME2Client(new URI(url), 5000L);
125                         sender.setAllowAllHttpReturnCodes(true);
126                         sender.setMethod(methodType);
127                         sender.setSubContext(subContextPath);
128                         sender.setPayload("");
129                         sender.addHeader("Content-Type", contentType);
130                         sender.setCredentials(user, password);
131                         sender.setHeaders(hm);
132
133                         LOGGER.info("Dropping consumer cache...........");
134                         String reply = sender.sendAndWait(5000L);
135                         
136                         // assertTrue(LoadPropertyFile.isValidJsonString(reply));
137                         assertNotNull(reply);
138                         LOGGER.info("response =" + reply);
139                 } catch (DME2Exception e) {
140                         e.printStackTrace();
141                 } catch (URISyntaxException e) {
142                         e.printStackTrace();
143                 } catch (Exception e) {
144                         e.printStackTrace();
145                 }
146         }
147
148 }