Moving common polling code into HttpOperation
[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 testStartPreprocessorAsync() {
62         assertNotNull(oper.startPreprocessorAsync());
63     }
64
65     @Test
66     public void testResetPollCount() {
67         oper.resetPollCount();
68         assertEquals(0, oper.getPollCount());
69     }
70
71     @Test
72     public void testGetRequestState() {
73         VfcResponse mockResponse = Mockito.mock(VfcResponse.class);
74         Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(null);
75         assertNull(oper.getRequestState(mockResponse));
76
77         VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
78         Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
79
80         // TODO use actual request state value
81         Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
82         assertNotNull(oper.getRequestState(mockResponse));
83     }
84
85     @Test
86     public void testIsSuccess() {
87         assertTrue(oper.isSuccess(rawResponse, response));
88     }
89
90 }