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.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.drools.pooling.message.Message;
31 import org.onap.policy.drools.utils.Pair;
33 public class InactiveStateTest extends BasicStateTester {
35 private InactiveState state;
38 public void setUp() throws Exception {
41 state = new InactiveState(mgr);
45 public void testGetFilter() {
46 Map<String, Object> filter = state.getFilter();
48 FilterUtilsTest utils = new FilterUtilsTest();
50 utils.checkArray(FilterUtils.CLASS_OR, 2, filter);
51 utils.checkEquals(FilterUtils.MSG_CHANNEL, Message.ADMIN, utils.getItem(filter, 0));
52 utils.checkEquals(FilterUtils.MSG_CHANNEL, MY_HOST, utils.getItem(filter, 1));
56 public void testGoInatcive() {
57 assertNull(state.goInactive());
61 public void testStart() {
64 Pair<Long, StateTimerTask> timer = onceTasks.remove();
66 assertEquals(STD_REACTIVATE_WAIT_MS, timer.first().longValue());
68 // invoke the task - it should go to the state returned by the mgr
69 State next = mock(State.class);
70 when(mgr.goStart()).thenReturn(next);
72 assertEquals(next, timer.second().fire());
76 public void testInactiveState() {
78 * Prove the state is attached to the manager by invoking getHost(), which
79 * delegates to the manager.
81 assertEquals(MY_HOST, state.getHost());