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.actor.guard;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertSame;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.when;
29 import java.util.concurrent.Executor;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.policy.common.endpoints.http.client.HttpClient;
35 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
36 import org.onap.policy.controlloop.actorserviceprovider.Util;
37 import org.onap.policy.models.decisions.concepts.DecisionRequest;
39 public class GuardConfigTest {
40 private static final String MY_CLIENT = "my-client";
41 private static final String PATH = "my-path";
42 private static final int TIMEOUT = 10;
43 private static final String ONAP_NAME = "onap-nap";
44 private static final String ONAP_COMP = "onap-component";
45 private static final String ONAP_INST = "onap-instance";
46 private static final String MY_ACTION = "my-action";
49 private HttpClient client;
51 private HttpClientFactory factory;
53 private Executor executor;
55 private GuardParams params;
56 private GuardConfig config;
63 MockitoAnnotations.initMocks(this);
65 when(factory.get(MY_CLIENT)).thenReturn(client);
67 params = GuardParams.builder().onapName(ONAP_NAME).onapComponent(ONAP_COMP).onapInstance(ONAP_INST)
68 .action(MY_ACTION).clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
69 config = new GuardConfig(executor, params, factory);
74 DecisionRequest expected = new DecisionRequest();
75 expected.setOnapComponent(ONAP_COMP);
76 expected.setOnapInstance(ONAP_INST);
77 expected.setOnapName(ONAP_NAME);
78 expected.setAction(MY_ACTION);
80 DecisionRequest actual = Util.translate("", config.makeRequest(), DecisionRequest.class);
81 assertEquals(expected, actual);
83 // check value from superclass
84 assertSame(executor, config.getBlockingExecutor());
85 assertSame(client, config.getClient());
87 // repeat, with minimal parameters
88 params = GuardParams.builder().clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
89 config = new GuardConfig(executor, params, factory);
90 assertFalse(config.isDisabled());
92 actual = Util.translate("", config.makeRequest(), DecisionRequest.class);
93 assertEquals(new DecisionRequest(), actual);
95 // try with disabled=true
96 params = params.toBuilder().disabled(true).build();
97 config = new GuardConfig(executor, params, factory);
98 assertTrue(config.isDisabled());