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.sdnc;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import java.util.Collections;
31 import java.util.TreeMap;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
35 import org.onap.policy.sdnc.SdncHealRequest;
36 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
37 import org.onap.policy.sdnc.SdncRequest;
39 public class SdncOperationTest extends BasicSdncOperation {
41 private static final String MY_URI = "my-uri";
43 private SdncRequest request;
44 private SdncOperation oper;
50 public void setUp() throws Exception {
53 request = new SdncRequest();
54 request.setUrl(MY_URI);
56 SdncHealRequest healRequest = new SdncHealRequest();
57 request.setHealRequest(healRequest);
59 SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
60 healRequest.setRequestHeaderInfo(headerInfo);
61 headerInfo.setSvcRequestId(SUB_REQ_ID);
63 oper = new SdncOperation(params, config, Collections.emptyList()) {
65 protected SdncRequest makeRequest(int attempt) {
72 public void testSdncOperator() {
73 assertEquals(DEFAULT_ACTOR, oper.getActorName());
74 assertEquals(DEFAULT_OPERATION, oper.getName());
78 public void testStartPreprocessorAsync() {
79 assertNotNull(oper.startPreprocessorAsync());
83 public void testStartOperationAsync_testStartRequestAsync() throws Exception {
84 verifyOperation(oper);
88 public void testIsSuccess() {
90 response.getResponseOutput().setResponseCode("200");
91 assertTrue(oper.isSuccess(null, response));
94 response.getResponseOutput().setResponseCode("555");
95 assertFalse(oper.isSuccess(null, response));
98 response.getResponseOutput().setResponseCode(null);
99 assertFalse(oper.isSuccess(null, response));
102 response.setResponseOutput(null);
103 assertFalse(oper.isSuccess(null, response));
107 public void testGetOptProperty() {
108 // in neither property nor enrichment
109 assertNull(oper.getOptProperty("propA", "propA2"));
111 // both - should choose the property
112 remakeOper(Map.of("propB2", "valueB2"));
113 oper.setProperty("propB", "valueB");
114 assertEquals("valueB", oper.getOptProperty("propB", "propB2"));
116 // both - should choose the property, even if it's null
117 remakeOper(Map.of("propC2", "valueC2"));
118 oper.setProperty("propC", null);
119 assertNull(oper.getOptProperty("propC", "propC2"));
121 // only in enrichment data
122 remakeOper(Map.of("propD2", "valueD2"));
123 assertEquals("valueD2", oper.getOptProperty("propD", "propD2"));
127 * Remakes the operation, with the specified A&AI enrichment data.
129 * @param aai A&AI enrichment data
131 private void remakeOper(Map<String, String> aai) {
133 context = new ControlLoopEventContext(event);
134 params = params.toBuilder().context(context).build();
136 oper = new SdncOperation(params, config, Collections.emptyList()) {
138 protected SdncRequest makeRequest(int attempt) {
145 protected Map<String, String> makeEnrichment() {
146 return new TreeMap<>();