2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018, 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.drools.pooling.state;
23 import static org.junit.Assert.assertNull;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.never;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.drools.pooling.message.BucketAssignments;
33 import org.onap.policy.drools.pooling.message.Heartbeat;
34 import org.onap.policy.drools.pooling.message.Identification;
35 import org.onap.policy.drools.pooling.message.Leader;
36 import org.onap.policy.drools.pooling.message.Offline;
37 import org.onap.policy.drools.pooling.message.Query;
39 public class IdleStateTest extends SupportBasicStateTester {
41 private IdleState state;
47 public void setUp() throws Exception {
50 state = new IdleState(mgr);
54 public void testProcessHeartbeat() {
55 assertNull(state.process(new Heartbeat(PREV_HOST, 0L)));
56 verifyNothingPublished();
60 public void testProcessIdentification() {
61 assertNull(state.process(new Identification(PREV_HOST, null)));
62 verifyNothingPublished();
66 public void testProcessLeader() {
67 BucketAssignments asgn = new BucketAssignments(new String[] {HOST2, PREV_HOST, MY_HOST});
68 Leader msg = new Leader(PREV_HOST, asgn);
70 State next = mock(State.class);
71 when(mgr.goActive()).thenReturn(next);
73 // should stay in current state, but start distributing
74 assertNull(state.process(msg));
75 verify(mgr).startDistributing(asgn);
79 public void testProcessOffline() {
80 assertNull(state.process(new Offline(PREV_HOST)));
81 verifyNothingPublished();
85 public void testProcessQuery() {
86 assertNull(state.process(new Query()));
87 verifyNothingPublished();
91 * Verifies that nothing was published on either channel.
93 private void verifyNothingPublished() {
94 verify(mgr, never()).publish(any(), any());
95 verify(mgr, never()).publishAdmin(any());