ff9a38a81b875afd4799a1cf23193c6a8794d83c
[policy/drools-applications.git] / controlloop / common / controller-usecases / src / test / java / org / onap / policy / drools / apps / controller / usecases / step / GetTargetEntityStep2Test.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 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.apps.controller.usecases.step;
22
23 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertSame;
27 import static org.junit.Assert.assertTrue;
28 import static org.mockito.Mockito.when;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.policy.controlloop.VirtualControlLoopEvent;
36 import org.onap.policy.controlloop.actorserviceprovider.Operation;
37 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
38 import org.onap.policy.controlloop.eventmanager.StepContext;
39 import org.onap.policy.drools.apps.controller.usecases.GetTargetEntityOperation2;
40 import org.onap.policy.drools.apps.controller.usecases.UsecasesConstants;
41
42 @RunWith(MockitoJUnitRunner.class)
43 public class GetTargetEntityStep2Test {
44     @Mock
45     private ControlLoopOperationParams params;
46     @Mock
47     private StepContext stepContext;
48     @Mock
49     private VirtualControlLoopEvent event;
50
51     private Step2 master;
52     private GetTargetEntityStep2 step;
53
54     /**
55      * Sets up.
56      */
57     @Before
58     public void setUp() {
59         when(params.toBuilder()).thenReturn(ControlLoopOperationParams.builder());
60
61         master = new Step2(stepContext, params, event);
62         step = new GetTargetEntityStep2(master);
63     }
64
65     @Test
66     public void testConstructor() {
67         assertEquals(UsecasesConstants.GET_TARGET_ENTITY_ACTOR, step.getActorName());
68         assertEquals(UsecasesConstants.GET_TARGET_ENTITY_OPERATION, step.getOperationName());
69         assertSame(stepContext, step.stepContext);
70         assertSame(event, step.event);
71     }
72
73     @Test
74     public void testBuildOperation() {
75         Operation oper = step.buildOperation();
76         assertTrue(oper instanceof GetTargetEntityOperation2);
77     }
78
79     @Test
80     public void testStart() {
81         assertThatIllegalStateException().isThrownBy(() -> step.start(200))
82                         .withMessage("step has not been initialized");
83
84         step.init();
85         assertFalse(step.start(100));
86     }
87 }