X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=appc-adapters%2Fappc-chef-adapter%2Fappc-chef-adapter-bundle%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fappc%2Fadapter%2Fchef%2Fimpl%2FChefAdapterImplVNFCOperationsTest.java;h=7f9c505ffb02d3b3378ebc63befe9b2437574650;hb=250db09d1ed3475ea7a03cbd21b244b523a64814;hp=dadcca56a7a7d0b441763d122166be0c6c6d5a2e;hpb=91e81944dd410196c5cd3fde32fed746ec5de466;p=appc.git diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java index dadcca56a..7f9c505ff 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java @@ -373,9 +373,9 @@ public class ChefAdapterImplVNFCOperationsTest { immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]")); String expectedErrorMessage = "Error posting request: " - + CHEF_ADAPTER_ERROR_PREFIX - + "Cannot find the private key in the APPC file system, please load the private key to " - + CLIENT_PRIVATE_KEY_PATH; + + CHEF_ADAPTER_ERROR_PREFIX + + "Cannot find the private key in the APPC file system, please load the private key to " + + CLIENT_PRIVATE_KEY_PATH; given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(false); // WHEN // THEN @@ -390,6 +390,54 @@ public class ChefAdapterImplVNFCOperationsTest { .isEqualTo(expectedErrorMessage); } + @Test + public void fetchResults_shouldUpdateSvcLogicContextWithJsonResponse_fromSuccessfulChefServerCall() + throws SvcLogicException { + // GIVEN + String json = "{normal:{PushJobOutput : \"ssh start/running, process 1090\"}}"; + Map params = givenInputParams( + immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\"]")); + given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true); + given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME, + CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient); + given(chefApiClient.get("/nodes/" + "test1.vnf_b.onap.com")) + .willReturn(ChefResponse.create(HttpStatus.SC_OK, json)); + + // WHEN + chefAdapterFactory.create().fetchResults(params, svcLogicContext); + + // THEN + assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS); + assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY)) + .isEqualTo(Integer.toString(HttpStatus.SC_OK)); + assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)) + .isEqualTo("{\"test1.vnf_b.onap.com\":{\"PushJobOutput\":\"ssh start/running, process 1090\"}}"); + } + + @Test + public void fetchResults_shouldUpdateSvcLogicContextWithFailedMessage_whenReturnedJSONMessageIsMissingAttribute() + throws SvcLogicException { + // GIVEN + String json = "{normal:{invalidKey : \"ssh start/running, process 1090\"}}"; + Map params = givenInputParams( + immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\"]")); + given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(true); + given(chefApiClientFactory.create(CHEF_END_POINT, ORGANIZATIONS, USERNAME, + CLIENT_PRIVATE_KEY_PATH)).willReturn(chefApiClient); + given(chefApiClient.get("/nodes/" + "test1.vnf_b.onap.com")) + .willReturn(ChefResponse.create(HttpStatus.SC_OK, json)); + + // WHEN + chefAdapterFactory.create().fetchResults(params, svcLogicContext); + + // THEN + assertThat(svcLogicContext.getStatus()).isEqualTo(SUCCESS_STATUS); + 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 PushJobOutput"); + } + private Map givenInputParams(Entry... entries) { Builder paramsBuilder = ImmutableMap.builder(); paramsBuilder.put("username", USERNAME)