* ONAP
* ================================================================================
* Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.drools.pooling.state;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.drools.pooling.CancellableScheduledTask;
import org.onap.policy.drools.pooling.PoolingManager;
import org.onap.policy.drools.pooling.message.BucketAssignments;
import org.onap.policy.drools.pooling.message.Offline;
import org.onap.policy.drools.pooling.message.Query;
-public class StateTest extends SupportBasicStateTester {
+class StateTest extends SupportBasicStateTester {
private State state;
/**
* Setup.
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
}
@Test
- public void testStatePoolingManager() {
+ void testStatePoolingManager() {
/*
* Prove the state is attached to the manager by invoking getHost(), which
* delegates to the manager.
}
@Test
- public void testStateState() {
+ void testStateState() {
// allocate a new state, copying from the old state
state = new MyState(mgr);
}
@Test
- public void testCancelTimers() {
+ void testCancelTimers() {
int delay = 100;
int initDelay = 200;
}
@Test
- public void testStart() {
+ void testStart() {
assertThatCode(() -> state.start()).doesNotThrowAnyException();
}
@Test
- public void testGoStart() {
+ void testGoStart() {
State next = mock(State.class);
when(mgr.goStart()).thenReturn(next);
}
@Test
- public void testGoQuery() {
+ void testGoQuery() {
State next = mock(State.class);
when(mgr.goQuery()).thenReturn(next);
}
@Test
- public void testGoActive_WithAssignment() {
+ void testGoActive_WithAssignment() {
State act = mock(State.class);
State inact = mock(State.class);
}
@Test
- public void testGoActive_WithoutAssignment() {
+ void testGoActive_WithoutAssignment() {
State act = mock(State.class);
State inact = mock(State.class);
}
@Test
- public void testGoActive_NullAssignment() {
+ void testGoActive_NullAssignment() {
State act = mock(State.class);
State inact = mock(State.class);
}
@Test
- public void testGoInactive() {
+ void testGoInactive() {
State next = mock(State.class);
when(mgr.goInactive()).thenReturn(next);
}
@Test
- public void testProcessHeartbeat() {
+ void testProcessHeartbeat() {
assertNull(state.process(new Heartbeat()));
}
@Test
- public void testProcessIdentification() {
+ void testProcessIdentification() {
assertNull(state.process(new Identification()));
}
@Test
- public void testProcessLeader() {
+ void testProcessLeader() {
String[] arr = {HOST2, HOST1};
BucketAssignments asgn = new BucketAssignments(arr);
Leader msg = new Leader(HOST1, asgn);
// should ignore it
- assertEquals(null, state.process(msg));
+ assertNull(state.process(msg));
verify(mgr).startDistributing(asgn);
}
@Test
- public void testProcessLeader_Invalid() {
+ void testProcessLeader_Invalid() {
Leader msg = new Leader(PREV_HOST, null);
// should stay in the same state, and not start distributing
}
@Test
- public void testIsValidLeader_NullAssignment() {
+ void testIsValidLeader_NullAssignment() {
assertFalse(state.isValid(new Leader(PREV_HOST, null)));
}
@Test
- public void testIsValidLeader_NullSource() {
+ void testIsValidLeader_NullSource() {
String[] arr = {HOST2, PREV_HOST, MY_HOST};
BucketAssignments asgn = new BucketAssignments(arr);
assertFalse(state.isValid(new Leader(null, asgn)));
}
@Test
- public void testIsValidLeader_EmptyAssignment() {
+ void testIsValidLeader_EmptyAssignment() {
assertFalse(state.isValid(new Leader(PREV_HOST, new BucketAssignments())));
}
@Test
- public void testIsValidLeader_FromSelf() {
+ void testIsValidLeader_FromSelf() {
String[] arr = {HOST2, MY_HOST};
BucketAssignments asgn = new BucketAssignments(arr);
}
@Test
- public void testIsValidLeader_WrongLeader() {
+ void testIsValidLeader_WrongLeader() {
String[] arr = {HOST2, HOST3};
BucketAssignments asgn = new BucketAssignments(arr);
}
@Test
- public void testIsValidLeader() {
+ void testIsValidLeader() {
String[] arr = {HOST2, HOST1};
BucketAssignments asgn = new BucketAssignments(arr);
}
@Test
- public void testProcessOffline() {
+ void testProcessOffline() {
assertNull(state.process(new Offline()));
}
@Test
- public void testProcessQuery() {
+ void testProcessQuery() {
assertNull(state.process(new Query()));
}
@Test
- public void testPublishIdentification() {
+ void testPublishIdentification() {
Identification msg = new Identification();
state.publish(msg);
}
@Test
- public void testPublishLeader() {
+ void testPublishLeader() {
Leader msg = new Leader();
state.publish(msg);
}
@Test
- public void testPublishOffline() {
+ void testPublishOffline() {
Offline msg = new Offline();
state.publish(msg);
}
@Test
- public void testPublishQuery() {
+ void testPublishQuery() {
Query msg = new Query();
state.publish(msg);
}
@Test
- public void testPublishStringHeartbeat() {
+ void testPublishStringHeartbeat() {
String chnl = "channelH";
Heartbeat msg = new Heartbeat();
}
@Test
- public void testStartDistributing() {
+ void testStartDistributing() {
BucketAssignments asgn = new BucketAssignments();
state.startDistributing(asgn);
}
@Test
- public void testStartDistributing_NullAssignments() {
+ void testStartDistributing_NullAssignments() {
state.startDistributing(null);
verify(mgr, never()).startDistributing(any());
}
@Test
- public void testSchedule() {
+ void testSchedule() {
int delay = 100;
StateTimerTask task = mock(StateTimerTask.class);
}
@Test
- public void testScheduleWithFixedDelay() {
+ void testScheduleWithFixedDelay() {
int initdel = 100;
int delay = 200;
}
@Test
- public void testMissedHeartbeat() {
+ void testMissedHeartbeat() {
State next = mock(State.class);
when(mgr.goStart()).thenReturn(next);
}
@Test
- public void testInternalTopicFailed() {
+ void testInternalTopicFailed() {
State next = mock(State.class);
when(mgr.goInactive()).thenReturn(next);
}
@Test
- public void testMakeHeartbeat() {
+ void testMakeHeartbeat() {
long timestamp = 30000L;
Heartbeat msg = state.makeHeartbeat(timestamp);
}
@Test
- public void testMakeIdentification() {
+ void testMakeIdentification() {
Identification ident = state.makeIdentification();
assertEquals(MY_HOST, ident.getSource());
assertEquals(ASGN3, ident.getAssignments());
}
@Test
- public void testMakeOffline() {
+ void testMakeOffline() {
Offline msg = state.makeOffline();
assertEquals(MY_HOST, msg.getSource());
}
@Test
- public void testMakeQuery() {
+ void testMakeQuery() {
Query msg = state.makeQuery();
assertEquals(MY_HOST, msg.getSource());
}
@Test
- public void testGetHost() {
+ void testGetHost() {
assertEquals(MY_HOST, state.getHost());
}
@Test
- public void testGetTopic() {
+ void testGetTopic() {
assertEquals(MY_TOPIC, state.getTopic());
}
/**
* State used for testing purposes, with abstract methods implemented.
*/
- private class MyState extends State {
+ private static class MyState extends State {
public MyState(PoolingManager mgr) {
super(mgr);