Drools support for kafka topics
[policy/drools-pdp.git] / feature-pooling-dmaap / src / test / java / org / onap / policy / drools / pooling / state / IdleStateTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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
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.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;
29
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;
38
39 public class IdleStateTest extends SupportBasicStateTester {
40
41     private IdleState state;
42
43     /**
44      * Setup.
45      */
46     @Before
47     public void setUp() throws Exception {
48         super.setUp();
49
50         state = new IdleState(mgr);
51     }
52
53     @Test
54     public void testProcessHeartbeat() {
55         assertNull(state.process(new Heartbeat(PREV_HOST, 0L)));
56         verifyNothingPublished();
57     }
58
59     @Test
60     public void testProcessIdentification() {
61         assertNull(state.process(new Identification(PREV_HOST, null)));
62         verifyNothingPublished();
63     }
64
65     @Test
66     public void testProcessLeader() {
67         BucketAssignments asgn = new BucketAssignments(new String[] {HOST2, PREV_HOST, MY_HOST});
68         Leader msg = new Leader(PREV_HOST, asgn);
69
70         State next = mock(State.class);
71         when(mgr.goActive()).thenReturn(next);
72
73         // should stay in current state, but start distributing
74         assertNull(state.process(msg));
75         verify(mgr).startDistributing(asgn);
76     }
77
78     @Test
79     public void testProcessOffline() {
80         assertNull(state.process(new Offline(PREV_HOST)));
81         verifyNothingPublished();
82     }
83
84     @Test
85     public void testProcessQuery() {
86         assertNull(state.process(new Query()));
87         verifyNothingPublished();
88     }
89
90     /**
91      * Verifies that nothing was published on either channel.
92      */
93     private void verifyNothingPublished() {
94         verify(mgr, never()).publish(any(), any());
95         verify(mgr, never()).publishAdmin(any());
96     }
97 }