Remove logback.xml files bundled as part of jar
[policy/models.git] / models-interactions / model-actors / actor.vfc / src / test / java / org / onap / policy / controlloop / actor / vfc / VfcOperatorTest.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.vfc;
22
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.when;
27
28 import java.util.Map;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.policy.common.endpoints.http.client.HttpClient;
34 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
35 import org.onap.policy.controlloop.actorserviceprovider.Util;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
37
38 public class VfcOperatorTest {
39     private static final String ACTOR = "my-actor";
40     private static final String OPERATION = "my-name";
41     private static final String CLIENT = "my-client";
42     private static final String PATH = "/my-path";
43     private static final String PATH_GET = "my-path-get/";
44     private static final int MAX_GETS = 3;
45     private static final int WAIT_SEC_GETS = 20;
46     private static final int TIMEOUT = 100;
47
48     private VfcOperator oper;
49
50     @Mock
51     private HttpClient client;
52
53     @Mock
54     private HttpClientFactory factory;
55
56     /**
57      * setUp.
58      *
59      * @throws Exception exception
60      */
61     @Before
62     public void setUp() throws Exception {
63         MockitoAnnotations.initMocks(this);
64
65         when(factory.get(CLIENT)).thenReturn(client);
66
67         oper = new MyOperator();
68
69         VfcParams params = VfcParams.builder().pathGet(PATH_GET).maxGets(MAX_GETS).waitSecGet(WAIT_SEC_GETS)
70                 .clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
71         Map<String, Object> paramMap = Util.translateToMap(OPERATION, params);
72         oper.configure(paramMap);
73     }
74
75     @Test
76     public void testConstructor() {
77         assertEquals(ACTOR, oper.getActorName());
78         assertEquals(OPERATION, oper.getName());
79         assertEquals(ACTOR + "." + OPERATION, oper.getFullName());
80     }
81
82     @Test
83     public void testDoConfigure_testGetters() {
84         assertTrue(oper.getCurrentConfig() instanceof VfcConfig);
85
86         // test invalid parameters
87         Map<String, Object> paramMap2 = Util.translateToMap(OPERATION, VfcParams.builder().build());
88         assertThatThrownBy(() -> oper.configure(paramMap2)).isInstanceOf(ParameterValidationRuntimeException.class);
89     }
90
91     private class MyOperator extends VfcOperator {
92
93         public MyOperator() {
94             super(ACTOR, OPERATION, null);
95         }
96
97         @Override
98         protected HttpClientFactory getClientFactory() {
99             return factory;
100         }
101     }
102 }