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.aai;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertSame;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
32 import java.util.concurrent.CompletableFuture;
33 import javax.ws.rs.client.Invocation.Builder;
34 import javax.ws.rs.client.WebTarget;
35 import org.junit.AfterClass;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.onap.policy.aai.AaiConstants;
40 import org.onap.policy.common.utils.coder.StandardCoderObject;
41 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
43 public class AaiGetOperationTest extends BasicAaiOperation<Void> {
44 private static final String MY_NAME = "my-operation-name";
45 private static final String PARAM_NAME = "my-param";
46 private static final String PARAM_VALUE = "my-value";
47 private static final String MY_URL = "my-url";
49 private AaiGetOperation oper;
51 public AaiGetOperationTest() {
52 super(AaiConstants.ACTOR_NAME, MY_NAME);
56 public static void setUpBeforeClass() throws Exception {
61 public static void tearDownAfterClass() {
69 public void setUp() throws Exception {
71 oper = new AaiGetOperation(params, config);
75 public void testConstructor() {
76 assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName());
77 assertEquals(MY_NAME, oper.getName());
81 public void testGenerateSubRequestId() {
82 oper.generateSubRequestId(3);
83 assertEquals("3", oper.getSubRequestId());
87 public void testAddQuery() {
88 WebTarget web = mock(WebTarget.class);
89 when(web.queryParam(any(), any())).thenReturn(web);
91 StringBuilder bldr = new StringBuilder();
93 assertSame(web, oper.addQuery(web, bldr, ",", PARAM_NAME, PARAM_VALUE));
94 assertEquals(",my-param=my-value", bldr.toString());
98 public void testAddHeaders() {
99 Builder bldr = mock(Builder.class);
100 oper.addHeaders(bldr, Map.of("hdrA", "valA", "hdrB", "valB"));
102 verify(bldr, times(2)).header(any(), any());
103 verify(bldr).header("hdrA", "valA");
104 verify(bldr).header("hdrB", "valB");
108 public void testPostProcessResponse() throws Exception {
109 StandardCoderObject resp = new StandardCoderObject();
110 CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, MY_URL, null, resp);
112 assertSame(outcome, future2.get());
113 assertSame(resp, context.getProperty("AAI.my-operation-name.my-target"));
117 public void testGetRetry() {
118 // use default if null retry
119 assertEquals(AaiGetOperation.DEFAULT_RETRY, oper.getRetry(null));
121 // otherwise, use specified value
122 assertEquals(0, oper.getRetry(0));
123 assertEquals(10, oper.getRetry(10));
127 public void testMakeHeaders() {
128 verifyHeaders(oper.makeHeaders());