Remove unused imports in 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  * ================================================================================
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.actor.xacml;
22
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;
28
29 import java.util.concurrent.Executor;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.policy.common.endpoints.http.client.HttpClient;
36 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
37 import org.onap.policy.models.decisions.concepts.DecisionRequest;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class DecisionConfigTest {
41     private static final String MY_CLIENT = "my-client";
42     private static final String PATH = "my-path";
43     private static final int TIMEOUT = 10;
44     private static final String ONAP_NAME = "onap-nap";
45     private static final String ONAP_COMP = "onap-component";
46     private static final String ONAP_INST = "onap-instance";
47     private static final String MY_ACTION = "my-action";
48
49     @Mock
50     private HttpClient client;
51     @Mock
52     private HttpClientFactory factory;
53     @Mock
54     private Executor executor;
55
56     private DecisionParams params;
57     private DecisionConfig config;
58
59     /**
60      * Sets up.
61      */
62     @Before
63     public void setUp() {
64         when(factory.get(MY_CLIENT)).thenReturn(client);
65
66         params = DecisionParams.builder().onapName(ONAP_NAME).onapComponent(ONAP_COMP).onapInstance(ONAP_INST)
67                         .action(MY_ACTION).clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
68         config = new DecisionConfig(executor, params, factory);
69     }
70
71     @Test
72     public void test() {
73         DecisionRequest expected = new DecisionRequest();
74         expected.setOnapComponent(ONAP_COMP);
75         expected.setOnapInstance(ONAP_INST);
76         expected.setOnapName(ONAP_NAME);
77         expected.setAction(MY_ACTION);
78
79         DecisionRequest actual = config.makeRequest();
80         assertEquals(expected, actual);
81
82         // check value from superclass
83         assertSame(executor, config.getBlockingExecutor());
84         assertSame(client, config.getClient());
85
86         // repeat, with minimal parameters
87         params = DecisionParams.builder().clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
88         config = new DecisionConfig(executor, params, factory);
89         assertFalse(config.isDisabled());
90
91         actual = config.makeRequest();
92         assertEquals(new DecisionRequest(), actual);
93
94         // try with disabled=true
95         params = params.toBuilder().disabled(true).build();
96         config = new DecisionConfig(executor, params, factory);
97         assertTrue(config.isDisabled());
98     }
99 }