diff options
author | Michal Kabaj <michal.kabaj@nokia.com> | 2018-03-21 13:26:51 +0100 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-03-22 14:23:52 +0000 |
commit | 7f42758f8292e1440a63867ec5d885abc35e38a4 (patch) | |
tree | c799a1646c24fba509424fbd1e4e8891371e41e0 /appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java | |
parent | f1bd95884be20932a3ab7a92440e9e306902c1a0 (diff) |
ChefAdapterImpl junits
- Added new Junit class ChefAdapterImplVNFCOperationsTest
- Added unit tests for method vnfcEnvironment
- Small refactor to for exception handling in vnfcEnvironment method to
improve readability and avoid catching and rethrowing same exception
Change-Id: I58a43390ff45598f6d17da48eed3620667008cb7
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/main/java')
-rw-r--r-- | appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java | 54 |
1 files changed, 25 insertions, 29 deletions
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 f689668bb..f5b6b6751 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 @@ -114,21 +114,18 @@ public class ChefAdapterImpl implements ChefAdapter { @Override public void vnfcEnvironment(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException { int code; - try { - logger.info("environment of VNF-C"); - chefInfo(params, ctx); - RequestContext rc = new RequestContext(ctx); - logger.info("Context" + ctx); - rc.isAlive(); - String env = params.get("Environment"); - logger.info("Environmnet" + env); - if (env.equals(StringUtils.EMPTY)) { - chefServerResult(rc, 200, "Skip Environment block "); - } else { - JSONObject envJ = new JSONObject(env); - String envName = envJ.getString("name"); - String message; - if (privateKeyChecker.doesExist(clientPrivatekey)) { + logger.info("environment of VNF-C"); + chefInfo(params, ctx); + String env = params.get("Environment"); + logger.info("Environmnet" + env); + if (env.equals(StringUtils.EMPTY)) { + chefServerResult(new RequestContext(ctx), 200, "Skip Environment block "); + } else { + String message; + if (privateKeyChecker.doesExist(clientPrivatekey)) { + try { + JSONObject envJ = new JSONObject(env); + String envName = envJ.getString("name"); // 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); @@ -141,22 +138,21 @@ public class ChefAdapterImpl implements ChefAdapter { message = chefResponse.getBody(); logger.info("requestbody {}", chefResponse.getBody()); } - - } else { - code = 500; - message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey; - doFailure(ctx, code, message); + chefServerResult(new RequestContext(ctx), code, message); + } catch (JSONException e) { + code = 401; + logger.error(POSTING_REQUEST_JSON_ERROR_STR, e); + doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage()); + } catch (Exception e) { + code = 401; + logger.error(POSTING_REQUEST_ERROR_STR, e); + doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage()); } - chefServerResult(rc, code, message); + } else { + code = 500; + message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey; + doFailure(ctx, code, message); } - } catch (JSONException e) { - code = 401; - logger.error(POSTING_REQUEST_JSON_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage()); - } catch (Exception e) { - code = 401; - logger.error(POSTING_REQUEST_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage()); } } |