2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.Matchers.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;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.drools.pooling.message.BucketAssignments;
34 import org.onap.policy.drools.pooling.message.Forward;
35 import org.onap.policy.drools.pooling.message.Heartbeat;
36 import org.onap.policy.drools.pooling.message.Identification;
37 import org.onap.policy.drools.pooling.message.Leader;
38 import org.onap.policy.drools.pooling.message.Message;
39 import org.onap.policy.drools.pooling.message.Offline;
40 import org.onap.policy.drools.pooling.message.Query;
42 public class IdleStateTest extends BasicStateTester {
44 private IdleState state;
50 public void setUp() throws Exception {
53 state = new IdleState(mgr);
57 public void testGetFilter() {
58 Map<String, Object> filter = state.getFilter();
60 FilterUtilsTest utils = new FilterUtilsTest();
62 utils.checkArray(FilterUtils.CLASS_OR, 2, filter);
63 utils.checkEquals(FilterUtils.MSG_CHANNEL, Message.ADMIN, utils.getItem(filter, 0));
64 utils.checkEquals(FilterUtils.MSG_CHANNEL, MY_HOST, utils.getItem(filter, 1));
68 public void testProcessForward() {
69 Forward msg = new Forward();
70 msg.setChannel(MY_HOST);
71 assertNull(state.process(msg));
73 verify(mgr).handle(msg);
77 public void testProcessHeartbeat() {
78 assertNull(state.process(new Heartbeat(PREV_HOST, 0L)));
79 verifyNothingPublished();
83 public void testProcessIdentification() {
84 assertNull(state.process(new Identification(PREV_HOST, null)));
85 verifyNothingPublished();
89 public void testProcessLeader() {
90 BucketAssignments asgn = new BucketAssignments(new String[] {HOST2, PREV_HOST, MY_HOST});
91 Leader msg = new Leader(PREV_HOST, asgn);
93 State next = mock(State.class);
94 when(mgr.goActive()).thenReturn(next);
96 // should stay in current state, but start distributing
97 assertNull(state.process(msg));
98 verify(mgr).startDistributing(asgn);
102 public void testProcessOffline() {
103 assertNull(state.process(new Offline(PREV_HOST)));
104 verifyNothingPublished();
108 public void testProcessQuery() {
109 assertNull(state.process(new Query()));
110 verifyNothingPublished();
114 * Verifies that nothing was published on either channel.
116 private void verifyNothingPublished() {
117 verify(mgr, never()).publish(any(), any());
118 verify(mgr, never()).publishAdmin(any());