2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.test;
23 import static org.mockito.Mockito.when;
25 import java.util.function.BiConsumer;
26 import org.mockito.ArgumentCaptor;
27 import org.mockito.Captor;
28 import org.mockito.Mock;
29 import org.onap.policy.common.utils.coder.CoderException;
30 import org.onap.policy.common.utils.coder.StandardCoderObject;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
32 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
33 import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
36 * Superclass for various BidirectionalTopicOperation tests.
38 public class BasicBidirectionalTopicOperation extends BasicOperation {
39 protected static final String MY_SINK = "my-sink";
40 protected static final String MY_SOURCE = "my-source";
41 protected static final int TIMEOUT_SEC = 10;
42 protected static final long TIMEOUT_MS = 1000L * TIMEOUT_SEC;
45 protected ArgumentCaptor<BiConsumer<String, StandardCoderObject>> listenerCaptor;
48 protected BidirectionalTopicHandler topicHandler;
50 protected Forwarder forwarder;
52 protected BidirectionalTopicConfig config;
55 * Constructs the object using a default actor and operation name.
57 public BasicBidirectionalTopicOperation() {
62 * Constructs the object.
64 * @param actor actor name
65 * @param operation operation name
67 public BasicBidirectionalTopicOperation(String actor, String operation) {
68 super(actor, operation);
72 * Initializes mocks and sets up.
75 public void setUpBasic() {
81 * Initializes a configuration.
83 protected void initConfig() {
84 when(config.getTopicHandler()).thenReturn(topicHandler);
85 when(config.getForwarder()).thenReturn(forwarder);
86 when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS);
90 * Provides a response to the topic {@link #listenerCaptor}.
92 * @param listener listener to which to provide the response
93 * @param response response to be provided
95 protected void provideResponse(BiConsumer<String, StandardCoderObject> listener, String response) {
97 StandardCoderObject sco = coder.decode(response, StandardCoderObject.class);
98 listener.accept(response, sco);
100 } catch (CoderException e) {
101 throw new IllegalArgumentException("response is not a Map", e);