diff options
author | Jim Hahn <jrh3@att.com> | 2020-07-29 13:50:40 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-07-31 14:08:17 -0400 |
commit | acded8235dcbb0b06abaa98297fecef78b4eec41 (patch) | |
tree | 8b400d09875cd2c6f7844fbbe0c4d9e1e1a16230 /models-interactions/model-actors/actorServiceProvider/src/test | |
parent | 1da24b28d9df7c8ad5154d7788dab0ab9da589f8 (diff) |
Add property lists to Actors
Modified the Actor code to provide a list of properties needed by the
actor to perform a given operation.
Added a build() method to the parameter class so invokers can build an
operation and set its properties prior to starting it.
Added a "preprocessed" field to the parameter class so invokers can
indicate that the Actor need not perform any preprocessing steps. Will
modify the actors, in a subsequent review, to observe the flag.
Added "properties" to Operation so invokers can set the properties. Will
modify the actors, in a subsequent review, to use the property values
instead of the event context.
Tweaked a few Actors to get values using the "params" object instead of
reaching inside to the event object that it contains.
Addressed review comment(s):
- add prefix to other property names
Issue-ID: POLICY-2746
Change-Id: I65996aef5cec5afe25e8287c0b2f5f322c532ca5
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src/test')
7 files changed, 56 insertions, 15 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index b62eae8a6..e28ddeb09 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -35,6 +35,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; @@ -363,7 +364,7 @@ public class BidirectionalTopicOperationTest { private class MyStringOperation extends BidirectionalTopicOperation<String, String> { public MyStringOperation() { - super(BidirectionalTopicOperationTest.this.params, config, String.class); + super(BidirectionalTopicOperationTest.this.params, config, String.class, Collections.emptyList()); } @Override @@ -385,7 +386,8 @@ public class BidirectionalTopicOperationTest { private class MyScoOperation extends BidirectionalTopicOperation<MyRequest, StandardCoderObject> { public MyScoOperation() { - super(BidirectionalTopicOperationTest.this.params, config, StandardCoderObject.class); + super(BidirectionalTopicOperationTest.this.params, config, StandardCoderObject.class, + Collections.emptyList()); } @Override @@ -407,7 +409,7 @@ public class BidirectionalTopicOperationTest { private class MyOperation extends BidirectionalTopicOperation<MyRequest, MyResponse> { public MyOperation() { - super(BidirectionalTopicOperationTest.this.params, config, MyResponse.class); + super(BidirectionalTopicOperationTest.this.params, config, MyResponse.class, Collections.emptyList()); } @Override 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 1b3485d5d..33e530334 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 @@ -502,7 +502,7 @@ public class HttpOperationTest { private class MyGetOperation<T> extends HttpOperation<T> { public MyGetOperation(Class<T> responseClass) { - super(HttpOperationTest.this.params, HttpOperationTest.this.config, responseClass); + super(HttpOperationTest.this.params, HttpOperationTest.this.config, responseClass, Collections.emptyList()); } @Override @@ -523,7 +523,8 @@ public class HttpOperationTest { private class MyPostOperation extends HttpOperation<MyResponse> { public MyPostOperation() { - super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class); + super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class, + Collections.emptyList()); } @Override @@ -550,7 +551,8 @@ public class HttpOperationTest { private class MyPutOperation extends HttpOperation<MyResponse> { public MyPutOperation() { - super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class); + super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class, + Collections.emptyList()); } @Override @@ -577,7 +579,7 @@ public class HttpOperationTest { private class MyDeleteOperation extends HttpOperation<String> { public MyDeleteOperation() { - super(HttpOperationTest.this.params, HttpOperationTest.this.config, String.class); + super(HttpOperationTest.this.params, HttpOperationTest.this.config, String.class, Collections.emptyList()); } @Override 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 f85ef30b6..5ae804aea 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 @@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; +import java.util.Collections; import java.util.Map; import java.util.concurrent.CompletableFuture; import org.junit.Before; @@ -157,7 +158,7 @@ public class HttpOperatorTest { private class MyOperation extends HttpOperation<String> { public MyOperation(ControlLoopOperationParams params, HttpConfig config) { - super(params, config, String.class); + super(params, config, String.class, Collections.emptyList()); } @Override diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java index ed5ba9b56..780964629 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java @@ -31,6 +31,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.Collections; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; @@ -196,7 +197,7 @@ public class HttpPollingOperationTest { @Test public void testDetmStatus() { // make an operation that does NOT override detmStatus() - oper = new HttpOperation<String>(params, config, String.class) {}; + oper = new HttpOperation<String>(params, config, String.class, Collections.emptyList()) {}; assertThatThrownBy(() -> oper.detmStatus(rawResponse, response)) .isInstanceOf(UnsupportedOperationException.class); @@ -230,7 +231,7 @@ public class HttpPollingOperationTest { private static class MyOper extends HttpOperation<String> { public MyOper(ControlLoopOperationParams params, HttpConfig config) { - super(params, config, String.class); + super(params, config, String.class, Collections.emptyList()); setUsePolling(); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java index 2a22b4b86..413667b20 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import java.util.Collections; import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -111,7 +112,7 @@ public class HttpPollingOperatorTest { private static class MyOperation extends HttpOperation<String> { public MyOperation(ControlLoopOperationParams params, HttpConfig config) { - super(params, config, String.class); + super(params, config, String.class, Collections.emptyList()); } } } 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 e2ed2d98f..9bbc528ec 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 @@ -36,6 +36,7 @@ import ch.qos.logback.classic.Logger; import java.time.Instant; import java.util.ArrayDeque; import java.util.Arrays; +import java.util.Collections; import java.util.Deque; import java.util.LinkedList; import java.util.List; @@ -106,6 +107,8 @@ public class OperationPartialTest { private static final Logger logger = (Logger) LoggerFactory.getLogger(OperationPartial.class); private static final ExtractAppender appender = new ExtractAppender(); + private static final List<String> PROP_NAMES = List.of("hello", "world"); + @Mock private ActorService service; @Mock @@ -217,6 +220,22 @@ public class OperationPartialTest { } @Test + public void testGetPropertyNames() { + assertThat(oper.getPropertyNames()).isEqualTo(PROP_NAMES); + } + + @Test + public void testGetProperty_testSetProperty() { + oper.setProperty("propertyA", "valueA"); + oper.setProperty("propertyB", "valueB"); + oper.setProperty("propertyC", 20); + + assertEquals("valueA", oper.getProperty("propertyA")); + assertEquals("valueB", oper.getProperty("propertyB")); + assertEquals(Integer.valueOf(20), oper.getProperty("propertyC")); + } + + @Test public void testStart() { verifyRun("testStart", 1, 1, PolicyResult.SUCCESS); } @@ -406,7 +425,7 @@ public class OperationPartialTest { /* * Use an operation that doesn't override doOperation(). */ - OperationPartial oper2 = new OperationPartial(params, config) {}; + OperationPartial oper2 = new OperationPartial(params, config, Collections.emptyList()) {}; oper2.start(); assertTrue(executor.runAll(MAX_REQUESTS)); @@ -1118,7 +1137,7 @@ public class OperationPartialTest { @Test public void testGetRetryWait() { // need an operator that doesn't override the retry time - OperationPartial oper2 = new OperationPartial(params, config) {}; + OperationPartial oper2 = new OperationPartial(params, config, Collections.emptyList()) {}; assertEquals(OperationPartial.DEFAULT_RETRY_WAIT_MS, oper2.getRetryWaitMs()); } @@ -1290,7 +1309,7 @@ public class OperationPartialTest { public MyOper() { - super(OperationPartialTest.this.params, config); + super(OperationPartialTest.this.params, config, PROP_NAMES); } @Override 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 e4c83049b..98ca6736d 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 @@ -126,7 +126,7 @@ public class ControlLoopOperationParamsTest { params = ControlLoopOperationParams.builder().actorService(actorService).completeCallback(completer) .context(context).executor(executor).actor(ACTOR).operation(OPERATION).payload(payload) .retry(RETRY).target(TARGET).targetEntity(TARGET_ENTITY).timeoutSec(TIMEOUT) - .startCallback(starter).build(); + .startCallback(starter).preprocessed(true).build(); outcome = params.makeOutcome(); } @@ -139,6 +139,13 @@ public class ControlLoopOperationParamsTest { } @Test + public void testBuild() { + assertSame(operation, params.build()); + + assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().context(null).build().build()); + } + + @Test public void testGetRequestId() { assertSame(REQ_ID, params.getRequestId()); @@ -292,6 +299,14 @@ public class ControlLoopOperationParamsTest { } @Test + public void test() { + assertTrue(params.isPreprocessed()); + + // should be false when unspecified + assertFalse(ControlLoopOperationParams.builder().build().isPreprocessed()); + } + + @Test public void testGetRetry() { assertSame(RETRY, params.getRetry()); |