Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-aai / src / test / java / org / openecomp / dcae / apod / analytics / aai / BaseAnalyticsAAIUnitTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *  ============================LICENSE_END===========================================
19  */
20
21 package org.openecomp.dcae.apod.analytics.aai;
22
23 import org.openecomp.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfig;
24 import org.openecomp.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfigBuilder;
25 import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;
26
27 import java.net.MalformedURLException;
28 import java.net.URL;
29 import java.util.LinkedHashMap;
30 import java.util.Map;
31
32 /**
33  * @author Rajiv Singla . Creation Date: 9/18/2017.
34  */
35 public class BaseAnalyticsAAIUnitTest extends BaseDCAEAnalyticsUnitTest {
36
37     protected static final String AAI_HOST_NAME = "1.2.3.4";
38     protected static final Integer AAI_HOST_PORT_NUMBER = 1234;
39     protected static final String AAI_HOST_PROTOCOL = "https";
40     protected static final String AAI_VNF_ENRICHMENT_PATH = "/aai/v11/network/generic-vnfs/generic-vnf";
41     protected static final String AAI_VSERVER_NODE_QUERY_PATH = "/aai/v11/search/nodes-query";
42     protected static final String AAI_VSERVER_QUERY_RESPONSE_LOCATION = "data/json/aai/aai_vserver_resource_data.json";
43
44     protected static final Map<String, String> AAI_HEADERS = new LinkedHashMap<>();
45
46     static {
47         AAI_HEADERS.put("X-FromAppId", "vv-temp");
48         AAI_HEADERS.put("X-TransactionId", "vv-temp");
49         AAI_HEADERS.put("Accept", "application/json");
50         AAI_HEADERS.put("Real-Time", "true");
51         AAI_HEADERS.put("Content-Type", "application/json");
52     }
53
54     protected static final String PROXY_HOST = "proxy.att.com";
55     protected static final Integer PROXY_PORT = 80;
56     protected static final String PROXY_URL = String.format("http://username:password@%s:%s", PROXY_HOST, PROXY_PORT);
57
58     protected static final String AAI_USER_NAME = "DCAE";
59     protected static final String AAI_USER_PASSWORD = "DCAE";
60     protected static final boolean IGNORE_SSL_CERTIFICATE_ERRORS = true;
61
62     protected AAIHttpClientConfig getAAIHttpClientTestConfig(final boolean ignoreSSLCertificateErrors,
63                                                              final String proxyURLString) {
64         URL proxyURL;
65         if (proxyURLString != null) {
66             try {
67                 proxyURL = new URL(proxyURLString);
68             } catch (MalformedURLException e) {
69                 throw new IllegalArgumentException("Proxy URL format is Invalid", e);
70             }
71         } else {
72             proxyURL = null;
73         }
74         return new AAIHttpClientConfigBuilder(AAI_HOST_NAME)
75                 .setAaiProtocol(AAI_HOST_PROTOCOL)
76                 .setAaiHostPortNumber(AAI_HOST_PORT_NUMBER)
77                 .setAaiUserName(AAI_USER_NAME)
78                 .setAaiUserPassword(AAI_USER_PASSWORD)
79                 .setAaiProxyURL(proxyURL)
80                 .setAaiIgnoreSSLCertificateErrors(ignoreSSLCertificateErrors).build();
81     }
82
83 }