From 0bca5f40a33cd5663002c49ed3d6950ab8417487 Mon Sep 17 00:00:00 2001 From: Tomasz Gwozdecki Date: Wed, 11 Jul 2018 03:52:04 -0400 Subject: junits for DefaultResponseHandler -Added new test for DefaultResponseHandler Change-Id: Iee616c2a73eee3b130bbc68a16055355ecf4eab9 Issue-ID: APPC-975 Signed-off-by: Tomasz Gwozdecki --- .../DefaultResponseHandlerTest.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'appc-config/appc-flow-controller/provider') diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java index 399259ad8..dc5e2553c 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java @@ -21,8 +21,10 @@ package org.onap.appc.flow.controller.ResponseHandlerImpl; import static org.junit.Assert.assertEquals; +import com.google.common.collect.Lists; import java.util.Collections; import org.junit.Test; +import org.onap.appc.flow.controller.data.Response; import org.onap.appc.flow.controller.data.ResponseAction; import org.onap.appc.flow.controller.data.Transaction; @@ -31,20 +33,51 @@ public class DefaultResponseHandlerTest { @Test public void handlerResponse_shouldReturnEmptyResponseAction_whenTransactionResponsesAreNull() { Transaction transaction = new Transaction(); - assertDefaultResponseAction(transaction); + assertExpectedResponseAction(transaction, new ResponseAction()); } @Test public void handlerResponse_shouldReturnEmptyResponseAction_whenTransactionResponsesAreEmpty() { Transaction transaction = new Transaction(); transaction.setResponses(Collections.emptyList()); - assertDefaultResponseAction(transaction); + assertExpectedResponseAction(transaction, new ResponseAction()); } - private void assertDefaultResponseAction(Transaction transaction) { + @Test + public void handlerResponse_shouldReturnExpectedResponseAction_forMatchingStatusCode() { // GIVEN + ResponseAction expectedResponseAction = createExpectedResponseAction(); + String responseCode = "404"; + + Transaction transaction = new Transaction(); + transaction.setStatusCode(responseCode); + transaction.setResponses(Lists.newArrayList( + createResponse(null, null), + createResponse(null, "500"), + createResponse(expectedResponseAction, responseCode))); + + assertExpectedResponseAction(transaction, expectedResponseAction); + } + + private ResponseAction createExpectedResponseAction() { ResponseAction expectedResponseAction = new ResponseAction(); + expectedResponseAction.setIntermediateMessage(true); + expectedResponseAction.setJump("value1"); + expectedResponseAction.setRetry("value2"); + expectedResponseAction.setWait("value3"); + expectedResponseAction.setIgnore(true); + expectedResponseAction.setStop(true); + return expectedResponseAction; + } + + private Response createResponse(ResponseAction expectedResponseAction, String responseCode) { + Response response = new Response(); + response.setResponseCode(responseCode); + response.setResponseAction(expectedResponseAction); + return response; + } + private void assertExpectedResponseAction(Transaction transaction, ResponseAction expectedResponseAction) { // WHEN ResponseAction responseAction = new DefaultResponseHandler().handlerResponse(transaction); -- cgit 1.2.3-korg