diff options
author | Marcus G K Williams <marcus.williams@intel.com> | 2017-09-07 17:16:09 -0700 |
---|---|---|
committer | Skip Wonnell <skip@att.com> | 2017-09-18 03:27:31 +0000 |
commit | c2f55b2e5771f32b84bb07770d15b0d42b8e814b (patch) | |
tree | 1cfbb6c6b04886af91f7d908a68d146477720ed2 /appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main | |
parent | 6475b40bcbb943aa52beec12fc8b54d671d9e429 (diff) |
Add Unit Tests for appc-chef-adapter
Issue-Id: APPC-181
Change-Id: Iee824ca929ea46944ac1673e709074687ad812f9
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
Diffstat (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main')
2 files changed, 19 insertions, 17 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/ApiMethod.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/ApiMethod.java index 19e381ec5..de4f31a04 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/ApiMethod.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/ApiMethod.java @@ -24,25 +24,19 @@ package org.openecomp.appc.adapter.chef.chefapi; -import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; -import org.apache.http.*; -import org.apache.http.client.*; -import org.apache.http.client.methods.*; -import org.apache.http.impl.client.*; +import org.apache.http.HttpResponse; +import org.apache.http.Header; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.util.EntityUtils; import org.openecomp.appc.adapter.chef.chefclient.Utils; -import javax.net.ssl.SSLContext; -import java.io.File; import org.apache.http.HttpEntity; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; public class ApiMethod { private HttpClient client = null; @@ -64,7 +58,7 @@ public class ApiMethod { this.methodName = methodName; } - public ApiMethod execute() { + public ApiMethod createRequest(){ String hashedPath = Utils.sha1AndBase64("/organizations/"+organizations+chefPath); String hashedBody = Utils.sha1AndBase64(reqBody); @@ -101,11 +95,15 @@ public class ApiMethod { * RHS=this.method.getHeaders(); for (int i = 0; i < RHS.length; i++) { * test=test+RHS[i]+"\n"; } test=test+this.reqBody+"\n"; */ + return this; + } + + public ApiMethod execute() { try{ - response = client.execute(method); - resCode = response.getStatusLine().getStatusCode(); - HttpEntity entity1 = response.getEntity(); - responseBody = EntityUtils.toString(entity1);} + response = client.execute(method); + resCode = response.getStatusLine().getStatusCode(); + HttpEntity entity1 = response.getEntity(); + responseBody = EntityUtils.toString(entity1);} catch(Exception ex){ resCode=500; responseBody=ex.getMessage(); diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java index b81c10bc8..ab853dcc4 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java @@ -145,7 +145,11 @@ public class ChefAdapterImpl implements ChefAdapter { serverAddress = params.get("org.openecomp.appc.instance.serverAddress"); organizations = params.get("org.openecomp.appc.instance.organizations"); chefserver = "https://" + serverAddress + ORGANIZATIONS_STR + organizations; - clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + clientName + ".pem"; + if (params.containsKey("org.openecomp.appc.instance.pemPath")) { + clientPrivatekey = params.get("org.openecomp.appc.instance.pemPath"); + } else { + clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + clientName + ".pem"; + } } public Boolean privateKeyCheck() { @@ -444,7 +448,7 @@ public class ChefAdapterImpl implements ChefAdapter { configuration = ConfigurationFactory.getConfiguration(); // need to fetch data from appc configurator or form some file in the appc vms clientName = "testnode"; - clientPrivatekey = "/etc/chef/client.pem"; + clientPrivatekey = System.getProperty("user.dir") + "/src/test/resources/testclient.pem"; serverAddress = "http://example.com"; organizations = "test"; chefserver = serverAddress + ORGANIZATIONS_STR + organizations; |