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.assertNull;
28 import java.util.TreeMap;
29 import java.util.function.Function;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.controlloop.actorserviceprovider.Util;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams;
34 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
36 public class HttpActorTest {
38 private static final String ACTOR = "my-actor";
39 private static final String UNKNOWN = "unknown";
40 private static final String CLIENT = "my-client";
41 private static final int TIMEOUT = 10;
43 private HttpActor<HttpActorParams> actor;
47 actor = new HttpActor<>(ACTOR, HttpActorParams.class);
51 public void testMakeOperatorParameters() {
52 HttpActorParams params = new HttpActorParams();
53 params.setClientName(CLIENT);
54 params.setTimeoutSec(TIMEOUT);
57 params.setOperations(Map.of(
58 "operA", Map.of("path", "urlA"),
59 "operB", Map.of("path", "urlB")));
62 final HttpActor<HttpActorParams> prov = new HttpActor<>(ACTOR, HttpActorParams.class);
63 Function<String, Map<String, Object>> maker =
64 prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params));
66 assertNull(maker.apply(UNKNOWN));
68 // use a TreeMap to ensure the properties are sorted
69 assertEquals("{clientName=my-client, path=urlA, timeoutSec=10}",
70 new TreeMap<>(maker.apply("operA")).toString());
72 assertEquals("{clientName=my-client, path=urlB, timeoutSec=10}",
73 new TreeMap<>(maker.apply("operB")).toString());
75 // with invalid actor parameters
76 params.setOperations(null);
77 assertThatThrownBy(() -> prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)))
78 .isInstanceOf(ParameterValidationRuntimeException.class);
82 public void testHttpActor() {
83 assertEquals(ACTOR, actor.getName());
84 assertEquals(ACTOR, actor.getFullName());