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 actor;
47 actor = new HttpActor(ACTOR);
51 public void testMakeOperatorParameters() {
52 HttpActorParams params = new HttpActorParams();
53 params.setClientName(CLIENT);
54 params.setTimeoutSec(TIMEOUT);
55 params.setPath(Map.of("operA", "urlA", "operB", "urlB"));
57 final HttpActor prov = new HttpActor(ACTOR);
58 Function<String, Map<String, Object>> maker =
59 prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params));
61 assertNull(maker.apply(UNKNOWN));
63 // use a TreeMap to ensure the properties are sorted
64 assertEquals("{clientName=my-client, path=urlA, timeoutSec=10}",
65 new TreeMap<>(maker.apply("operA")).toString());
67 assertEquals("{clientName=my-client, path=urlB, timeoutSec=10}",
68 new TreeMap<>(maker.apply("operB")).toString());
70 // with invalid actor parameters
71 params.setClientName(null);
72 assertThatThrownBy(() -> prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)))
73 .isInstanceOf(ParameterValidationRuntimeException.class);
77 public void testHttpActor() {
78 assertEquals(ACTOR, actor.getName());
79 assertEquals(ACTOR, actor.getFullName());