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.actorserviceprovider.parameters;
 
  23 import static org.junit.Assert.assertEquals;
 
  24 import static org.junit.Assert.assertSame;
 
  25 import static org.mockito.Mockito.when;
 
  27 import java.util.Arrays;
 
  28 import java.util.List;
 
  29 import java.util.concurrent.Executor;
 
  30 import org.junit.Before;
 
  31 import org.junit.Test;
 
  32 import org.mockito.Mock;
 
  33 import org.mockito.MockitoAnnotations;
 
  34 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
 
  35 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
 
  36 import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
 
  37 import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
 
  39 public class BidirectionalTopicConfigTest {
 
  40     private static final String MY_SINK = "my-sink";
 
  41     private static final String MY_SOURCE = "my-source";
 
  42     private static final int TIMEOUT_SEC = 10;
 
  45     private BidirectionalTopicManager topicManager;
 
  47     private BidirectionalTopicHandler topicHandler;
 
  49     private Forwarder forwarder;
 
  51     private Executor executor;
 
  53     private BidirectionalTopicConfig config;
 
  60         MockitoAnnotations.initMocks(this);
 
  62         List<SelectorKey> keys = Arrays.asList(new SelectorKey(""));
 
  64         when(topicManager.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(topicHandler);
 
  65         when(topicHandler.addForwarder(keys)).thenReturn(forwarder);
 
  67         BidirectionalTopicParams params = BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE)
 
  68                         .timeoutSec(TIMEOUT_SEC).build();
 
  69         config = new BidirectionalTopicConfig(executor, params, topicManager, keys);
 
  74         assertSame(executor, config.getBlockingExecutor());
 
  75         assertSame(topicHandler, config.getTopicHandler());
 
  76         assertSame(forwarder, config.getForwarder());
 
  77         assertEquals(1000L * TIMEOUT_SEC, config.getTimeoutMs());