4f20c12d4f4109ee963e1035414f7233e9e28140
[policy/models.git] / models-interactions / model-actors / actor.vfc / src / test / java / org / onap / policy / controlloop / actor / vfc / VfcOperationTest.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.actor.vfc;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertSame;
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.onap.policy.vfc.VfcResponse;
33 import org.onap.policy.vfc.VfcResponseDescriptor;
34
35 public class VfcOperationTest extends BasicVfcOperation {
36
37     private VfcOperation oper;
38
39     /**
40      * setUp.
41      */
42     @Before
43     @Override
44     public void setUp() throws Exception {
45         super.setUp();
46
47         initConfig();
48
49         oper = new VfcOperation(params, config) {};
50     }
51
52     @Test
53     public void testConstructor() {
54         assertEquals(DEFAULT_ACTOR, oper.getActorName());
55         assertEquals(DEFAULT_OPERATION, oper.getName());
56         assertSame(config, oper.getConfig());
57         assertTrue(oper.isUsePolling());
58     }
59
60     @Test
61     public void testResetPollCount() {
62         oper.resetPollCount();
63         assertEquals(0, oper.getPollCount());
64     }
65
66     @Test
67     public void testGetRequestState() {
68         VfcResponse mockResponse = Mockito.mock(VfcResponse.class);
69         Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(null);
70         assertNull(oper.getRequestState(mockResponse));
71
72         VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
73         Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
74
75         // TODO use actual request state value
76         Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
77         assertNotNull(oper.getRequestState(mockResponse));
78     }
79
80     @Test
81     public void testIsSuccess() {
82         assertTrue(oper.isSuccess(rawResponse, response));
83     }
84 }