aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy')
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java151
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java10
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java9
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java173
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java71
5 files changed, 17 insertions, 397 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java
deleted file mode 100644
index 0f44f4f36..000000000
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.actorserviceprovider.controlloop;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-
-public class ControlLoopEventContextTest {
- private static final String MY_KEY = "def";
- private static final UUID REQ_ID = UUID.randomUUID();
- private static final String ITEM_KEY = "obtain-C";
-
- private Map<String, String> enrichment;
- private VirtualControlLoopEvent event;
- private ControlLoopEventContext context;
-
- /**
- * Initializes data, including {@link #context}.
- */
- @Before
- public void setUp() {
- enrichment = Map.of("abc", "one", MY_KEY, "two");
-
- event = new VirtualControlLoopEvent();
- event.setRequestId(REQ_ID);
- event.setAai(enrichment);
-
- context = new ControlLoopEventContext(event);
- }
-
- @Test
- public void testControlLoopEventContext() {
- assertSame(event, context.getEvent());
- assertSame(REQ_ID, context.getRequestId());
- assertEquals(enrichment, context.getEnrichment());
-
- // null event
- assertThatThrownBy(() -> new ControlLoopEventContext(null));
-
- // no request id, no enrichment data
- event.setRequestId(null);
- event.setAai(null);
- context = new ControlLoopEventContext(event);
- assertSame(event, context.getEvent());
- assertNotNull(context.getRequestId());
- assertEquals(Map.of(), context.getEnrichment());
- }
-
- @Test
- public void testContains_testGetProperty_testSetProperty_testRemoveProperty() {
- context.setProperty("abc", "a string");
- context.setProperty(MY_KEY, 100);
-
- assertTrue(context.contains(MY_KEY));
- assertFalse(context.contains("ghi"));
-
- String strValue = context.getProperty("abc");
- assertEquals("a string", strValue);
-
- int intValue = context.getProperty(MY_KEY);
- assertEquals(100, intValue);
-
- context.removeProperty(MY_KEY);
- assertFalse(context.contains(MY_KEY));
- }
-
- @Test
- public void testObtain() {
- final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class);
-
- // property is already loaded
- context.setProperty("obtain-A", "value-A");
- assertNull(context.obtain("obtain-A", params));
-
- // new property - should retrieve
- CompletableFuture<OperationOutcome> future = new CompletableFuture<>();
- when(params.start()).thenReturn(future);
- assertSame(future, context.obtain("obtain-B", params));
-
- // repeat - should get the same future, without invoking start() again
- assertSame(future, context.obtain("obtain-B", params));
- verify(params).start();
-
- // arrange for another invoker to start while this one is starting
- CompletableFuture<OperationOutcome> future2 = new CompletableFuture<>();
-
- when(params.start()).thenAnswer(args -> {
-
- ControlLoopOperationParams params2 = mock(ControlLoopOperationParams.class);
- when(params2.start()).thenReturn(future2);
-
- assertSame(future2, context.obtain(ITEM_KEY, params2));
- return future;
- });
-
- assertSame(future2, context.obtain(ITEM_KEY, params));
-
- // should have canceled the interrupted future
- assertTrue(future.isCancelled());
-
- // return a new future next time start() is called
- CompletableFuture<OperationOutcome> future3 = new CompletableFuture<>();
- when(params.start()).thenReturn(future3);
-
- // repeat - should get the same future
- assertSame(future2, context.obtain(ITEM_KEY, params));
- assertSame(future2, context.obtain(ITEM_KEY, params));
-
- // future2 should still be active
- assertFalse(future2.isCancelled());
-
- // cancel it - now we should get the new future
- future2.cancel(false);
- assertSame(future3, context.obtain(ITEM_KEY, params));
- }
-}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
index 453592d2b..587313a46 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
@@ -77,10 +77,8 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.network.NetworkUtil;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
@@ -118,8 +116,6 @@ public class HttpOperationTest {
@Mock
private Executor executor;
- private VirtualControlLoopEvent event;
- private ControlLoopEventContext context;
private ControlLoopOperationParams params;
private OperationOutcome outcome;
private AtomicReference<InvocationCallback<Response>> callback;
@@ -184,11 +180,7 @@ public class HttpOperationTest {
when(response.readEntity(String.class)).thenReturn(TEXT);
when(response.getStatus()).thenReturn(200);
- event = new VirtualControlLoopEvent();
- event.setRequestId(REQ_ID);
-
- context = new ControlLoopEventContext(event);
- params = ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION).context(context).build();
+ params = ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION).requestId(REQ_ID).build();
outcome = params.makeOutcome(null);
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java
index 5ae804aea..af8f1aaab 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.junit.Before;
import org.junit.Test;
@@ -37,11 +38,9 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
@@ -112,10 +111,8 @@ public class HttpOperatorTest {
assertNotNull(oper2);
assertNotNull(oper2.getClientFactory());
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- ControlLoopEventContext context = new ControlLoopEventContext(event);
- ControlLoopOperationParams params =
- ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION).context(context).build();
+ ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION)
+ .requestId(UUID.randomUUID()).build();
// configure and start it
HttpParams params2 = HttpParams.builder().clientName(HTTP_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java
index 455393c93..b7a6a1d3b 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java
@@ -29,7 +29,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import ch.qos.logback.classic.Logger;
@@ -60,7 +59,6 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -71,14 +69,12 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.common.utils.time.PseudoExecutor;
import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.Operator;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
@@ -119,8 +115,6 @@ public class OperationPartialTest {
@Mock
private Operation guardOperation;
- private VirtualControlLoopEvent event;
- private ControlLoopEventContext context;
private PseudoExecutor executor;
private ControlLoopOperationParams params;
@@ -167,14 +161,9 @@ public class OperationPartialTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
-
- event = new VirtualControlLoopEvent();
- event.setRequestId(REQ_ID);
-
- context = new ControlLoopEventContext(event);
executor = new PseudoExecutor();
- params = ControlLoopOperationParams.builder().completeCallback(this::completer).context(context)
+ params = ControlLoopOperationParams.builder().completeCallback(this::completer).requestId(REQ_ID)
.executor(executor).actorService(service).actor(ACTOR).operation(OPERATION).timeoutSec(TIMEOUT)
.startCallback(this::starter).targetEntity(MY_TARGET_ENTITY).build();
@@ -226,14 +215,20 @@ public class OperationPartialTest {
}
@Test
- public void testGetProperty_testSetProperty() {
+ public void testGetProperty_testSetProperty_testGetRequiredProperty() {
oper.setProperty("propertyA", "valueA");
oper.setProperty("propertyB", "valueB");
oper.setProperty("propertyC", 20);
+ oper.setProperty("propertyD", "valueD");
assertEquals("valueA", oper.getProperty("propertyA"));
assertEquals("valueB", oper.getProperty("propertyB"));
assertEquals(Integer.valueOf(20), oper.getProperty("propertyC"));
+
+ assertEquals("valueD", oper.getRequiredProperty("propertyD", "typeD"));
+
+ assertThatIllegalStateException().isThrownBy(() -> oper.getRequiredProperty("propertyUnknown", "some type"))
+ .withMessage("missing some type");
}
@Test
@@ -261,118 +256,6 @@ public class OperationPartialTest {
assertEquals(MAX_PARALLEL, numEnd);
}
- /**
- * Tests startPreprocessor() when the preprocessor returns a failure.
- */
- @Test
- public void testStartPreprocessorFailure() {
- oper.setPreProc(CompletableFuture.completedFuture(makeFailure()));
-
- verifyRun("testStartPreprocessorFailure", 1, 0, OperationResult.FAILURE_GUARD);
- }
-
- /**
- * Tests startPreprocessor() when the preprocessor throws an exception.
- */
- @Test
- public void testStartPreprocessorException() {
- // arrange for the preprocessor to throw an exception
- oper.setPreProc(CompletableFuture.failedFuture(new IllegalStateException(EXPECTED_EXCEPTION)));
-
- verifyRun("testStartPreprocessorException", 1, 0, OperationResult.FAILURE_GUARD);
- }
-
- /**
- * Tests startPreprocessor() when the pipeline is not running.
- */
- @Test
- public void testStartPreprocessorNotRunning() {
- // arrange for the preprocessor to return success, which will be ignored
- // oper.setGuard(CompletableFuture.completedFuture(makeSuccess()));
-
- oper.start().cancel(false);
- assertTrue(executor.runAll(MAX_REQUESTS));
-
- assertNull(opstart);
- assertNull(opend);
-
- assertEquals(0, numStart);
- assertEquals(0, oper.getCount());
- assertEquals(0, numEnd);
- }
-
- /**
- * Tests startPreprocessor() when the preprocessor <b>builder</b> throws an exception.
- */
- @Test
- public void testStartPreprocessorBuilderException() {
- oper = new MyOper() {
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- throw new IllegalStateException(EXPECTED_EXCEPTION);
- }
- };
-
- assertThatIllegalStateException().isThrownBy(() -> oper.start());
-
- // should be nothing in the queue
- assertEquals(0, executor.getQueueLength());
- }
-
- @Test
- public void testStartPreprocessorAsync() {
- assertNull(oper.startPreprocessorAsync());
- }
-
- @Test
- public void testStartGuardAsync() throws Exception {
- CompletableFuture<OperationOutcome> future = oper.startGuardAsync();
- assertTrue(future.isDone());
- assertEquals(OperationResult.SUCCESS, future.get().getResult());
-
- // verify the parameters that were passed
- ArgumentCaptor<ControlLoopOperationParams> paramsCaptor =
- ArgumentCaptor.forClass(ControlLoopOperationParams.class);
- verify(guardOperator).buildOperation(paramsCaptor.capture());
-
- params = paramsCaptor.getValue();
- assertEquals(OperationPartial.GUARD_ACTOR_NAME, params.getActor());
- assertEquals(OperationPartial.GUARD_OPERATION_NAME, params.getOperation());
- assertNull(params.getRetry());
- assertNull(params.getTimeoutSec());
-
- Map<String, Object> payload = params.getPayload();
- assertNotNull(payload);
-
- assertEquals(oper.makeGuardPayload(), payload);
- }
-
- /**
- * Tests startGuardAsync() when preprocessing is disabled.
- */
- @Test
- public void testStartGuardAsyncDisabled() {
- params = params.toBuilder().preprocessed(true).build();
- assertNull(new MyOper().startGuardAsync());
- }
-
- @Test
- public void testMakeGuardPayload() {
- Map<String, Object> payload = oper.makeGuardPayload();
- assertSame(REQ_ID, payload.get("requestId"));
-
- // request id changes, so remove it
- payload.remove("requestId");
-
- assertEquals("{actor=my-actor, operation=my-operation, target=my-entity}", payload.toString());
-
- // repeat, but with closed loop name
- event.setClosedLoopControlName("my-loop");
- payload = oper.makeGuardPayload();
- payload.remove("requestId");
- assertEquals("{actor=my-actor, operation=my-operation, target=my-entity, clname=my-loop}", payload.toString());
- }
-
@Test
public void testStartOperationAsync() {
oper.start();
@@ -616,34 +499,6 @@ public class OperationPartialTest {
assertTrue(oper.isSameOperation(outcome));
}
- /**
- * Tests handleFailure() when the outcome is a success.
- */
- @Test
- public void testHandlePreprocessorFailureSuccess() {
- oper.setPreProc(CompletableFuture.completedFuture(makeSuccess()));
- verifyRun("testHandlePreprocessorFailureTrue", 1, 1, OperationResult.SUCCESS);
- }
-
- /**
- * Tests handleFailure() when the outcome is <i>not</i> a success.
- */
- @Test
- public void testHandlePreprocessorFailureFailed() throws Exception {
- oper.setPreProc(CompletableFuture.completedFuture(makeFailure()));
- verifyRun("testHandlePreprocessorFailureFalse", 1, 0, OperationResult.FAILURE_GUARD);
- }
-
- /**
- * Tests handleFailure() when the outcome is {@code null}.
- */
- @Test
- public void testHandlePreprocessorFailureNull() throws Exception {
- // arrange to return a null outcome from the preprocessor
- oper.setPreProc(CompletableFuture.completedFuture(null));
- verifyRun("testHandlePreprocessorFailureNull", 1, 0, OperationResult.FAILURE_GUARD);
- }
-
@Test
public void testFromException() {
// arrange to generate an exception when operation runs
@@ -1204,13 +1059,6 @@ public class OperationPartialTest {
return outcome;
}
- private OperationOutcome makeFailure() {
- OperationOutcome outcome = params.makeOutcome(null);
- outcome.setResult(OperationResult.FAILURE);
-
- return outcome;
- }
-
/**
* Verifies a run.
*
@@ -1358,10 +1206,5 @@ public class OperationPartialTest {
*/
return 0L;
}
-
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- return (preProc != null ? preProc : super.startPreprocessorAsync());
- }
}
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java
index caa840891..b6bd50c7e 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java
@@ -49,18 +49,15 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.Operator;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams.ControlLoopOperationParamsBuilder;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
public class ControlLoopOperationParamsTest {
private static final String NULL_MSG = "null";
- private static final String REQUEST_ID_NAME = "requestId";
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String ACTOR = "my-actor";
private static final String OPERATION = "my-operation";
@@ -68,7 +65,6 @@ public class ControlLoopOperationParamsTest {
private static final Integer RETRY = 3;
private static final Integer TIMEOUT = 100;
private static final UUID REQ_ID = UUID.randomUUID();
- private static final UUID REQ_ID2 = UUID.randomUUID();
@Mock
private Actor actor;
@@ -80,12 +76,6 @@ public class ControlLoopOperationParamsTest {
private Consumer<OperationOutcome> completer;
@Mock
- private ControlLoopEventContext context;
-
- @Mock
- private VirtualControlLoopEvent event;
-
- @Mock
private Executor executor;
@Mock
@@ -118,14 +108,10 @@ public class ControlLoopOperationParamsTest {
when(operator.buildOperation(any())).thenReturn(operation);
when(operation.start()).thenReturn(operFuture);
- when(event.getRequestId()).thenReturn(REQ_ID);
-
- when(context.getEvent()).thenReturn(event);
-
payload = new TreeMap<>();
params = ControlLoopOperationParams.builder().actorService(actorService).completeCallback(completer)
- .context(context).executor(executor).actor(ACTOR).operation(OPERATION).payload(payload)
+ .requestId(REQ_ID).executor(executor).actor(ACTOR).operation(OPERATION).payload(payload)
.retry(RETRY).targetEntity(TARGET_ENTITY).timeoutSec(TIMEOUT)
.startCallback(starter).preprocessed(true).build();
@@ -134,14 +120,14 @@ public class ControlLoopOperationParamsTest {
@Test
public void testStart() {
- assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().context(null).build().start());
+ assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().requestId(null).build().start());
assertSame(operFuture, params.start());
}
@Test
public void testBuild() {
- assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().context(null).build().build());
+ assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().requestId(null).build().build());
assertSame(operation, params.build());
}
@@ -149,26 +135,6 @@ public class ControlLoopOperationParamsTest {
@Test
public void testGetRequestId() {
assertSame(REQ_ID, params.getRequestId());
-
- // when both request ID and event request ID are set - should use request ID
- // parameter
- assertSame(REQ_ID2, params.toBuilder().requestId(REQ_ID2).build().getRequestId());
- }
-
- /**
- * Tests getRequestId() when the request ID is not available in the context.
- */
- @Test
- public void testGetRequestIdNotFromContext() {
- // try with null context
- assertNull(params.toBuilder().context(null).build().getRequestId());
-
- // try with null event
- when(context.getEvent()).thenReturn(null);
- assertNull(params.getRequestId());
-
- // set request ID directly
- assertSame(REQ_ID2, params.toBuilder().requestId(REQ_ID2).build().getRequestId());
}
@Test
@@ -243,14 +209,12 @@ public class ControlLoopOperationParamsTest {
testValidate("actorService", NULL_MSG, bldr -> bldr.actorService(null));
testValidate("executor", NULL_MSG, bldr -> bldr.executor(null));
testValidate("operation", NULL_MSG, bldr -> bldr.operation(null));
+ testValidate("requestId", NULL_MSG, bldr -> bldr.requestId(null));
// has no target entity
BeanValidationResult result = params.toBuilder().targetEntity(null).build().validate();
assertTrue(result.isValid());
- // note: if context is null, then it will ACTUALLY complain about the request ID
- testValidate(REQUEST_ID_NAME, NULL_MSG, bldr -> bldr.context(null));
-
// check edge cases
assertTrue(params.toBuilder().build().validate().isValid());
@@ -259,28 +223,8 @@ public class ControlLoopOperationParamsTest {
.completeCallback(null).build().validate().isValid());
// test with minimal fields
- assertTrue(ControlLoopOperationParams.builder().actorService(actorService).context(context).actor(ACTOR)
+ assertTrue(ControlLoopOperationParams.builder().actorService(actorService).requestId(REQ_ID).actor(ACTOR)
.operation(OPERATION).targetEntity(TARGET_ENTITY).build().validate().isValid());
-
- // test when event has no request ID
- when(event.getRequestId()).thenReturn(null);
- result = params.validate();
- assertFalse(result.isValid());
- assertThat(result.getResult()).contains("event").contains(REQUEST_ID_NAME).contains(NULL_MSG);
-
- // try when context has no event
- when(context.getEvent()).thenReturn(null);
- result = params.validate();
- assertFalse(result.isValid());
- assertThat(result.getResult()).contains("event").doesNotContain(REQUEST_ID_NAME).contains(NULL_MSG);
-
- // has both request ID and context, but no event
- result = params.toBuilder().requestId(REQ_ID2).build().validate();
- assertTrue(result.isValid());
-
- // has request ID, but not context
- result = params.toBuilder().requestId(REQ_ID2).context(null).build().validate();
- assertTrue(result.isValid());
}
private void testValidate(String fieldName, String expected,
@@ -312,11 +256,6 @@ public class ControlLoopOperationParamsTest {
}
@Test
- public void testGetContext() {
- assertSame(context, params.getContext());
- }
-
- @Test
public void testGetExecutor() {
assertSame(executor, params.getExecutor());