aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-02-20 09:40:14 -0500
committerJim Hahn <jrh3@att.com>2020-02-20 16:29:08 -0500
commit467247c7970f9ae83464d78929ed970bbf03c593 (patch)
tree54b78e6505b664c3a61e532bf6f7c276307d6591 /models-interactions/model-actors/actorServiceProvider/src/test
parentf6da7772d9dc01ce4ddd21a55b0f1c5fb7ad814f (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/actorServiceProvider/src/test')
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java11
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java26
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java45
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java6
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java98
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java77
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java49
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java79
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java69
9 files changed, 289 insertions, 171 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
index e1606aeaf..4a4354195 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
@@ -61,7 +61,7 @@ public class BidirectionalTopicActorTest {
@Mock
private BidirectionalTopicHandler handler2;
- private BidirectionalTopicActor actor;
+ private BidirectionalTopicActor<BidirectionalTopicActorParams> actor;
/**
@@ -157,7 +157,8 @@ public class BidirectionalTopicActorTest {
public void testMakeOperatorParameters() {
BidirectionalTopicActorParams params = makeParams();
- final BidirectionalTopicActor prov = new BidirectionalTopicActor(ACTOR);
+ final BidirectionalTopicActor<BidirectionalTopicActorParams> prov =
+ new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class);
Function<String, Map<String, Object>> maker =
prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params));
@@ -193,7 +194,7 @@ public class BidirectionalTopicActorTest {
@Test
public void testMakeTopicHandler() {
// use a real actor
- actor = new BidirectionalTopicActor(ACTOR);
+ actor = new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class);
handler1 = actor.getTopicHandler(MY_SINK, MY_SOURCE1);
handler2 = actor.getTopicHandler(MY_SINK, MY_SOURCE2);
@@ -218,10 +219,10 @@ public class BidirectionalTopicActorTest {
return params;
}
- private class MyActor extends BidirectionalTopicActor {
+ private class MyActor extends BidirectionalTopicActor<BidirectionalTopicActorParams> {
public MyActor() {
- super(ACTOR);
+ super(ACTOR, BidirectionalTopicActorParams.class);
}
@Override
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 ceb63fe91..5725a6d61 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
@@ -53,7 +53,7 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.time.PseudoExecutor;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
@@ -65,8 +65,6 @@ public class BidirectionalTopicOperationTest {
private static final String ACTOR = "my-actor";
private static final String OPERATION = "my-operation";
private static final String REQ_ID = "my-request-id";
- private static final String MY_SINK = "my-sink";
- private static final String MY_SOURCE = "my-source";
private static final String TEXT = "some text";
private static final int TIMEOUT_SEC = 10;
private static final long TIMEOUT_MS = 1000 * TIMEOUT_SEC;
@@ -75,7 +73,7 @@ public class BidirectionalTopicOperationTest {
private static final StandardCoder coder = new StandardCoder();
@Mock
- private BidirectionalTopicOperator operator;
+ private BidirectionalTopicConfig config;
@Mock
private BidirectionalTopicHandler handler;
@Mock
@@ -85,7 +83,6 @@ public class BidirectionalTopicOperationTest {
private ArgumentCaptor<BiConsumer<String, StandardCoderObject>> listenerCaptor;
private ControlLoopOperationParams params;
- private BidirectionalTopicParams topicParams;
private OperationOutcome outcome;
private StandardCoderObject stdResponse;
private String responseText;
@@ -100,15 +97,9 @@ public class BidirectionalTopicOperationTest {
public void setUp() throws CoderException {
MockitoAnnotations.initMocks(this);
- topicParams = BidirectionalTopicParams.builder().sourceTopic(MY_SOURCE).sinkTopic(MY_SINK)
- .timeoutSec(TIMEOUT_SEC).build();
-
- when(operator.getActorName()).thenReturn(ACTOR);
- when(operator.getName()).thenReturn(OPERATION);
- when(operator.getTopicHandler()).thenReturn(handler);
- when(operator.getForwarder()).thenReturn(forwarder);
- when(operator.getParams()).thenReturn(topicParams);
- when(operator.isAlive()).thenReturn(true);
+ when(config.getTopicHandler()).thenReturn(handler);
+ when(config.getForwarder()).thenReturn(forwarder);
+ when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS);
when(handler.send(any())).thenReturn(true);
when(handler.getSinkTopicCommInfrastructure()).thenReturn(SINK_INFRA);
@@ -132,7 +123,6 @@ public class BidirectionalTopicOperationTest {
assertEquals(OPERATION, oper.getName());
assertSame(handler, oper.getTopicHandler());
assertSame(forwarder, oper.getForwarder());
- assertSame(topicParams, oper.getTopicParams());
assertEquals(TIMEOUT_MS, oper.getTimeoutMs());
assertSame(MyResponse.class, oper.getResponseClass());
}
@@ -334,7 +324,7 @@ public class BidirectionalTopicOperationTest {
private class MyStringOperation extends BidirectionalTopicOperation<String, String> {
public MyStringOperation() {
- super(BidirectionalTopicOperationTest.this.params, operator, String.class);
+ super(BidirectionalTopicOperationTest.this.params, config, String.class);
}
@Override
@@ -356,7 +346,7 @@ public class BidirectionalTopicOperationTest {
private class MyScoOperation extends BidirectionalTopicOperation<MyRequest, StandardCoderObject> {
public MyScoOperation() {
- super(BidirectionalTopicOperationTest.this.params, operator, StandardCoderObject.class);
+ super(BidirectionalTopicOperationTest.this.params, config, StandardCoderObject.class);
}
@Override
@@ -378,7 +368,7 @@ public class BidirectionalTopicOperationTest {
private class MyOperation extends BidirectionalTopicOperation<MyRequest, MyResponse> {
public MyOperation() {
- super(BidirectionalTopicOperationTest.this.params, operator, MyResponse.class);
+ super(BidirectionalTopicOperationTest.this.params, config, MyResponse.class);
}
@Override
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java
index 4fae782bd..ae923c0bd 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java
@@ -20,20 +20,23 @@
package org.onap.policy.controlloop.actorserviceprovider.impl;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.when;
+import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.BiFunction;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.Util;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
@@ -86,9 +89,7 @@ public class BidirectionalTopicOperatorTest {
public void testConstructor_testGetParams_testGetTopicHandler_testGetForwarder() {
assertEquals(ACTOR, oper.getActorName());
assertEquals(OPERATION, oper.getName());
- assertEquals(params, oper.getParams());
- assertSame(handler, oper.getTopicHandler());
- assertSame(forwarder, oper.getForwarder());
+ assertNotNull(oper.getCurrentConfig());
}
@Test
@@ -102,31 +103,45 @@ public class BidirectionalTopicOperatorTest {
}
@Test
- public void testMakeOperator() {
+ public void testBuildOperator() {
AtomicReference<ControlLoopOperationParams> paramsRef = new AtomicReference<>();
- AtomicReference<BidirectionalTopicOperator> operRef = new AtomicReference<>();
+ AtomicReference<BidirectionalTopicConfig> configRef = new AtomicReference<>();
// @formatter:off
- BiFunction<ControlLoopOperationParams, BidirectionalTopicOperator,
- BidirectionalTopicOperation<String, Integer>> maker =
- (params, operator) -> {
- paramsRef.set(params);
- operRef.set(operator);
- return operation;
- };
+ @SuppressWarnings("rawtypes")
+ OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> maker =
+ (params, config) -> {
+ paramsRef.set(params);
+ configRef.set(config);
+ return operation;
+ };
// @formatter:on
BidirectionalTopicOperator oper2 =
- BidirectionalTopicOperator.makeOperator(ACTOR, OPERATION, mgr, maker, new SelectorKey(""));
+ new BidirectionalTopicOperator(ACTOR, OPERATION, mgr, maker, new SelectorKey(""));
assertEquals(ACTOR, oper2.getActorName());
assertEquals(OPERATION, oper2.getName());
ControlLoopOperationParams params2 = ControlLoopOperationParams.builder().build();
+ // not running yet
+ assertThatIllegalStateException().isThrownBy(() -> oper2.buildOperation(params2));
+
+ // configure and start it
+ params = BidirectionalTopicParams.builder().sourceTopic(MY_SOURCE).sinkTopic(MY_SINK).timeoutSec(TIMEOUT_SEC)
+ .build();
+ oper2.configure(Util.translateToMap(OPERATION, params));
+ oper2.start();
+
assertSame(operation, oper2.buildOperation(params2));
assertSame(params2, paramsRef.get());
- assertSame(oper2, operRef.get());
+ assertSame(oper2.getCurrentConfig(), configRef.get());
+
+ // with no operation-maker
+ BidirectionalTopicOperator oper3 =
+ new BidirectionalTopicOperator(ACTOR, OPERATION, mgr, Arrays.asList(new SelectorKey("")));
+ assertThatThrownBy(() -> oper3.buildOperation(params2)).isInstanceOf(UnsupportedOperationException.class);
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java
index 80b1d427a..dacd3a529 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java
@@ -40,11 +40,11 @@ public class HttpActorTest {
private static final String CLIENT = "my-client";
private static final int TIMEOUT = 10;
- private HttpActor actor;
+ private HttpActor<HttpActorParams> actor;
@Before
public void setUp() {
- actor = new HttpActor(ACTOR);
+ actor = new HttpActor<>(ACTOR, HttpActorParams.class);
}
@Test
@@ -59,7 +59,7 @@ public class HttpActorTest {
"operB", Map.of("path", "urlB")));
// @formatter:on
- final HttpActor prov = new HttpActor(ACTOR);
+ final HttpActor<HttpActorParams> prov = new HttpActor<>(ACTOR, HttpActorParams.class);
Function<String, Map<String, Object>> maker =
prov.makeOperatorParameters(Util.translateToMap(prov.getName(), 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 8189c74fe..2e9f58cbc 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
@@ -29,7 +29,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.spy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.util.Collections;
@@ -39,6 +39,7 @@ import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -67,6 +68,7 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
@@ -76,11 +78,10 @@ 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.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;
import org.onap.policy.controlloop.policy.PolicyResult;
@@ -110,9 +111,12 @@ public class HttpOperationTest {
@Mock
private HttpClient client;
-
+ @Mock
+ private HttpClientFactory clientFactory;
@Mock
private Response response;
+ @Mock
+ private Executor executor;
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
@@ -120,7 +124,7 @@ public class HttpOperationTest {
private OperationOutcome outcome;
private AtomicReference<InvocationCallback<Response>> callback;
private Future<Response> future;
- private HttpOperator operator;
+ private HttpConfig config;
private MyGetOperation<String> oper;
/**
@@ -192,19 +196,9 @@ public class HttpOperationTest {
callback = new AtomicReference<>();
future = new CompletableFuture<>();
- operator = new HttpOperator(ACTOR, OPERATION) {
- @Override
- public Operation buildOperation(ControlLoopOperationParams params) {
- return null;
- }
+ when(clientFactory.get(any())).thenReturn(client);
- @Override
- public HttpClient getClient() {
- return client;
- }
- };
-
- initOper(operator, HTTP_CLIENT);
+ initConfig(HTTP_CLIENT);
oper = new MyGetOperation<>(String.class);
}
@@ -229,7 +223,9 @@ public class HttpOperationTest {
@Test
public void testMakeUrl() {
// use a real client
- client = HttpClientFactoryInstance.getClientFactory().get(HTTP_CLIENT);
+ initRealConfig(HTTP_CLIENT);
+
+ oper = new MyGetOperation<>(String.class);
assertThat(oper.makeUrl()).endsWith("/" + BASE_URI + PATH);
}
@@ -243,19 +239,6 @@ public class HttpOperationTest {
// should use given value
assertEquals(20 * 1000L, oper.getTimeoutMs(20));
-
- // indicate we have a timeout value
- operator = spy(operator);
- when(operator.getTimeoutMs()).thenReturn(30L);
-
- oper = new MyGetOperation<String>(String.class);
-
- // should use default
- assertEquals(30L, oper.getTimeoutMs(null));
- assertEquals(30L, oper.getTimeoutMs(0));
-
- // should use given value
- assertEquals(40 * 1000L, oper.getTimeoutMs(40));
}
/**
@@ -366,7 +349,7 @@ public class HttpOperationTest {
@Test
public void testGet() throws Exception {
// use a real client
- client = HttpClientFactoryInstance.getClientFactory().get(HTTP_CLIENT);
+ initRealConfig(HTTP_CLIENT);
MyGetOperation<MyResponse> oper2 = new MyGetOperation<>(MyResponse.class);
@@ -382,7 +365,7 @@ public class HttpOperationTest {
@Test
public void testDelete() throws Exception {
// use a real client
- client = HttpClientFactoryInstance.getClientFactory().get(HTTP_CLIENT);
+ initRealConfig(HTTP_CLIENT);
MyDeleteOperation oper2 = new MyDeleteOperation();
@@ -398,8 +381,7 @@ public class HttpOperationTest {
@Test
public void testPost() throws Exception {
// use a real client
- client = HttpClientFactoryInstance.getClientFactory().get(HTTP_CLIENT);
-
+ initRealConfig(HTTP_CLIENT);
MyPostOperation oper2 = new MyPostOperation();
OperationOutcome outcome = runOperation(oper2);
@@ -414,7 +396,7 @@ public class HttpOperationTest {
@Test
public void testPut() throws Exception {
// use a real client
- client = HttpClientFactoryInstance.getClientFactory().get(HTTP_CLIENT);
+ initRealConfig(HTTP_CLIENT);
MyPutOperation oper2 = new MyPutOperation();
@@ -454,18 +436,34 @@ public class HttpOperationTest {
}
/**
- * Initializes the given operator.
+ * Initializes the configuration.
*
* @param operator operator to be initialized
* @param clientName name of the client which it should use
*/
- private void initOper(HttpOperator operator, String clientName) {
- operator.stop();
+ private void initConfig(String clientName) {
+ initConfig(clientName, clientFactory);
+ }
+ /**
+ * Initializes the configuration with a real client.
+ *
+ * @param operator operator to be initialized
+ * @param clientName name of the client which it should use
+ */
+ private void initConfig(String clientName, HttpClientFactory factory) {
HttpParams params = HttpParams.builder().clientName(clientName).path(PATH).timeoutSec(1).build();
- Map<String, Object> mapParams = Util.translateToMap(OPERATION, params);
- operator.configure(mapParams);
- operator.start();
+ config = new HttpConfig(executor, params, factory);
+ }
+
+ /**
+ * Initializes the configuration with a real client.
+ *
+ * @param operator operator to be initialized
+ * @param clientName name of the client which it should use
+ */
+ private void initRealConfig(String clientName) {
+ initConfig(clientName, HttpClientFactoryInstance.getClientFactory());
}
/**
@@ -497,7 +495,7 @@ public class HttpOperationTest {
private class MyGetOperation<T> extends HttpOperation<T> {
public MyGetOperation(Class<T> responseClass) {
- super(HttpOperationTest.this.params, HttpOperationTest.this.operator, responseClass);
+ super(HttpOperationTest.this.params, HttpOperationTest.this.config, responseClass);
}
@Override
@@ -511,14 +509,14 @@ public class HttpOperationTest {
// @formatter:off
return handleResponse(outcome, url,
- callback -> operator.getClient().get(callback, makePath(), headers));
+ callback -> getClient().get(callback, makePath(), headers));
// @formatter:on
}
}
private class MyPostOperation extends HttpOperation<MyResponse> {
public MyPostOperation() {
- super(HttpOperationTest.this.params, HttpOperationTest.this.operator, MyResponse.class);
+ super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class);
}
@Override
@@ -537,14 +535,14 @@ public class HttpOperationTest {
// @formatter:off
return handleResponse(outcome, url,
- callback -> operator.getClient().post(callback, makePath(), entity, headers));
+ callback -> getClient().post(callback, makePath(), entity, headers));
// @formatter:on
}
}
private class MyPutOperation extends HttpOperation<MyResponse> {
public MyPutOperation() {
- super(HttpOperationTest.this.params, HttpOperationTest.this.operator, MyResponse.class);
+ super(HttpOperationTest.this.params, HttpOperationTest.this.config, MyResponse.class);
}
@Override
@@ -563,14 +561,14 @@ public class HttpOperationTest {
// @formatter:off
return handleResponse(outcome, url,
- callback -> operator.getClient().put(callback, makePath(), entity, headers));
+ callback -> getClient().put(callback, makePath(), entity, headers));
// @formatter:on
}
}
private class MyDeleteOperation extends HttpOperation<String> {
public MyDeleteOperation() {
- super(HttpOperationTest.this.params, HttpOperationTest.this.operator, String.class);
+ super(HttpOperationTest.this.params, HttpOperationTest.this.config, String.class);
}
@Override
@@ -584,7 +582,7 @@ public class HttpOperationTest {
// @formatter:off
return handleResponse(outcome, url,
- callback -> operator.getClient().delete(callback, makePath(), headers));
+ callback -> getClient().delete(callback, makePath(), headers));
// @formatter:on
}
}
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 081bb346b..873a306c2 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
@@ -20,12 +20,12 @@
package org.onap.policy.controlloop.actorserviceprovider.impl;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.when;
import java.util.Map;
@@ -42,6 +42,7 @@ 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;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
@@ -86,63 +87,65 @@ public class HttpOperatorTest {
}
@Test
- public void testGetClient() {
- assertNotNull(oper.getClient());
+ public void testDoConfigureMapOfStringObject_testGetConfig() {
+ // start with an UNCONFIGURED operator
+ oper.shutdown();
+ oper = new MyOperator();
+
+ assertNull(oper.getCurrentConfig());
+
+ HttpParams params = HttpParams.builder().clientName(HTTP_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
+ Map<String, Object> paramMap = Util.translateToMap(OPERATION, params);
+ oper.configure(paramMap);
+
+ assertNotNull(oper.getCurrentConfig());
+
+ // test invalid parameters
+ paramMap.remove("path");
+ assertThatThrownBy(() -> oper.configure(paramMap)).isInstanceOf(ParameterValidationRuntimeException.class);
}
@Test
- public void testMakeOperator() {
- HttpOperator oper2 = HttpOperator.makeOperator(ACTOR, OPERATION, MyOperation::new);
+ public void testBuildOperation() {
+ HttpOperator oper2 = new MyOperator();
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();
+ // not running yet
+ assertThatIllegalStateException().isThrownBy(() -> oper2.buildOperation(params));
+
+ // configure and start it
+ HttpParams params2 = HttpParams.builder().clientName(HTTP_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
+ Map<String, Object> paramMap = Util.translateToMap(OPERATION, params2);
+ oper2.configure(paramMap);
+ oper2.start();
+
Operation operation1 = oper2.buildOperation(params);
assertNotNull(operation1);
Operation operation2 = oper2.buildOperation(params);
assertNotNull(operation2);
assertNotSame(operation1, operation2);
+
+ // with no operation-maker
+ HttpOperator oper3 = new HttpOperator(ACTOR, OPERATION);
+ assertThatThrownBy(() -> oper3.buildOperation(params)).isInstanceOf(UnsupportedOperationException.class);
}
@Test
- public void testDoConfigureMapOfStringObject_testGetClient_testGetPath_testGetTimeoutMs() {
- // start with an UNCONFIGURED operator
- oper.shutdown();
- oper = new MyOperator();
-
- assertNull(oper.getClient());
- assertNull(oper.getPath());
-
- // no timeout yet
- assertEquals(0L, oper.getTimeoutMs());
-
- HttpParams params = HttpParams.builder().clientName(HTTP_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
- Map<String, Object> paramMap = Util.translateToMap(OPERATION, params);
- oper.configure(paramMap);
-
- assertSame(client, oper.getClient());
- assertEquals(PATH, oper.getPath());
-
- // should use given value
- assertEquals(TIMEOUT * 1000, oper.getTimeoutMs());
-
- // test invalid parameters
- paramMap.remove("path");
- assertThatThrownBy(() -> oper.configure(paramMap)).isInstanceOf(ParameterValidationRuntimeException.class);
+ public void testGetClientFactory() {
+ HttpOperator oper2 = new HttpOperator(ACTOR, OPERATION);
+ assertNotNull(oper2.getClientFactory());
}
private class MyOperator extends HttpOperator {
public MyOperator() {
- super(ACTOR, OPERATION);
- }
-
- @Override
- public Operation buildOperation(ControlLoopOperationParams params) {
- return null;
+ super(ACTOR, OPERATION, MyOperation::new);
}
@Override
@@ -152,8 +155,8 @@ public class HttpOperatorTest {
}
private class MyOperation extends HttpOperation<String> {
- public MyOperation(ControlLoopOperationParams params, HttpOperator operator) {
- super(params, operator, String.class);
+ public MyOperation(ControlLoopOperationParams params, HttpConfig config) {
+ super(params, config, String.class);
}
@Override
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 67ac27c8d..39564a443 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
@@ -21,7 +21,6 @@
package org.onap.policy.controlloop.actorserviceprovider.impl;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -41,7 +40,6 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -70,6 +68,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
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.policy.PolicyResult;
import org.slf4j.LoggerFactory;
@@ -111,7 +110,7 @@ public class OperationPartialTest {
private OperationOutcome opstart;
private OperationOutcome opend;
- private OperatorPartial operator;
+ private OperatorConfig config;
/**
* Attaches the appender to the logger.
@@ -150,20 +149,7 @@ public class OperationPartialTest {
.executor(executor).actor(ACTOR).operation(OPERATION).timeoutSec(TIMEOUT)
.startCallback(this::starter).targetEntity(MY_SINK).build();
- operator = new OperatorPartial(ACTOR, OPERATION) {
- @Override
- public Executor getBlockingExecutor() {
- return executor;
- }
-
- @Override
- public Operation buildOperation(ControlLoopOperationParams params) {
- return null;
- }
- };
-
- operator.configure(null);
- operator.start();
+ config = new OperatorConfig(executor);
oper = new MyOper();
@@ -197,35 +183,12 @@ public class OperationPartialTest {
assertNull(future.get(5, TimeUnit.SECONDS));
}
- /**
- * Exercises the doXxx() methods.
- */
- @Test
- public void testDoXxx() {
- assertThatCode(() -> operator.doConfigure(null)).doesNotThrowAnyException();
- assertThatCode(() -> operator.doStart()).doesNotThrowAnyException();
- assertThatCode(() -> operator.doStop()).doesNotThrowAnyException();
- assertThatCode(() -> operator.doShutdown()).doesNotThrowAnyException();
-
- }
-
@Test
public void testStart() {
verifyRun("testStart", 1, 1, PolicyResult.SUCCESS);
}
/**
- * Tests startOperation() when the operator is not running.
- */
- @Test
- public void testStartNotRunning() {
- // stop the operator
- operator.stop();
-
- assertThatIllegalStateException().isThrownBy(() -> oper.start());
- }
-
- /**
* Tests startOperation() when the operation has a preprocessor.
*/
@Test
@@ -392,7 +355,7 @@ public class OperationPartialTest {
/*
* Use an operation that doesn't override doOperation().
*/
- OperationPartial oper2 = new OperationPartial(params, operator) {};
+ OperationPartial oper2 = new OperationPartial(params, config) {};
oper2.start();
assertTrue(executor.runAll(MAX_REQUESTS));
@@ -1101,7 +1064,7 @@ public class OperationPartialTest {
@Test
public void testGetRetryWait() {
// need an operator that doesn't override the retry time
- OperationPartial oper2 = new OperationPartial(params, operator) {};
+ OperationPartial oper2 = new OperationPartial(params, config) {};
assertEquals(OperationPartial.DEFAULT_RETRY_WAIT_MS, oper2.getRetryWaitMs());
}
@@ -1257,7 +1220,7 @@ public class OperationPartialTest {
public MyOper() {
- super(OperationPartialTest.this.params, operator);
+ super(OperationPartialTest.this.params, config);
}
@Override
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java
new file mode 100644
index 000000000..7c6a98fde
--- /dev/null
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java
@@ -0,0 +1,79 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.Executor;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
+import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
+import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
+import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
+
+public class BidirectionalTopicConfigTest {
+ private static final String MY_SINK = "my-sink";
+ private static final String MY_SOURCE = "my-source";
+ private static final int TIMEOUT_SEC = 10;
+
+ @Mock
+ private BidirectionalTopicManager topicManager;
+ @Mock
+ private BidirectionalTopicHandler topicHandler;
+ @Mock
+ private Forwarder forwarder;
+ @Mock
+ private Executor executor;
+
+ private BidirectionalTopicConfig config;
+
+ /**
+ * Sets up.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ List<SelectorKey> keys = Arrays.asList(new SelectorKey(""));
+
+ when(topicManager.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(topicHandler);
+ when(topicHandler.addForwarder(keys)).thenReturn(forwarder);
+
+ BidirectionalTopicParams params = BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE)
+ .timeoutSec(TIMEOUT_SEC).build();
+ config = new BidirectionalTopicConfig(executor, params, topicManager, keys);
+ }
+
+ @Test
+ public void test() {
+ assertSame(executor, config.getBlockingExecutor());
+ assertSame(topicHandler, config.getTopicHandler());
+ assertSame(forwarder, config.getForwarder());
+ assertEquals(1000L * TIMEOUT_SEC, config.getTimeoutMs());
+ }
+}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java
new file mode 100644
index 000000000..309b30fd5
--- /dev/null
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.when;
+
+import java.util.concurrent.Executor;
+import org.junit.Before;
+import org.junit.Test;
+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;
+
+public class HttpConfigTest {
+ private static final String MY_CLIENT = "my-client";
+ private static final String MY_PATH = "my-path";
+ private static final int TIMEOUT_SEC = 10;
+
+ @Mock
+ private HttpClient client;
+ @Mock
+ private HttpClientFactory factory;
+ @Mock
+ private Executor executor;
+
+ private HttpConfig config;
+
+ /**
+ * Sets up.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ when(factory.get(MY_CLIENT)).thenReturn(client);
+
+ HttpParams params = HttpParams.builder().clientName(MY_CLIENT).path(MY_PATH).timeoutSec(TIMEOUT_SEC).build();
+ config = new HttpConfig(executor, params, factory);
+ }
+
+ @Test
+ public void test() {
+ assertSame(executor, config.getBlockingExecutor());
+ assertSame(client, config.getClient());
+ assertEquals(MY_PATH, config.getPath());
+ assertEquals(1000L * TIMEOUT_SEC, config.getTimeoutMs());
+ }
+}