More actor clean-up
[policy/models.git] / models-interactions / model-actors / actor.guard / src / test / java / org / onap / policy / controlloop / actor / guard / GuardConfigTest.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.actor.guard;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertSame;
25 import static org.mockito.Mockito.when;
26
27 import java.util.concurrent.Executor;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.policy.common.endpoints.http.client.HttpClient;
33 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
34 import org.onap.policy.controlloop.actorserviceprovider.Util;
35 import org.onap.policy.models.decisions.concepts.DecisionRequest;
36
37 public class GuardConfigTest {
38     private static final String MY_CLIENT = "my-client";
39     private static final String PATH = "my-path";
40     private static final int TIMEOUT = 10;
41     private static final String ONAP_NAME = "onap-nap";
42     private static final String ONAP_COMP = "onap-component";
43     private static final String ONAP_INST = "onap-instance";
44     private static final String MY_ACTION = "my-action";
45
46     @Mock
47     private HttpClient client;
48     @Mock
49     private HttpClientFactory factory;
50     @Mock
51     private Executor executor;
52
53     private GuardParams params;
54     private GuardConfig config;
55
56     /**
57      * Sets up.
58      */
59     @Before
60     public void setUp() {
61         MockitoAnnotations.initMocks(this);
62
63         when(factory.get(MY_CLIENT)).thenReturn(client);
64
65         params = GuardParams.builder().onapName(ONAP_NAME).onapComponent(ONAP_COMP).onapInstance(ONAP_INST)
66                         .action(MY_ACTION).clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
67         config = new GuardConfig(executor, params, factory);
68     }
69
70     @Test
71     public void test() {
72         DecisionRequest expected = new DecisionRequest();
73         expected.setOnapComponent(ONAP_COMP);
74         expected.setOnapInstance(ONAP_INST);
75         expected.setOnapName(ONAP_NAME);
76         expected.setAction(MY_ACTION);
77
78         DecisionRequest actual = Util.translate("", config.makeRequest(), DecisionRequest.class);
79         assertEquals(expected, actual);
80
81         // check value from superclass
82         assertSame(executor, config.getBlockingExecutor());
83         assertSame(client, config.getClient());
84
85         // repeat, with minimal parameters
86         params = GuardParams.builder().clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
87         config = new GuardConfig(executor, params, factory);
88
89         actual = Util.translate("", config.makeRequest(), DecisionRequest.class);
90         assertEquals(new DecisionRequest(), actual);
91     }
92 }