8f833b700aa4025f14fbe817566a5a9c853d13c7
[policy/models.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2024 Nordix Foundation
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.actorserviceprovider.parameters;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertSame;
26 import static org.mockito.Mockito.when;
27
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.concurrent.Executor;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.junit.jupiter.api.extension.ExtendWith;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.mockito.junit.jupiter.MockitoExtension;
38 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
39 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
40 import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
41 import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
42
43 @ExtendWith(MockitoExtension.class)
44 class BidirectionalTopicConfigTest {
45     private static final String MY_SINK = "my-sink";
46     private static final String MY_SOURCE = "my-source";
47     private static final int TIMEOUT_SEC = 10;
48
49     @Mock
50     private BidirectionalTopicManager topicManager;
51     @Mock
52     private BidirectionalTopicHandler topicHandler;
53     @Mock
54     private Forwarder forwarder;
55     @Mock
56     private Executor executor;
57
58     private BidirectionalTopicConfig config;
59
60     /**
61      * Sets up.
62      */
63     @BeforeEach
64     void setUp() {
65         List<SelectorKey> keys = Arrays.asList(new SelectorKey(""));
66
67         when(topicManager.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(topicHandler);
68         when(topicHandler.addForwarder(keys)).thenReturn(forwarder);
69
70         BidirectionalTopicParams params = BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE)
71                         .timeoutSec(TIMEOUT_SEC).build();
72         config = new BidirectionalTopicConfig(executor, params, topicManager, keys);
73     }
74
75     @Test
76      void test() {
77         assertSame(executor, config.getBlockingExecutor());
78         assertSame(topicHandler, config.getTopicHandler());
79         assertSame(forwarder, config.getForwarder());
80         assertEquals(1000L * TIMEOUT_SEC, config.getTimeoutMs());
81     }
82 }