summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src
diff options
context:
space:
mode:
authorMichal Kabaj <michal.kabaj@nokia.com>2018-03-07 15:08:52 +0100
committerTakamune Cho <tc012c@att.com>2018-03-09 20:40:43 +0000
commitc6f9a1aab9e6ba545d8148d4f7456235be1e67d8 (patch)
tree777e0cba8d87df922d047caaa51dfbabd0718dd3 /appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src
parent072d9eb28f13b50058cf9a50207dce435ab88369 (diff)
ChefAdapterImpl JUnits
-Added unit tests for chefXXX methods - extracted new test class -Moved privateKeyCheck method to new class PrivateKeyChecker + JUnits -New Factory class ChefAdapterFactory for ChefAdapterImpl construction -Fixed potential bug with wrong String being assigned in iniSvcLogic method Change-Id: I27badfd01bfaa807b8ecb9b4a4c13e7f026e34af Issue-ID: APPC-437 Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src')
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java5
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java2
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterFactory.java30
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java39
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/PrivateKeyChecker.java40
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java6
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplHttpMethodTest.java181
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java4
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/PrivateKeyCheckerTest.java40
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java5
10 files changed, 316 insertions, 36 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java
index a2eadfa63..d96716e9b 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java
@@ -27,7 +27,7 @@ package org.onap.appc.adapter.chef;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.onap.appc.Constants;
-import org.onap.appc.adapter.chef.impl.ChefAdapterImpl;
+import org.onap.appc.adapter.chef.impl.ChefAdapterFactory;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
import org.onap.appc.i18n.Msg;
@@ -74,6 +74,7 @@ public class ChefActivator implements BundleActivator {
*/
private Configuration configuration = ConfigurationFactory.getConfiguration();
+
/**
* Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
* this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
@@ -95,7 +96,7 @@ public class ChefActivator implements BundleActivator {
String appName = readApplicationNameFromProperties();
logger.info(Msg.COMPONENT_INITIALIZING, appName, ADAPTER_NAME);
- adapter = new ChefAdapterImpl();
+ adapter = new ChefAdapterFactory().create();
if (registration == null) {
logger.info(Msg.REGISTERING_SERVICE, appName, ADAPTER_NAME,
ChefAdapter.class.getSimpleName());
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java
index a69ccf1b2..818d51694 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java
@@ -25,7 +25,7 @@ import org.onap.appc.adapter.chef.chefclient.api.ChefApiClient;
import org.onap.appc.adapter.chef.chefclient.impl.ChefApiClientImpl;
import org.onap.appc.adapter.chef.chefclient.impl.ChefApiHeaderFactory;
-public final class ChefApiClientFactory {
+public class ChefApiClientFactory {
private HttpClient httpClient = HttpClients.createDefault();
private ChefApiHeaderFactory chefApiHeaderFactory = new ChefApiHeaderFactory();
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterFactory.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterFactory.java
new file mode 100644
index 000000000..60c06bad4
--- /dev/null
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterFactory.java
@@ -0,0 +1,30 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.adapter.chef.impl;
+
+import org.onap.appc.adapter.chef.ChefAdapter;
+import org.onap.appc.adapter.chef.chefclient.ChefApiClientFactory;
+
+public class ChefAdapterFactory {
+
+ public ChefAdapter create() {
+ return new ChefAdapterImpl(new ChefApiClientFactory(), new PrivateKeyChecker());
+ }
+}
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java
index 4a4081e5c..0f4b8c8b3 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java
@@ -23,11 +23,9 @@
*/
package org.onap.appc.adapter.chef.impl;
-import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -109,12 +107,12 @@ public class ChefAdapterImpl implements ChefAdapter {
private static final String CHEF_SERVER_RESULT_MSG_STR = "chefServerResult.message";
private static final String CHEF_ACTION_STR = "chefAction";
private static final String NODE_LIST_STR = "NodeList";
- private ChefApiClientFactory chefApiClientFactory = new ChefApiClientFactory();
+ private final ChefApiClientFactory chefApiClientFactory;
+ private final PrivateKeyChecker privateKeyChecker;
- /**
- * This default constructor is used as a work around because the activator wasnt getting called
- */
- public ChefAdapterImpl() {
+ ChefAdapterImpl(ChefApiClientFactory chefApiClientFactory, PrivateKeyChecker privateKeyChecker) {
+ this.chefApiClientFactory = chefApiClientFactory;
+ this.privateKeyChecker = privateKeyChecker;
logger.info("Initialize Chef Adapter");
}
@@ -136,7 +134,7 @@ public class ChefAdapterImpl implements ChefAdapter {
JSONObject envJ = new JSONObject(env);
String envName = envJ.getString("name");
String message;
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
// update the details of an environment on the Chef server.
ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
ChefResponse chefResponse = chefApiClient.put("/environments/" + envName, env);
@@ -187,7 +185,7 @@ public class ChefAdapterImpl implements ChefAdapter {
rc.isAlive();
code = 200;
String message = null;
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
for (String nodeName: nodes) {
@@ -295,7 +293,7 @@ public class ChefAdapterImpl implements ChefAdapter {
for (String node : nodes) {
String chefAction = "/nodes/" + node;
String message;
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
ChefResponse chefResponse = getApiMethod(chefAction);
code = chefResponse.getStatusCode();
message = chefResponse.getBody();
@@ -396,17 +394,6 @@ public class ChefAdapterImpl implements ChefAdapter {
}
}
- private Boolean privateKeyCheck() {
- File f = new File(clientPrivatekey);
- if (f.exists()) {
- logger.info("Key exists");
- return true;
- } else {
- logger.info("Key doesn't exists");
- return false;
- }
- }
-
@SuppressWarnings("nls")
@Override
public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
@@ -458,7 +445,7 @@ public class ChefAdapterImpl implements ChefAdapter {
int code;
String message;
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
ChefResponse chefResponse = getApiMethod(chefAction);
code = chefResponse.getStatusCode();
message = chefResponse.getBody();
@@ -483,7 +470,7 @@ public class ChefAdapterImpl implements ChefAdapter {
rc.isAlive();
int code;
String message;
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
ChefResponse chefResponse = chefApiClient.put(chefAction, chefNodeStr);
@@ -513,7 +500,7 @@ public class ChefAdapterImpl implements ChefAdapter {
int code;
String message;
// should load pem from somewhere else
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
// need pass path into it
@@ -541,7 +528,7 @@ public class ChefAdapterImpl implements ChefAdapter {
rc.isAlive();
int code;
String message;
- if (privateKeyCheck()) {
+ if (privateKeyChecker.doesExist(clientPrivatekey)) {
ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
ChefResponse chefResponse = chefApiClient.delete(chefAction);
code = chefResponse.getStatusCode();
@@ -718,7 +705,7 @@ public class ChefAdapterImpl implements ChefAdapter {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
String codeStr = "server".equals(target) ? CHEF_SERVER_RESULT_CODE_STR : CHEF_CLIENT_RESULT_CODE_STR;
- String messageStr = "client".equals(target) ? CHEF_SERVER_RESULT_MSG_STR : CHEF_CLIENT_RESULT_MSG_STR;
+ String messageStr = "client".equals(target) ? CHEF_CLIENT_RESULT_MSG_STR : CHEF_SERVER_RESULT_MSG_STR;
svcLogic.setStatus(OUTCOME_SUCCESS);
svcLogic.setAttribute(codeStr, Integer.toString(code));
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/PrivateKeyChecker.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/PrivateKeyChecker.java
new file mode 100644
index 000000000..e6c35cb29
--- /dev/null
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/PrivateKeyChecker.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.adapter.chef.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.File;
+
+class PrivateKeyChecker {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(PrivateKeyChecker.class);
+
+ Boolean doesExist(String clientPrivateKeyPath) {
+ File f = new File(clientPrivateKeyPath);
+ if (f.exists()) {
+ logger.info("Key exists");
+ return true;
+ } else {
+ logger.info("Key doesn't exists");
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java
index 1f447a4ff..d4850cda2 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java
@@ -41,7 +41,7 @@ public class ChefAdapterImplDataRetrieverTest {
SvcLogicContext svcLogicContext = new SvcLogicContext();
// WHEN
- ChefAdapter chefAdapter = new ChefAdapterImpl();
+ ChefAdapter chefAdapter = new ChefAdapterFactory().create();
chefAdapter.retrieveData(params, svcLogicContext);
// THEN
@@ -55,7 +55,7 @@ public class ChefAdapterImplDataRetrieverTest {
SvcLogicContext svcLogicContext = new SvcLogicContext();
// WHEN
- ChefAdapter chefAdapter = new ChefAdapterImpl();
+ ChefAdapter chefAdapter = new ChefAdapterFactory().create();
chefAdapter.retrieveData(params, svcLogicContext);
// THEN
@@ -69,7 +69,7 @@ public class ChefAdapterImplDataRetrieverTest {
SvcLogicContext svcLogicContext = new SvcLogicContext();
// WHEN
- ChefAdapter chefAdapter = new ChefAdapterImpl();
+ ChefAdapter chefAdapter = new ChefAdapterFactory().create();
chefAdapter.retrieveData(params, svcLogicContext);
// THEN
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplHttpMethodTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplHttpMethodTest.java
new file mode 100644
index 000000000..82d15366b
--- /dev/null
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplHttpMethodTest.java
@@ -0,0 +1,181 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.adapter.chef.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.verifyZeroInteractions;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.appc.adapter.chef.ChefAdapter;
+import org.onap.appc.adapter.chef.chefclient.ChefApiClientFactory;
+import org.onap.appc.adapter.chef.chefclient.api.ChefApiClient;
+import org.onap.appc.adapter.chef.chefclient.api.ChefResponse;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ChefAdapterImplHttpMethodTest {
+
+ private static final String CLIENT_PRIVATE_KEY_PATH = "/opt/onap/appc/chef/localhost/onap/testclient.pem";
+ private static final String RESULT_CODE_ATTR_KEY = "chefServerResult.code";
+ private static final String RESULT_MESSAGE_ATTR_KEY = "chefServerResult.message";
+ private static final String EXPECTED_RESPONSE_MSG = "chefResponseMessage";
+ private static final String ACTION_PARAM = "action";
+ private static final String REQUEST_BODY_DATA = "requestBodyData";
+ private static final Map<String, String> PARAMS = ImmutableMap
+ .of("username", "testclient",
+ "serverAddress", "localhost",
+ "organizations", "onap",
+ "chefAction", ACTION_PARAM,
+ "chefRequestBody", REQUEST_BODY_DATA);
+ @Mock
+ private PrivateKeyChecker privateKeyChecker;
+ @Mock
+ private ChefApiClientFactory chefApiClientFactory;
+ @Mock
+ private ChefApiClient chefApiClient;
+
+ private ChefAdapter chefAdapter;
+ private SvcLogicContext svcLogicContext;
+
+ @Before
+ public void setUp() {
+ chefAdapter = new ChefAdapterImpl(chefApiClientFactory, privateKeyChecker);
+ svcLogicContext = new SvcLogicContext();
+ }
+
+ @Test
+ public void chefGet_shouldExecuteHttpClient_andSetChefResponseInContext_whenPrivateKeyFileExists() {
+ assertSuccessfulChefHttpCallFor(() -> chefApiClient.get(ACTION_PARAM), this::chefGet);
+ }
+
+ @Test
+ public void chefGet_shouldNotExecuteHttpClient_andSetErrorResponseInContext_whenPrivateKeyFileDoesNotExist() {
+ assertNoChefCallOccurFor(this::chefGet);
+ }
+
+ @Test
+ public void chefDelete_shouldExecuteHttpClient_andSetChefResponseInContext_whenPrivateKeyFileExists() {
+ assertSuccessfulChefHttpCallFor(() -> chefApiClient.delete(ACTION_PARAM), this::chefDelete);
+ }
+
+ @Test
+ public void chefDelete_shouldNotExecuteHttpClient_andSetErrorResponseInContext_whenPrivateKeyFileDoesNotExist() {
+ assertNoChefCallOccurFor(this::chefDelete);
+ }
+
+ @Test
+ public void chefPut_shouldExecuteHttpClient_andSetChefResponseInContext_whenPrivateKeyFileExists() {
+ assertSuccessfulChefHttpCallFor(() -> chefApiClient.put(ACTION_PARAM, REQUEST_BODY_DATA), this::chefPut);
+ }
+
+ @Test
+ public void chefPut_shouldNotExecuteHttpClient_andSetErrorResponseInContext_whenPrivateKeyFileDoesNotExist() {
+ assertNoChefCallOccurFor(this::chefPut);
+ }
+
+ @Test
+ public void chefPost_shouldExecuteHttpClient_andSetChefResponseInContext_whenPrivateKeyFileExists() {
+ assertSuccessfulChefHttpCallFor(() -> chefApiClient.post(ACTION_PARAM, REQUEST_BODY_DATA), this::chefPost);
+ }
+
+ @Test
+ public void chefPost_shouldNotExecuteHttpClient_andSetErrorResponseInContext_whenPrivateKeyFileDoesNotExist() {
+ assertNoChefCallOccurFor(this::chefPost);
+ }
+
+ public void assertSuccessfulChefHttpCallFor(Supplier<ChefResponse> responseSupplier,
+ Consumer<ChefAdapter> chefAdapterCall) {
+ // GIVEN
+ given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
+ given(chefApiClientFactory.create("https://localhost/organizations/onap",
+ "onap",
+ "testclient",
+ CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient);
+ given(responseSupplier.get()).willReturn(ChefResponse.create(HttpStatus.SC_OK, EXPECTED_RESPONSE_MSG));
+
+ // WHEN
+ chefAdapterCall.accept(chefAdapter);
+
+ // THEN
+ assertThat(svcLogicContext.getStatus()).isEqualTo("success");
+ assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY)).isEqualTo(Integer.toString(HttpStatus.SC_OK));
+ assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(EXPECTED_RESPONSE_MSG);
+ }
+
+ public void assertNoChefCallOccurFor(Consumer<ChefAdapter> chefAdapterCall) {
+ // GIVEN
+ given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(false);
+
+ // WHEN
+ chefAdapterCall.accept(chefAdapter);
+
+ // THEN
+ verifyZeroInteractions(chefApiClient);
+ assertThat(svcLogicContext.getStatus()).isEqualTo("success");
+ assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
+ .isEqualTo(Integer.toString(HttpStatus.SC_INTERNAL_SERVER_ERROR));
+ assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(
+ "Cannot find the private key in the APPC file system, please load the private key to "
+ + CLIENT_PRIVATE_KEY_PATH);
+ }
+
+ public void chefGet(ChefAdapter chefAdapter) {
+ try {
+ chefAdapter.chefGet(PARAMS, svcLogicContext);
+ } catch (SvcLogicException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void chefDelete(ChefAdapter chefAdapter) {
+ try {
+ chefAdapter.chefDelete(PARAMS, svcLogicContext);
+ } catch (SvcLogicException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void chefPost(ChefAdapter chefAdapter) {
+ try {
+ chefAdapter.chefPost(PARAMS, svcLogicContext);
+ } catch (SvcLogicException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void chefPut(ChefAdapter chefAdapter) {
+ try {
+ chefAdapter.chefPut(PARAMS, svcLogicContext);
+ } catch (SvcLogicException e) {
+ e.printStackTrace();
+ }
+ }
+} \ No newline at end of file
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java
index df8326782..7b3546765 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java
@@ -42,7 +42,7 @@ public class ChefAdapterImplTest {
SvcLogicContext svcLogicContext = new SvcLogicContext();
// WHEN
- ChefAdapter chefAdapter = new ChefAdapterImpl();
+ ChefAdapter chefAdapter = new ChefAdapterFactory().create();
chefAdapter.nodeObejctBuilder(params, svcLogicContext);
// THEN
@@ -87,7 +87,7 @@ public class ChefAdapterImplTest {
SvcLogicContext svcLogicContext = new SvcLogicContext();
// WHEN
- ChefAdapter chefAdapter = new ChefAdapterImpl();
+ ChefAdapter chefAdapter = new ChefAdapterFactory().create();
chefAdapter.combineStrings(params, svcLogicContext);
// THEN
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/PrivateKeyCheckerTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/PrivateKeyCheckerTest.java
new file mode 100644
index 000000000..b5c206753
--- /dev/null
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/PrivateKeyCheckerTest.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.adapter.chef.impl;
+
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+
+import org.junit.Test;
+
+public class PrivateKeyCheckerTest {
+
+ @Test
+ public void doesExist_shouldReturnTrue_whenFileExists() {
+ String pemFilePath = getClass().getResource("/testclient.pem").getPath();
+ assertTrue(new PrivateKeyChecker().doesExist(pemFilePath));
+ }
+
+ @Test
+ public void doesExist_shouldReturnFalse_whenFileDoesNotExist() {
+ assertFalse(new PrivateKeyChecker().doesExist("dummyPemFile"));
+ }
+
+} \ No newline at end of file
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java
index d5eb0af36..e7d7e77b9 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java
@@ -33,6 +33,7 @@ import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.appc.adapter.chef.ChefAdapter;
import org.onap.appc.exceptions.APPCException;
import com.att.cdp.exceptions.ZoneException;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -41,14 +42,14 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class TestChefAdapterImpl {
private SvcLogicContext svcContext;
- private ChefAdapterImpl adapter;
+ private ChefAdapter adapter;
private Map<String, String> params;
private String getAttribute;
@Before
public void setup() {
- adapter = new ChefAdapterImpl();
+ adapter = new ChefAdapterFactory().create();
params = new HashMap<>();
params.put("pemPath",
"/src/test/resources/testclient.pem");