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 javax.ws.rs.client.Invocation.Builder;
33 import javax.ws.rs.client.WebTarget;
34 import org.junit.AfterClass;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.onap.policy.aai.AaiConstants;
40 public class AaiGetOperationTest extends BasicAaiOperation {
41 private static final String MY_NAME = "my-operation-name";
42 private static final String PARAM_NAME = "my-param";
43 private static final String PARAM_VALUE = "my-value";
45 private AaiGetOperation oper;
47 public AaiGetOperationTest() {
48 super(AaiConstants.ACTOR_NAME, MY_NAME);
52 public static void setUpBeforeClass() throws Exception {
57 public static void tearDownAfterClass() {
65 public void setUp() throws Exception {
67 oper = new AaiGetOperation(params, config);
71 public void testConstructor() {
72 assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName());
73 assertEquals(MY_NAME, oper.getName());
77 public void testGenerateSubRequestId() {
78 oper.generateSubRequestId(3);
79 assertEquals("3", oper.getSubRequestId());
83 public void testAddQuery() {
84 WebTarget web = mock(WebTarget.class);
85 when(web.queryParam(any(), any())).thenReturn(web);
87 StringBuilder bldr = new StringBuilder();
89 assertSame(web, oper.addQuery(web, bldr, ",", PARAM_NAME, PARAM_VALUE));
90 assertEquals(",my-param=my-value", bldr.toString());
94 public void testAddHeaders() {
95 Builder bldr = mock(Builder.class);
96 oper.addHeaders(bldr, Map.of("hdrA", "valA", "hdrB", "valB"));
98 verify(bldr, times(2)).header(any(), any());
99 verify(bldr).header("hdrA", "valA");
100 verify(bldr).header("hdrB", "valB");
104 public void testGetRetry() {
105 // use default if null retry
106 assertEquals(AaiGetOperation.DEFAULT_RETRY, oper.getRetry(null));
108 // otherwise, use specified value
109 assertEquals(0, oper.getRetry(0));
110 assertEquals(10, oper.getRetry(10));
114 public void testMakeHeaders() {
115 verifyHeaders(oper.makeHeaders());