Clean up and enhancement of Actor re-design
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / test / java / org / onap / policy / controlloop / actorserviceprovider / CallbackManagerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 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.controlloop.actorserviceprovider;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.time.Instant;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 public class CallbackManagerTest {
34
35     private CallbackManager mgr;
36
37     @Before
38     public void setUp() {
39         mgr = new CallbackManager();
40     }
41
42     @Test
43     public void testCanStart_testGetStartTime() {
44         // null until canXxx() is called
45         assertNull(mgr.getStartTime());
46
47         assertTrue(mgr.canStart());
48
49         Instant time = mgr.getStartTime();
50         assertNotNull(time);
51         assertNull(mgr.getEndTime());
52
53         // false for now on
54         assertFalse(mgr.canStart());
55         assertFalse(mgr.canStart());
56
57         assertEquals(time, mgr.getStartTime());
58     }
59
60     @Test
61     public void testCanEnd_testGetEndTime() {
62         // null until canXxx() is called
63         assertNull(mgr.getEndTime());
64         assertNull(mgr.getEndTime());
65
66         assertTrue(mgr.canEnd());
67
68         Instant time = mgr.getEndTime();
69         assertNotNull(time);
70         assertNull(mgr.getStartTime());
71
72         // false for now on
73         assertFalse(mgr.canEnd());
74         assertFalse(mgr.canEnd());
75
76         assertEquals(time, mgr.getEndTime());
77     }
78
79     @Test
80     public void testRun() {
81         mgr.run();
82
83         assertNotNull(mgr.getStartTime());
84         assertNotNull(mgr.getEndTime());
85
86         assertFalse(mgr.canStart());
87         assertFalse(mgr.canEnd());
88     }
89 }