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