2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7 * =============================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.appc.adapter.chef.impl;
24 import static com.google.common.collect.Maps.immutableEntry;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27 import static org.mockito.BDDMockito.given;
29 import com.google.common.collect.ImmutableMap;
30 import com.google.common.collect.ImmutableMap.Builder;
32 import java.util.Map.Entry;
33 import org.apache.http.HttpStatus;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.runners.MockitoJUnitRunner;
40 import org.onap.appc.adapter.chef.chefclient.ChefApiClientFactory;
41 import org.onap.appc.adapter.chef.chefclient.api.ChefApiClient;
42 import org.onap.appc.adapter.chef.chefclient.api.ChefResponse;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
46 @RunWith(MockitoJUnitRunner.class)
47 public class ChefAdapterImplVNFCOperationsTest {
49 private static final String CHEF_END_POINT = "https://localhost/organizations/onap";
50 private static final String USERNAME = "testclient";
51 private static final String ORGANIZATIONS = "onap";
52 private static final String SERVER_ADDRESS = "localhost";
53 private static final String CLIENT_PRIVATE_KEY_PATH = "/opt/onap/appc/chef/localhost/onap/testclient.pem";
54 private static final String RESULT_CODE_ATTR_KEY = "chefServerResult.code";
55 private static final String RESULT_MESSAGE_ATTR_KEY = "chefServerResult.message";
56 private static final String FAILURE_STATUS = "failure";
57 private static final String SUCCESS_STATUS = "success";
58 private static final String CHEF_ADAPTER_ERROR_PREFIX = "Chef Adapter error:";
59 private static final String ENV_PARAM_KEY = "Environment";
60 private static final String ENV_JSON_VALUE = "{name:envName}";
63 private PrivateKeyChecker privateKeyChecker;
65 private ChefApiClientFactory chefApiClientFactory;
67 private ChefApiClient chefApiClient;
70 private ChefAdapterFactory chefAdapterFactory;
71 private SvcLogicContext svcLogicContext;
75 svcLogicContext = new SvcLogicContext();
78 @SuppressWarnings("unchecked")
80 public void vnfcEnvironment_shouldSkipEnvironmentCreation_whenEnvParamIsEmpty() throws SvcLogicException {
82 Map<String, String> params = givenInputParams(immutableEntry(ENV_PARAM_KEY, ""));
85 chefAdapterFactory.create().vnfcEnvironment(params, svcLogicContext);
88 assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS);
89 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
90 .isEqualTo(Integer.toString(HttpStatus.SC_OK));
91 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo("Skip Environment block ");
94 @SuppressWarnings("unchecked")
96 public void vnfcEnvironment_shouldCreateNewEnvironment_forEnvParam_whenRequestedEnvDoesNotExist()
97 throws SvcLogicException {
99 String expectedErrorMessage = "New Environment Created";
100 Map<String, String> params = givenInputParams(immutableEntry(ENV_PARAM_KEY, ENV_JSON_VALUE));
101 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
102 given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME,
103 CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient);
104 given(chefApiClient.put("/environments/" + "envName", ENV_JSON_VALUE))
105 .willReturn(ChefResponse.create(HttpStatus.SC_NOT_FOUND, ""));
106 given(chefApiClient.post("/environments", ENV_JSON_VALUE))
107 .willReturn(ChefResponse.create(HttpStatus.SC_CREATED, expectedErrorMessage));
110 chefAdapterFactory.create().vnfcEnvironment(params, svcLogicContext);
113 assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS);
114 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
115 .isEqualTo(Integer.toString(HttpStatus.SC_CREATED));
116 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage);
119 @SuppressWarnings("unchecked")
121 public void vnfcEnvironment_shouldNotAttemptEnvCreation_andThrowException_whenPrivateKeyCheckFails() {
123 String expectedErrorMsg = "Cannot find the private key in the APPC file system, please load the private key to ";
124 Map<String, String> params = givenInputParams(immutableEntry(ENV_PARAM_KEY, ENV_JSON_VALUE));
125 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(false);
128 assertThatExceptionOfType(SvcLogicException.class)
129 .isThrownBy(() -> chefAdapterFactory.create().vnfcEnvironment(params, svcLogicContext))
130 .withMessage(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMsg + CLIENT_PRIVATE_KEY_PATH);
132 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
133 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
134 .isEqualTo(Integer.toString(HttpStatus.SC_INTERNAL_SERVER_ERROR));
135 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
136 .isEqualTo(expectedErrorMsg + CLIENT_PRIVATE_KEY_PATH);
139 @SuppressWarnings("unchecked")
141 public void vnfcEnvironment_shouldNotAttemptEnvCreation_andHandleJSONException_whenJSONParamsAreMalformed() {
143 String expectedErrorMessage = "Error posting request due to invalid JSON block: ";
144 Map<String, String> params = givenInputParams(immutableEntry(ENV_PARAM_KEY, "MALFORMED_JSON"));
145 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
148 assertThatExceptionOfType(SvcLogicException.class)
149 .isThrownBy(() -> chefAdapterFactory.create().vnfcEnvironment(params, svcLogicContext))
150 .withMessageStartingWith(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
152 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
153 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
154 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
155 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
156 .startsWith(expectedErrorMessage);
159 @SuppressWarnings("unchecked")
161 public void vnfcEnvironment_shouldNotAttemptEnvCreation_andHandleException_whenExceptionOccursDuringExecution() {
163 String expectedErrorMessage = "Error posting request: ";
164 Map<String, String> params = givenInputParams(immutableEntry(ENV_PARAM_KEY, ENV_JSON_VALUE));
165 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
166 given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME,
167 CLIENT_PRIVATE_KEY_PATH)).willThrow(new NullPointerException("Null value encountered"));
170 assertThatExceptionOfType(SvcLogicException.class)
171 .isThrownBy(() -> chefAdapterFactory.create().vnfcEnvironment(params, svcLogicContext))
172 .withMessage(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage + "vnfcEnvironmentNull value encountered");
174 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
175 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
176 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
177 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).startsWith(expectedErrorMessage);
181 public void vnfcNodeObjects_shouldUpdateNodeObjects_andSetCodeAndMessageFromLastSuccessfulResponseInSvcLogicContext()
182 throws SvcLogicException {
184 ChefResponse firstNodeResponse = ChefResponse.create(HttpStatus.SC_OK, "firstMessage");
185 ChefResponse secondNodeResponse = ChefResponse.create(HttpStatus.SC_OK, "secondMessage");
186 int expectedHttpStatus = HttpStatus.SC_OK;
187 String expectedMessage = "secondMessage";
189 assertNodeObjectsAreUpdatedFor(firstNodeResponse, secondNodeResponse, expectedHttpStatus, expectedMessage);
193 public void vnfcNodeObjects_shouldStopProcessingNodeObjectUpdates_whenFirstReturnedResponseIsOtherThan_200()
194 throws SvcLogicException {
195 ChefResponse firstNodeResponse = ChefResponse.create(HttpStatus.SC_ACCEPTED, "firstMessage");
196 ChefResponse secondNodeResponse = ChefResponse.create(HttpStatus.SC_OK, "secondMessage");
197 int expectedHttpStatus = HttpStatus.SC_ACCEPTED;
198 String expectedMessage = "firstMessage";
200 assertNodeObjectsAreUpdatedFor(firstNodeResponse, secondNodeResponse, expectedHttpStatus, expectedMessage);
203 @SuppressWarnings("unchecked")
204 public void assertNodeObjectsAreUpdatedFor(ChefResponse firstNodeResponse, ChefResponse secondNodeResponse,
205 int expectedHttpStatus, String expectedMessage) throws SvcLogicException {
207 Map<String, String> params = givenInputParams(
208 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]"),
209 immutableEntry("Node", "{name:nodeName}"));
211 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
212 given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME,
213 CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient);
214 given(chefApiClient.put("/nodes/" + "test1.vnf_b.onap.com", "{\"name\":\"test1.vnf_b.onap.com\"}"))
215 .willReturn(firstNodeResponse);
217 .put("/nodes/" + "test2.vnf_b.onap.com", "{\"name\":\"test2.vnf_b.onap.com\"}"))
218 .willReturn(secondNodeResponse);
221 chefAdapterFactory.create().vnfcNodeobjects(params, svcLogicContext);
224 assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS);
225 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
226 .isEqualTo(Integer.toString(expectedHttpStatus));
227 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedMessage);
230 @SuppressWarnings("unchecked")
232 public void vnfcNodeObjects_shouldThrowSvcLogicException_whenNodeListParamIsEmpty() {
233 Map<String, String> params = givenInputParams(
234 immutableEntry("NodeList", ""),
235 immutableEntry("Node", "{name:nodeName}"));
236 checkMissingParamsAreValidated(params);
239 @SuppressWarnings("unchecked")
241 public void vnfcNodeObjects_shouldThrowSvcLogicException_whenNodeParamIsEmpty() {
242 Map<String, String> params = givenInputParams(
243 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]"),
244 immutableEntry("Node", ""));
245 checkMissingParamsAreValidated(params);
248 public void checkMissingParamsAreValidated(Map<String, String> params) {
250 String expectedErrorMsg = "vnfcNodeobjectsMissing Mandatory param(s) Node , NodeList ";
253 assertThatExceptionOfType(SvcLogicException.class)
254 .isThrownBy(() -> chefAdapterFactory.create().vnfcNodeobjects(params, svcLogicContext))
255 .withMessage(CHEF_ADAPTER_ERROR_PREFIX + "Error posting request: " + expectedErrorMsg);
257 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
258 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
259 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
260 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
261 .isEqualTo("Error posting request: " + expectedErrorMsg);
264 @SuppressWarnings("unchecked")
266 public void vnfcNodeObjects_shouldNotUpdateNodes_andHandleJSONException_whenJSONParamsAreMalformed() {
268 Map<String, String> params = givenInputParams(
269 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]"),
270 immutableEntry("Node", "MALFORMED_JSON"));
271 String expectedErrorMessage = "Error posting request due to invalid JSON block: ";
272 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
275 assertThatExceptionOfType(SvcLogicException.class)
276 .isThrownBy(() -> chefAdapterFactory.create().vnfcNodeobjects(params, svcLogicContext))
277 .withMessageStartingWith(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
279 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
280 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
281 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
282 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
283 .startsWith(expectedErrorMessage);
286 @SuppressWarnings("unchecked")
288 public void vnfcPushJob_shouldUpdateSvcContextWithJobId_whenPushJobWasSuccessfullyCreatedWithCallbackUrl()
289 throws SvcLogicException {
290 Map<String, String> params = givenInputParams(
291 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]"),
292 immutableEntry("CallbackCapable", "true"),
293 immutableEntry("RequestId", "666"),
294 immutableEntry("CallbackUrl", "someURLForCallback"));
295 int expectedResponseStatus = HttpStatus.SC_CREATED;
296 String expectedResponseMessage = "jobs:666-9";
298 assertVnfcPushJobExecutionFor(params, buildJsonRequestWithCallback(), expectedResponseStatus,
299 expectedResponseMessage);
300 assertThat(svcLogicContext.getAttribute("jobID")).isEqualTo("666");
303 private String buildJsonRequestWithCallback() {
304 return "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
305 + "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]" + "," + "\"env\": {\"RequestId\": \"" + "666"
306 + "\", \"CallbackUrl\": \""
307 + "someURLForCallback" + "\"}," + "\"capture_output\": true" + "}";
310 @SuppressWarnings("unchecked")
312 public void vnfcPushJob_shouldUpdateSvcContextWithJobId_whenPushJobWasSuccessfullyCreatedWithoutCallbackUrl()
313 throws SvcLogicException {
314 Map<String, String> params = givenInputParams(
315 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]"),
316 immutableEntry("RequestId", "666"));
317 int expectedResponseStatus = HttpStatus.SC_OK;
318 String expectedResponseMessage = "jobs:666-9";
320 assertVnfcPushJobExecutionFor(params, buildJsonRequestWithoutCallback(), expectedResponseStatus,
321 expectedResponseMessage);
322 assertThat(svcLogicContext.getAttribute("jobID")).isBlank();
325 private String buildJsonRequestWithoutCallback() {
326 return "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
327 + "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]" + "," + "\"env\": {}," + "\"capture_output\": true"
331 public void assertVnfcPushJobExecutionFor(Map<String, String> params, String pushRequestWithCallback,
332 int expectedResponseStatus, String expectedResponseMessage) throws SvcLogicException {
334 given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME,
335 CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient);
336 given(chefApiClient.post("/pushy/jobs", pushRequestWithCallback))
337 .willReturn(ChefResponse.create(expectedResponseStatus, expectedResponseMessage));
340 chefAdapterFactory.create().vnfcPushJob(params, svcLogicContext);
343 assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS);
344 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
345 .isEqualTo(Integer.toString(expectedResponseStatus));
346 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedResponseMessage);
349 @SuppressWarnings("unchecked")
351 public void vnfcPushJob_shouldNotPushJob_andThrowException_whenNodeListParamIsEmpty() {
353 String expectedErrorMessage = "Error posting request: vnfcPushJobMissing Mandatory param(s) NodeList ";
354 Map<String, String> params = givenInputParams();
356 assertThatExceptionOfType(SvcLogicException.class)
357 .isThrownBy(() -> chefAdapterFactory.create().vnfcPushJob(params, svcLogicContext))
358 .withMessageStartingWith(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
360 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
361 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
362 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
363 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage);
366 @SuppressWarnings("unchecked")
368 public void fetchResults_shouldNotFetchResults_andThrowException_whenNodeListParamIsEmpty() {
370 String expectedErrorMessage = "Error posting request: fetchResultsMissing Mandatory param(s) NodeList ";
371 Map<String, String> params = givenInputParams();
373 assertThatExceptionOfType(SvcLogicException.class)
374 .isThrownBy(() -> chefAdapterFactory.create().fetchResults(params, svcLogicContext))
375 .withMessageStartingWith(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
377 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
378 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
379 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
380 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage);
383 @SuppressWarnings("unchecked")
385 public void fetchResults_shouldNotFetchResults_andThrowException_whenPrivateKeyCheckFails() {
387 Map<String, String> params = givenInputParams(
388 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]"));
389 String expectedErrorMessage =
390 "Error posting request: fetchResults"
391 + CHEF_ADAPTER_ERROR_PREFIX
392 + "Cannot find the private key in the APPC file system, please load the private key to "
393 + CLIENT_PRIVATE_KEY_PATH;
394 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(false);
397 assertThatExceptionOfType(SvcLogicException.class)
398 .isThrownBy(() -> chefAdapterFactory.create().fetchResults(params, svcLogicContext))
399 .withMessage(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
401 assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
402 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
403 .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
404 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
405 .isEqualTo(expectedErrorMessage);
408 @SuppressWarnings("unchecked")
410 public void fetchResults_shouldUpdateSvcLogicContextWithJsonResponse_fromSuccessfulChefServerCall()
411 throws SvcLogicException {
413 String json = "{normal:{PushJobOutput : \"ssh start/running, process 1090\"}}";
414 Map<String, String> params = givenInputParams(
415 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\"]"));
416 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
417 given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME,
418 CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient);
419 given(chefApiClient.get("/nodes/" + "test1.vnf_b.onap.com"))
420 .willReturn(ChefResponse.create(HttpStatus.SC_OK, json));
423 chefAdapterFactory.create().fetchResults(params, svcLogicContext);
426 assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS);
427 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
428 .isEqualTo(Integer.toString(HttpStatus.SC_OK));
429 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
430 .isEqualTo("{\"test1.vnf_b.onap.com\":{\"PushJobOutput\":\"ssh start/running, process 1090\"}}");
433 @SuppressWarnings("unchecked")
435 public void fetchResults_shouldUpdateSvcLogicContextWithFailedMessage_whenReturnedJSONMessageIsMissingAttribute()
436 throws SvcLogicException {
438 String json = "{normal:{invalidKey : \"ssh start/running, process 1090\"}}";
439 Map<String, String> params = givenInputParams(
440 immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\"]"));
441 given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true);
442 given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME,
443 CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient);
444 given(chefApiClient.get("/nodes/" + "test1.vnf_b.onap.com"))
445 .willReturn(ChefResponse.create(HttpStatus.SC_OK, json));
448 chefAdapterFactory.create().fetchResults(params, svcLogicContext);
451 assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS);
452 assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
453 .isEqualTo(Integer.toString(HttpStatus.SC_INTERNAL_SERVER_ERROR));
454 assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
455 .isEqualTo("Cannot find PushJobOutput");
458 @SuppressWarnings("unchecked")
459 private Map<String, String> givenInputParams(Entry<String, String>... entries) {
460 Builder<String, String> paramsBuilder = ImmutableMap.builder();
461 paramsBuilder.put("username", USERNAME)
462 .put("serverAddress", SERVER_ADDRESS)
463 .put("organizations", ORGANIZATIONS);
465 for (Entry<String, String> entry : entries) {
466 paramsBuilder.put(entry);
468 return paramsBuilder.build();