2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018, 2020 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.drools.pooling.state;
24 import static org.junit.jupiter.api.Assertions.assertNull;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.drools.pooling.message.BucketAssignments;
34 import org.onap.policy.drools.pooling.message.Heartbeat;
35 import org.onap.policy.drools.pooling.message.Identification;
36 import org.onap.policy.drools.pooling.message.Leader;
37 import org.onap.policy.drools.pooling.message.Offline;
38 import org.onap.policy.drools.pooling.message.Query;
40 class IdleStateTest extends SupportBasicStateTester {
42 private IdleState state;
48 public void setUp() throws Exception {
51 state = new IdleState(mgr);
55 void testProcessHeartbeat() {
56 assertNull(state.process(new Heartbeat(PREV_HOST, 0L)));
57 verifyNothingPublished();
61 void testProcessIdentification() {
62 assertNull(state.process(new Identification(PREV_HOST, null)));
63 verifyNothingPublished();
67 void testProcessLeader() {
68 BucketAssignments asgn = new BucketAssignments(new String[] {HOST2, PREV_HOST, MY_HOST});
69 Leader msg = new Leader(PREV_HOST, asgn);
71 State next = mock(State.class);
72 when(mgr.goActive()).thenReturn(next);
74 // should stay in current state, but start distributing
75 assertNull(state.process(msg));
76 verify(mgr).startDistributing(asgn);
80 void testProcessOffline() {
81 assertNull(state.process(new Offline(PREV_HOST)));
82 verifyNothingPublished();
86 void testProcessQuery() {
87 assertNull(state.process(new Query()));
88 verifyNothingPublished();
92 * Verifies that nothing was published on either channel.
94 private void verifyNothingPublished() {
95 verify(mgr, never()).publish(any(), any());
96 verify(mgr, never()).publishAdmin(any());