Close old UEB/DMaaP consumer
[policy/drools-pdp.git] / feature-pooling-dmaap / src / test / java / org / onap / policy / drools / pooling / state / InactiveStateTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.drools.pooling.state;
22
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;
27 import java.util.Map;
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;
32
33 public class InactiveStateTest extends BasicStateTester {
34
35     private InactiveState state;
36
37     @Before
38     public void setUp() throws Exception {
39         super.setUp();
40
41         state = new InactiveState(mgr);
42     }
43
44     @Test
45     public void testGetFilter() {
46         Map<String, Object> filter = state.getFilter();
47
48         FilterUtilsTest utils = new FilterUtilsTest();
49
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));
53     }
54
55     @Test
56     public void testGoInatcive() {
57         assertNull(state.goInactive());
58     }
59
60     @Test
61     public void testStart() {
62         state.start();
63
64         Pair<Long, StateTimerTask> timer = onceTasks.remove();
65
66         assertEquals(STD_REACTIVATE_WAIT_MS, timer.first().longValue());
67
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);
71
72         assertEquals(next, timer.second().fire());
73     }
74
75     @Test
76     public void testInactiveState() {
77         /*
78          * Prove the state is attached to the manager by invoking getHost(), which
79          * delegates to the manager.
80          */
81         assertEquals(MY_HOST, state.getHost());
82     }
83
84 }