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");
85 CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
86 assertFalse(future2.isDone());
87 //assertSame(outcome, future2.get()); TODO Hanging
88 assertEquals(PolicyResult.SUCCESS, outcome.getResult());
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());
96 response.getResponseDescriptor().setStatus("eRRor");
97 future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
98 assertTrue(future2.isDone());
99 assertSame(outcome, future2.get());
100 assertEquals(PolicyResult.FAILURE, outcome.getResult());
103 /*response.getResponseDescriptor().setStatus("anything but finished");
104 future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
105 assertTrue(future2.isDone());
106 assertSame(outcome, future2.get());
107 assertEquals(PolicyResult.FAILURE, outcome.getResult());*/
111 public void testGetRequestState() {
112 VfcResponse mockResponse = Mockito.mock(VfcResponse.class);
113 Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(null);
114 assertNull(oper.getRequestState(mockResponse));
116 VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
117 Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
118 Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE"); // TODO use actual request state value
119 assertNotNull(oper.getRequestState(mockResponse));
123 public void testIsSuccess() {
124 assertTrue(oper.isSuccess(rawResponse, response));