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;
25 import java.net.URISyntaxException;
26 import java.util.Properties;
28 import org.apache.log4j.Logger;
29 import org.json.JSONObject;
31 import com.att.aft.dme2.api.DME2Client;
32 import com.att.aft.dme2.api.DME2Exception;
33 import com.att.aft.dme2.internal.jackson.map.ObjectMapper;
35 import junit.framework.TestCase;
37 public class DME2ApiKeyTest extends TestCase {
38 private static final Logger LOGGER = Logger.getLogger(DME2ApiKeyTest.class);
42 protected Properties props;
45 protected void setUp() throws Exception {
47 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1");
48 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
49 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");
50 this.props = LoadPropertyFile.getPropertyFileDataProducer();
51 String latitude = props.getProperty("Latitude");
52 String longitude = props.getProperty("Longitude");
53 String version = props.getProperty("Version");
54 String serviceName = props.getProperty("ServiceName");
55 String env = props.getProperty("Environment");
56 String partner = props.getProperty("Partner");
57 String protocol = props.getProperty("Protocol");
58 this.url = protocol + "://" + serviceName + "?" + "version=" + version + "&" + "envContext=" + env + "&"
59 + "routeOffer=" + partner + "&partner=BOT_R";
60 LoadPropertyFile.loadAFTProperties(latitude, longitude);
63 public void testCreateKey() {
64 LOGGER.info("Create Key test case initiated");
66 ApiKeyBean apiKeyBean = new ApiKeyBean("user1@onap.com", "Creating Api Key.m");
68 System.out.println(url);
70 returnKey(apiKeyBean, url, props);
74 public String returnKey(ApiKeyBean apibean, String url, Properties props) {
78 LOGGER.info("Call to return key ");
79 DME2Client sender = new DME2Client(new URI(url), 5000L);
80 sender.setAllowAllHttpReturnCodes(true);
81 sender.setMethod(props.getProperty("MethodTypePost"));
82 sender.setSubContext(props.getProperty("SubContextPathGetCreateKeys"));
83 String jsonStringApiBean = new ObjectMapper().writeValueAsString(apibean);
84 sender.setPayload(jsonStringApiBean);
85 sender.addHeader("content-type", props.getProperty("contenttype"));
86 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
87 LOGGER.info("creating ApiKey");
88 reply = sender.sendAndWait(5000L);
89 System.out.println("reply: " + reply);
90 assertTrue(LoadPropertyFile.isValidJsonString(reply));
91 LOGGER.info("response =" + reply);
93 } catch (DME2Exception e) {
95 } catch (URISyntaxException e) {
97 } catch (Exception e) {
103 public void testGetAllKey() {
104 LOGGER.info("Test case Get All key initiated....");
106 DME2Client sender = new DME2Client(new URI(this.url), 5000L);
107 sender.setAllowAllHttpReturnCodes(true);
108 sender.setMethod(this.props.getProperty("MethodTypeGet"));
109 String subcontextPath = this.props.getProperty("SubContextPathGetApiKeys");
110 // sender.setSubContext(subcontextPath);
111 sender.setPayload("");
112 sender.addHeader("content-type", props.getProperty("contenttype"));
113 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
114 LOGGER.info("Fetching all keys");
115 String reply = sender.sendAndWait(5000L);
116 System.out.println(reply);
117 assertTrue(LoadPropertyFile.isValidJsonString(reply));
118 LOGGER.info("response =" + reply);
119 } catch (DME2Exception e) {
121 } catch (URISyntaxException e) {
123 } catch (Exception e) {