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.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;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
34 import org.onap.policy.vfc.VfcResponse;
35 import org.onap.policy.vfc.VfcResponseDescriptor;
37 public class VfcOperationTest extends BasicVfcOperation {
39 private VfcOperation oper;
46 public void setUp() throws Exception {
51 oper = new VfcOperation(params, config) {};
55 public void testConstructor() {
56 assertEquals(DEFAULT_ACTOR, oper.getActorName());
57 assertEquals(DEFAULT_OPERATION, oper.getName());
58 assertSame(config, oper.getConfig());
59 assertTrue(oper.isUsePolling());
63 public void testStartPreprocessorAsync() {
64 assertNotNull(oper.startPreprocessorAsync());
68 public void testResetPollCount() {
69 oper.resetPollCount();
70 assertEquals(0, oper.getPollCount());
74 public void testGetRequestState() {
75 VfcResponse mockResponse = Mockito.mock(VfcResponse.class);
76 Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(null);
77 assertNull(oper.getRequestState(mockResponse));
79 VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
80 Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
82 // TODO use actual request state value
83 Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
84 assertNotNull(oper.getRequestState(mockResponse));
88 public void testIsSuccess() {
89 assertTrue(oper.isSuccess(rawResponse, response));
93 public void testGetOptProperty() {
94 // in neither property nor enrichment
95 assertNull(oper.getOptProperty("propA", "propA2"));
97 // both - should choose the property
98 remakeOper(Map.of("propB2", "valueB2"));
99 oper.setProperty("propB", "valueB");
100 assertEquals("valueB", oper.getOptProperty("propB", "propB2"));
102 // both - should choose the property, even if it's null
103 remakeOper(Map.of("propC2", "valueC2"));
104 oper.setProperty("propC", null);
105 assertNull(oper.getOptProperty("propC", "propC2"));
107 // only in enrichment data
108 remakeOper(Map.of("propD2", "valueD2"));
109 assertEquals("valueD2", oper.getOptProperty("propD", "propD2"));
113 * Remakes the operation, with the specified A&AI enrichment data.
115 * @param aai A&AI enrichment data
117 private void remakeOper(Map<String, String> aai) {
119 context = new ControlLoopEventContext(event);
120 params = params.toBuilder().context(context).build();
122 oper = new VfcOperation(params, config) {};