2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.actor.vfc;
23 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertSame;
29 import static org.junit.Assert.assertTrue;
31 import java.util.concurrent.CompletableFuture;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
36 import org.onap.policy.controlloop.policy.PolicyResult;
37 import org.onap.policy.vfc.VfcResponse;
38 import org.onap.policy.vfc.VfcResponseDescriptor;
40 public class VfcOperationTest extends BasicVfcOperation {
42 private VfcOperation oper;
49 public void setUp() throws Exception {
54 oper = new VfcOperation(params, config) {};
58 public void testConstructor_testGetWaitMsGet() {
59 assertEquals(DEFAULT_ACTOR, oper.getActorName());
60 assertEquals(DEFAULT_OPERATION, oper.getName());
61 assertSame(config, oper.getConfig());
62 assertEquals(1000 * WAIT_SEC_GETS, oper.getWaitMsGet());
66 public void testStartPreprocessorAsync() {
67 assertNotNull(oper.startPreprocessorAsync());
71 public void testResetGetCount() {
73 assertEquals(0, oper.getGetCount());
77 public void testPostProcess() throws Exception {
79 assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
80 oper.postProcessResponse(outcome, PATH, rawResponse, response);
83 response.setResponseDescriptor(new VfcResponseDescriptor());
84 response.setJobId("sampleJobId");
87 CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
88 assertFalse(future2.isDone());
90 response.getResponseDescriptor().setStatus("FinisHeD");
91 future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
92 assertTrue(future2.isDone());
93 assertSame(outcome, future2.get());
94 assertEquals(PolicyResult.SUCCESS, outcome.getResult());
95 assertSame(response, outcome.getResponse());
98 response.getResponseDescriptor().setStatus("eRRor");
99 future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
100 assertTrue(future2.isDone());
101 assertSame(outcome, future2.get());
102 assertEquals(PolicyResult.FAILURE, outcome.getResult());
103 assertSame(response, outcome.getResponse());
106 response.getResponseDescriptor().setStatus("anything but finished");
107 future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
108 assertFalse(future2.isDone());
112 public void testGetRequestState() {
113 VfcResponse mockResponse = Mockito.mock(VfcResponse.class);
114 Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(null);
115 assertNull(oper.getRequestState(mockResponse));
117 VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
118 Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
120 // TODO use actual request state value
121 Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
122 assertNotNull(oper.getRequestState(mockResponse));
126 public void testIsSuccess() {
127 assertTrue(oper.isSuccess(rawResponse, response));