diff options
author | Jim Hahn <jrh3@att.com> | 2020-02-20 09:40:14 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-02-20 16:29:08 -0500 |
commit | 467247c7970f9ae83464d78929ed970bbf03c593 (patch) | |
tree | 54b78e6505b664c3a61e532bf6f7c276307d6591 /models-interactions/model-actors/actor.test/src/main | |
parent | f6da7772d9dc01ce4ddd21a55b0f1c5fb7ad814f (diff) |
More actor clean-up
Currently, Operator classes refer to Operation classes, and
vice versa, creating a dependency cycle. In addition, there is
a slight problem in that if an operator is reconfigured, any
running operation may get inconsistent configuration data.
Modified the code to create Config objects that are passed to
the operation, instead of passing the Operator to the operations.
This solved both issues.
Replaceed makeOperator() with constructors.
Added parameter type to HttpActors.
Modified guard to get "ONAP" properties from its configuration,
as a default.
Changed setUp() to setUpBasic(), so "throws Exception" could be
removed, thus resolving a sonar issue.
Issue-ID: POLICY-1625
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I21eb8798acfbc636ff1bd8741b21c7278365b6e4
Diffstat (limited to 'models-interactions/model-actors/actor.test/src/main')
3 files changed, 25 insertions, 49 deletions
diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java index e10e94142..bba2bc13a 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java @@ -26,12 +26,9 @@ import java.util.function.BiConsumer; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoderObject; -import org.onap.policy.common.utils.time.PseudoExecutor; -import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperator; -import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; @@ -41,7 +38,8 @@ import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; public class BasicBidirectionalTopicOperation extends BasicOperation { protected static final String MY_SINK = "my-sink"; protected static final String MY_SOURCE = "my-source"; - protected static final int TIMEOUT = 10; + protected static final int TIMEOUT_SEC = 10; + protected static final long TIMEOUT_MS = 1000L * TIMEOUT_SEC; @Captor protected ArgumentCaptor<BiConsumer<String, StandardCoderObject>> listenerCaptor; @@ -51,9 +49,7 @@ public class BasicBidirectionalTopicOperation extends BasicOperation { @Mock protected Forwarder forwarder; @Mock - protected BidirectionalTopicOperator operator; - - protected BidirectionalTopicParams topicParams; + protected BidirectionalTopicConfig config; /** * Constructs the object using a default actor and operation name. @@ -75,31 +71,19 @@ public class BasicBidirectionalTopicOperation extends BasicOperation { /** * Initializes mocks and sets up. */ - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - executor = new PseudoExecutor(); - - makeContext(); - - outcome = params.makeOutcome(); - topicParams = BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).timeoutSec(TIMEOUT) - .build(); - - initOperator(); + @Override + public void setUpBasic() { + super.setUpBasic(); + initConfig(); } /** - * Initializes an operator so that it is "alive" and has the given names. + * Initializes a configuration. */ - protected void initOperator() { - when(operator.isAlive()).thenReturn(true); - when(operator.getFullName()).thenReturn(actorName + "." + operationName); - when(operator.getActorName()).thenReturn(actorName); - when(operator.getName()).thenReturn(operationName); - when(operator.getTopicHandler()).thenReturn(topicHandler); - when(operator.getForwarder()).thenReturn(forwarder); - when(operator.getParams()).thenReturn(topicParams); + protected void initConfig() { + when(config.getTopicHandler()).thenReturn(topicHandler); + when(config.getForwarder()).thenReturn(forwarder); + when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS); } /** diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java index 05fa2260b..e803df8c9 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java @@ -33,7 +33,7 @@ import org.mockito.Mock; import org.mockito.stubbing.Answer; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; /** * Superclass for various HttpOperation tests. @@ -47,25 +47,20 @@ public class BasicHttpOperation<Q> extends BasicOperation { @Captor protected ArgumentCaptor<InvocationCallback<Response>> callbackCaptor; - @Captor protected ArgumentCaptor<Entity<Q>> requestCaptor; - @Captor protected ArgumentCaptor<Map<String, Object>> headerCaptor; @Mock + protected HttpConfig config; + @Mock protected HttpClient client; - @Mock protected HttpClientFactory factory; - @Mock protected Response rawResponse; - @Mock - protected HttpOperator operator; - /** * Constructs the object using a default actor and operation name. @@ -87,8 +82,9 @@ public class BasicHttpOperation<Q> extends BasicOperation { /** * Initializes mocks and sets up. */ - public void setUp() throws Exception { - super.setUp(); + @Override + public void setUpBasic() { + super.setUpBasic(); when(factory.get(MY_CLIENT)).thenReturn(client); @@ -96,19 +92,15 @@ public class BasicHttpOperation<Q> extends BasicOperation { when(client.getBaseUrl()).thenReturn(BASE_URI); - initOperator(); + initConfig(); } /** - * Initializes an operator so that it is "alive" and has the given names. + * Initializes a configuration. */ - protected void initOperator() { - when(operator.isAlive()).thenReturn(true); - when(operator.getFullName()).thenReturn(actorName + "." + operationName); - when(operator.getActorName()).thenReturn(actorName); - when(operator.getName()).thenReturn(operationName); - when(operator.getClient()).thenReturn(client); - when(operator.getPath()).thenReturn(PATH); + protected void initConfig() { + when(config.getClient()).thenReturn(client); + when(config.getPath()).thenReturn(PATH); } /** diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java index dbdd553a9..f027c1c18 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java @@ -86,7 +86,7 @@ public class BasicOperation { /** * Initializes mocks and sets up. */ - public void setUp() throws Exception { + public void setUpBasic() { MockitoAnnotations.initMocks(this); future = new CompletableFuture<>(); |