diff options
author | Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com> | 2018-03-15 08:33:00 -0400 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-03-16 13:23:53 +0000 |
commit | 3cbf289d3e7319338031e0ddf270404c8ba16df2 (patch) | |
tree | 4804a1a7c1df1a599461eecf5ae6bc3ec00ed127 /appc-adapters/appc-chef-adapter | |
parent | d273922725ebed244d8ba6458dee68487f260de5 (diff) |
ChefAdapterImpl- checkInfo junits
-Added junit tests for checkInfo method to verify if input params are present
-Support for Michal Kabaj as part of APPC-437
Change-Id: I29758f29f32354439ea0471e1afa3df6bb8184b9
Issue-ID: APPC-437
Signed-off-by: Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
Diffstat (limited to 'appc-adapters/appc-chef-adapter')
-rw-r--r-- | appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java | 45 |
1 files changed, 44 insertions, 1 deletions
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 92893303d..62de292d9 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 @@ -21,6 +21,7 @@ package org.onap.appc.adapter.chef.impl; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Answers.RETURNS_DEEP_STUBS; import static org.mockito.BDDMockito.given; @@ -38,6 +39,7 @@ import org.mockito.runners.MockitoJUnitRunner; import org.onap.appc.adapter.chef.chefclient.ChefApiClientFactory; 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 ChefAdapterImplTest { @@ -149,4 +151,45 @@ public class ChefAdapterImplTest { .isEqualTo(Integer.toString(HttpStatus.SC_INTERNAL_SERVER_ERROR)); assertThat(svcLogicContext.getAttribute(CHEF_AGENT_MESSAGE_KEY)).isEqualTo(new RuntimeException().toString()); } -} + + @Test + public void chefInfo_shouldUpdateSvcLogicContext_withFailStatusAndMsg_andThrowException_whenUsernameParamIsMissing() { + Map<String, String> params = ImmutableMap.of( + "serverAddress", "http://chefAddress", + "organizations", "onap"); + checkIfInputParamsAreValidated(params); + } + + @Test + public void chefInfo_shouldUpdateSvcLogicContext_withFailStatusAndMsg_andThrowException_whenServerAddressParamIsMissing() { + Map<String, String> params = ImmutableMap.of( + "username", "TestUsername", + "organizations", "onap"); + checkIfInputParamsAreValidated(params); + } + + @Test + public void chefInfo_shouldUpdateSvcLogicContext_withFailStatusAndMsg_andThrowException_whenOrganizationsParamIsMissing() { + Map<String, String> params = ImmutableMap.of( + "username", "TestUsername", + "serverAddress", "http://chefAddress"); + checkIfInputParamsAreValidated(params); + } + + private void checkIfInputParamsAreValidated(Map<String, String> params) { + // GIVEN + String expectedErrorMsg = "Missing mandatory param(s) such as username, serverAddress, organizations"; + SvcLogicContext svcLogicContext = new SvcLogicContext(); + + // WHEN// THEN + assertThatExceptionOfType(SvcLogicException.class) + .isThrownBy(() -> chefAdapterFactory.create().chefGet(params, svcLogicContext)) + .withMessage("Chef Adapter error:" + + expectedErrorMsg); + assertThat(svcLogicContext.getStatus()).isEqualTo("failure"); + assertThat(svcLogicContext.getAttribute("chefServerResult.code")) + .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED)); + assertThat(svcLogicContext.getAttribute("chefServerResult.message")) + .isEqualTo(expectedErrorMsg); + } +}
\ No newline at end of file |