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