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.actorserviceprovider.impl;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertSame;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.onap.policy.common.endpoints.http.client.HttpClient;
37 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
38 import org.onap.policy.controlloop.actorserviceprovider.Util;
39 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
40 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
42 public class HttpOperatorTest {
44 private static final String ACTOR = "my-actor";
45 private static final String OPERATION = "my-name";
46 private static final String CLIENT = "my-client";
47 private static final String PATH = "my-path";
48 private static final long TIMEOUT = 100;
51 private HttpClient client;
53 private HttpOperator oper;
56 * Initializes fields, including {@link #oper}.
60 MockitoAnnotations.initMocks(this);
62 oper = new HttpOperator(ACTOR, OPERATION);
66 public void testDoConfigureMapOfStringObject_testGetClient_testGetPath_testGetTimeoutSec() {
67 assertNull(oper.getClient());
68 assertNull(oper.getPath());
69 assertEquals(0L, oper.getTimeoutSec());
71 oper = new HttpOperator(ACTOR, OPERATION) {
73 protected HttpClientFactory getClientFactory() {
74 HttpClientFactory factory = mock(HttpClientFactory.class);
75 when(factory.get(CLIENT)).thenReturn(client);
80 HttpParams params = HttpParams.builder().clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
81 Map<String, Object> paramMap = Util.translateToMap(OPERATION, params);
82 oper.configure(paramMap);
84 assertSame(client, oper.getClient());
85 assertEquals(PATH, oper.getPath());
86 assertEquals(TIMEOUT, oper.getTimeoutSec());
88 // test invalid parameters
89 paramMap.remove("path");
90 assertThatThrownBy(() -> oper.configure(paramMap)).isInstanceOf(ParameterValidationRuntimeException.class);
94 public void testHttpOperator() {
95 assertEquals(ACTOR, oper.getActorName());
96 assertEquals(OPERATION, oper.getName());
97 assertEquals(ACTOR + "." + OPERATION, oper.getFullName());
101 public void testGetClient() {
102 assertNotNull(oper.getClientFactory());