8ce3b32308a76878f544c74ac0e0d4a651d1a524
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / test / java / org / onap / policy / controlloop / actorserviceprovider / impl / HttpActorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actorserviceprovider.impl;
22
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26
27 import java.util.Map;
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;
35
36 public class HttpActorTest {
37
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;
42
43     private HttpActor actor;
44
45     @Before
46     public void setUp() {
47         actor = new HttpActor(ACTOR);
48     }
49
50     @Test
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"));
56
57         final HttpActor prov = new HttpActor(ACTOR);
58         Function<String, Map<String, Object>> maker =
59                         prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params));
60
61         assertNull(maker.apply(UNKNOWN));
62
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());
66
67         assertEquals("{clientName=my-client, path=urlB, timeoutSec=10}",
68                         new TreeMap<>(maker.apply("operB")).toString());
69
70         // with invalid actor parameters
71         params.setClientName(null);
72         assertThatThrownBy(() -> prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)))
73                         .isInstanceOf(ParameterValidationRuntimeException.class);
74     }
75
76     @Test
77     public void testHttpActor() {
78         assertEquals(ACTOR, actor.getName());
79         assertEquals(ACTOR, actor.getFullName());
80     }
81 }