Update policy committers in policy/models
[policy/models.git] / models-interactions / model-actors / actor.xacml / src / test / java / org / onap / policy / controlloop / actor / xacml / DecisionConfigTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2024 Nordix Foundation
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.xacml;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertSame;
27 import static org.junit.jupiter.api.Assertions.assertTrue;
28 import static org.mockito.Mockito.when;
29
30 import java.util.concurrent.Executor;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.junit.jupiter.api.extension.ExtendWith;
34 import org.mockito.Mock;
35 import org.mockito.junit.jupiter.MockitoExtension;
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.models.decisions.concepts.DecisionRequest;
39
40 @ExtendWith(MockitoExtension.class)
41  class DecisionConfigTest {
42     private static final String MY_CLIENT = "my-client";
43     private static final String PATH = "my-path";
44     private static final int TIMEOUT = 10;
45     private static final String ONAP_NAME = "onap-nap";
46     private static final String ONAP_COMP = "onap-component";
47     private static final String ONAP_INST = "onap-instance";
48     private static final String MY_ACTION = "my-action";
49
50     @Mock
51     private HttpClient client;
52     @Mock
53     private HttpClientFactory factory;
54     @Mock
55     private Executor executor;
56
57     private DecisionParams params;
58     private DecisionConfig config;
59
60     /**
61      * Sets up.
62      */
63     @BeforeEach
64      void setUp() {
65         when(factory.get(MY_CLIENT)).thenReturn(client);
66
67         params = DecisionParams.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 DecisionConfig(executor, params, factory);
70     }
71
72     @Test
73      void test() {
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);
79
80         DecisionRequest actual = config.makeRequest();
81         assertEquals(expected, actual);
82
83         // check value from superclass
84         assertSame(executor, config.getBlockingExecutor());
85         assertSame(client, config.getClient());
86
87         // repeat, with minimal parameters
88         params = DecisionParams.builder().clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
89         config = new DecisionConfig(executor, params, factory);
90         assertFalse(config.isDisabled());
91
92         actual = config.makeRequest();
93         assertEquals(new DecisionRequest(), actual);
94
95         // try with disabled=true
96         params = params.toBuilder().disabled(true).build();
97         config = new DecisionConfig(executor, params, factory);
98         assertTrue(config.isDisabled());
99     }
100 }