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;
28 import java.net.URISyntaxException;
29 import java.util.Properties;
30 import junit.framework.TestCase;
31 import org.apache.logging.log4j.LogManager;
32 import org.apache.logging.log4j.Logger;
34 public class DME2ApiKeyTest extends TestCase {
36 private static final Logger LOGGER = LogManager.getLogger(DME2ApiKeyTest.class);
40 protected Properties props;
43 protected void setUp() throws Exception {
45 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1");
46 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
47 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");
48 this.props = LoadPropertyFile.getPropertyFileDataProducer();
49 String latitude = props.getProperty("Latitude");
50 String longitude = props.getProperty("Longitude");
51 String version = props.getProperty("Version");
52 String serviceName = props.getProperty("ServiceName");
53 String env = props.getProperty("Environment");
54 String partner = props.getProperty("Partner");
55 String protocol = props.getProperty("Protocol");
57 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");
65 ApiKeyBean apiKeyBean = new ApiKeyBean("user1@onap.com", "Creating Api Key.m");
66 System.out.println(url);
67 returnKey(apiKeyBean, url, props);
70 public String returnKey(ApiKeyBean apibean, String url, Properties props) {
73 LOGGER.info("Call to return key ");
74 DME2Client sender = new DME2Client(new URI(url), 5000L);
75 sender.setAllowAllHttpReturnCodes(true);
76 sender.setMethod(props.getProperty("MethodTypePost"));
77 sender.setSubContext(props.getProperty("SubContextPathGetCreateKeys"));
78 String jsonStringApiBean = new ObjectMapper().writeValueAsString(apibean);
79 sender.setPayload(jsonStringApiBean);
80 sender.addHeader("content-type", props.getProperty("contenttype"));
81 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
82 LOGGER.info("creating ApiKey");
83 reply = sender.sendAndWait(5000L);
84 System.out.println("reply: " + reply);
85 assertTrue(LoadPropertyFile.isValidJsonString(reply));
86 LOGGER.info("response =" + reply);
87 } catch (DME2Exception e) {
89 } catch (URISyntaxException e) {
91 } catch (Exception e) {
97 public void testGetAllKey() {
98 LOGGER.info("Test case Get All key initiated....");
100 DME2Client sender = new DME2Client(new URI(this.url), 5000L);
101 sender.setAllowAllHttpReturnCodes(true);
102 sender.setMethod(this.props.getProperty("MethodTypeGet"));
103 String subcontextPath = this.props.getProperty("SubContextPathGetApiKeys");
104 // sender.setSubContext(subcontextPath);
105 sender.setPayload("");
106 sender.addHeader("content-type", props.getProperty("contenttype"));
107 sender.setCredentials(props.getProperty("user"), props.getProperty("password"));
108 LOGGER.info("Fetching all keys");
109 String reply = sender.sendAndWait(5000L);
110 System.out.println(reply);
111 assertTrue(LoadPropertyFile.isValidJsonString(reply));
112 LOGGER.info("response =" + reply);
113 } catch (DME2Exception e) {
115 } catch (URISyntaxException e) {
117 } catch (Exception e) {