aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Kabaj <michal.kabaj@nokia.com>2018-04-06 16:14:56 +0200
committerTakamune Cho <tc012c@att.com>2018-04-06 14:47:05 +0000
commit596a8a86e0e6d4f1b8a019936b5d7e2b12eec337 (patch)
treebeebd41cc63b7830484e63e033cd4831ecd67661
parent39c2a8df8e4a9d6a7017ee1c3b15e3797565b492 (diff)
ChefAdapterImpl junits
-Add new JUnits to ChefAdapterImplVNFCOperationsTest Change-Id: Idd4cd456d6409a499e569c7175d97642fc3607d2 Issue-ID: APPC-437 Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java40
1 files changed, 40 insertions, 0 deletions
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 5955d6099..dadcca56a 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
@@ -350,6 +350,46 @@ public class ChefAdapterImplVNFCOperationsTest {
assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage);
}
+ @Test
+ public void fetchResults_shouldNotFetchResults_andThrowException_whenNodeListParamIsEmpty() {
+ // GIVEN
+ String expectedErrorMessage = "Error posting request: Missing Mandatory param(s) NodeList ";
+ Map<String, String> params = givenInputParams();
+ // WHEN // THEN
+ assertThatExceptionOfType(SvcLogicException.class)
+ .isThrownBy(() -> chefAdapterFactory.create().fetchResults(params, svcLogicContext))
+ .withMessageStartingWith(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
+
+ assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
+ assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
+ .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
+ assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage);
+ }
+
+ @Test
+ public void fetchResults_shouldNotFetchResults_andThrowException_whenPrivateKeyCheckFails() {
+ // GIVEN
+ Map<String, String> params = givenInputParams(
+ 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;
+ given(privateKeyChecker.doesExist(CLIENT_PRIVATE_KEY_PATH)).willReturn(false);
+
+ // WHEN // THEN
+ assertThatExceptionOfType(SvcLogicException.class)
+ .isThrownBy(() -> chefAdapterFactory.create().fetchResults(params, svcLogicContext))
+ .withMessage(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage);
+
+ assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS);
+ assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY))
+ .isEqualTo(Integer.toString(HttpStatus.SC_UNAUTHORIZED));
+ assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY))
+ .isEqualTo(expectedErrorMessage);
+ }
+
private Map<String, String> givenInputParams(Entry<String, String>... entries) {
Builder<String, String> paramsBuilder = ImmutableMap.builder();
paramsBuilder.put("username", USERNAME)