Removing deprecated DMAAP library
[policy/drools-pdp.git] / feature-pooling-messages / 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  * Modifications Copyright (C) 2024 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.drools.pooling.state;
23
24 import static org.junit.jupiter.api.Assertions.assertNull;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.drools.pooling.message.BucketAssignments;
34 import org.onap.policy.drools.pooling.message.Heartbeat;
35 import org.onap.policy.drools.pooling.message.Identification;
36 import org.onap.policy.drools.pooling.message.Leader;
37 import org.onap.policy.drools.pooling.message.Offline;
38 import org.onap.policy.drools.pooling.message.Query;
39
40 class IdleStateTest extends SupportBasicStateTester {
41
42     private IdleState state;
43
44     /**
45      * Setup.
46      */
47     @BeforeEach
48     public void setUp() throws Exception {
49         super.setUp();
50
51         state = new IdleState(mgr);
52     }
53
54     @Test
55     void testProcessHeartbeat() {
56         assertNull(state.process(new Heartbeat(PREV_HOST, 0L)));
57         verifyNothingPublished();
58     }
59
60     @Test
61     void testProcessIdentification() {
62         assertNull(state.process(new Identification(PREV_HOST, null)));
63         verifyNothingPublished();
64     }
65
66     @Test
67     void testProcessLeader() {
68         BucketAssignments asgn = new BucketAssignments(new String[] {HOST2, PREV_HOST, MY_HOST});
69         Leader msg = new Leader(PREV_HOST, asgn);
70
71         State next = mock(State.class);
72         when(mgr.goActive()).thenReturn(next);
73
74         // should stay in current state, but start distributing
75         assertNull(state.process(msg));
76         verify(mgr).startDistributing(asgn);
77     }
78
79     @Test
80     void testProcessOffline() {
81         assertNull(state.process(new Offline(PREV_HOST)));
82         verifyNothingPublished();
83     }
84
85     @Test
86     void testProcessQuery() {
87         assertNull(state.process(new Query()));
88         verifyNothingPublished();
89     }
90
91     /**
92      * Verifies that nothing was published on either channel.
93      */
94     private void verifyNothingPublished() {
95         verify(mgr, never()).publish(any(), any());
96         verify(mgr, never()).publishAdmin(any());
97     }
98 }