2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.actor.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertSame;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.Mockito.when;
30 import jakarta.ws.rs.client.InvocationCallback;
31 import jakarta.ws.rs.core.Response;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.junit.MockitoJUnitRunner;
37 @RunWith(MockitoJUnitRunner.class)
38 public class BasicHttpOperationTest {
39 private static final String ACTOR = "my-actor";
40 private static final String OPERATION = "my-operation";
42 private BasicHttpOperation oper;
46 public void setUp() throws Exception {
47 oper = new BasicHttpOperation(ACTOR, OPERATION);
52 public void testBasicHttpOperation() {
53 oper = new BasicHttpOperation();
54 assertEquals(BasicOperation.DEFAULT_ACTOR, oper.actorName);
55 assertEquals(BasicOperation.DEFAULT_OPERATION, oper.operationName);
59 public void testBasicHttpOperationStringString() {
60 assertEquals(ACTOR, oper.actorName);
61 assertEquals(OPERATION, oper.operationName);
65 public void testSetUp() throws Exception {
66 assertNotNull(oper.client);
67 assertSame(oper.client, oper.factory.get(BasicHttpOperation.MY_CLIENT));
68 assertEquals(200, oper.rawResponse.getStatus());
69 assertNotNull(oper.future);
70 assertEquals(BasicHttpOperation.BASE_URI, oper.client.getBaseUrl());
71 assertNotNull(oper.outcome);
72 assertNotNull(oper.executor);
76 public void testInitOperator() throws Exception {
79 assertSame(oper.client, oper.config.getClient());
80 assertEquals(BasicHttpOperation.PATH, oper.config.getPath());
84 public void testProvideResponse() throws Exception {
85 InvocationCallback<Response> cb = new InvocationCallback<>() {
87 public void completed(Response response) {
92 public void failed(Throwable throwable) {
98 when(oper.client.get(any(), any(), any())).thenAnswer(oper.provideResponse(oper.rawResponse));
100 assertSame(oper.rawResponse, oper.client.get(cb, null, null).get());