diff options
Diffstat (limited to 'models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java')
-rw-r--r-- | models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java index bd23a818b..a43292a65 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java @@ -26,14 +26,17 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Map; import java.util.TreeMap; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -44,6 +47,12 @@ import org.onap.policy.models.decisions.concepts.DecisionResponse; public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { + @Mock + private Consumer<OperationOutcome> started; + @Mock + private Consumer<OperationOutcome> completed; + + private GuardConfig guardConfig; private GuardOperation oper; /** @@ -53,12 +62,14 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { public void setUp() throws Exception { super.setUpBasic(); - GuardConfig cguard = mock(GuardConfig.class); - when(cguard.makeRequest()).thenAnswer(args -> new TreeMap<>(Map.of("action", "guard"))); + guardConfig = mock(GuardConfig.class); + when(guardConfig.makeRequest()).thenAnswer(args -> new TreeMap<>(Map.of("action", "guard"))); - config = cguard; + config = guardConfig; initConfig(); + params = params.toBuilder().startCallback(started).completeCallback(completed).build(); + oper = new GuardOperation(params, config); } @@ -87,6 +98,29 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); } + /** + * Tests startOperationAsync() when the guard is disabled. + */ + @Test + public void testStartOperationAsyncDisabled() throws Exception { + // indicate that it's disabled + when(guardConfig.isDisabled()).thenReturn(true); + + CompletableFuture<OperationOutcome> future2 = oper.start(); + executor.runAll(100); + + verify(client, never()).post(any(), any(), any(), any()); + + // should already be done + assertTrue(future2.isDone()); + + assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + + // ensure callbacks were invoked + verify(started).accept(any()); + verify(completed).accept(any()); + } + @Test public void testMakeRequest() throws CoderException { verifyPayload("makeReqStd.json", makePayload()); |