Remove logback.xml files bundled as part of jar
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / SoParamsTest.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.so;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.function.Function;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.common.parameters.ValidationResult;
32 import org.onap.policy.controlloop.actor.so.SoParams.SoParamsBuilder;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams.HttpParamsBuilder;
34
35 public class SoParamsTest {
36     private static final String CONTAINER = "my-container";
37     private static final String CLIENT = "my-client";
38     private static final String PATH = "my-path";
39     private static final String PATH_GET = "my-path-get";
40     private static final int MAX_GETS = 3;
41     private static final int WAIT_SEC_GETS = 20;
42     private static final int TIMEOUT = 10;
43
44     private SoParams params;
45
46     @Before
47     public void setUp() {
48         params = SoParams.builder().pathGet(PATH_GET).maxGets(MAX_GETS).waitSecGet(WAIT_SEC_GETS).clientName(CLIENT)
49                         .path(PATH).timeoutSec(TIMEOUT).build();
50     }
51
52     @Test
53     public void testValidate() {
54         assertTrue(params.validate(CONTAINER).isValid());
55
56         testValidateField("pathGet", "null", bldr -> bldr.pathGet(null));
57         testValidateField("maxGets", "minimum", bldr -> bldr.maxGets(-1));
58         testValidateField("waitSecGet", "minimum", bldr -> bldr.waitSecGet(-1));
59
60         // validate one of the superclass fields
61         testValidateField("clientName", "null", bldr -> bldr.clientName(null));
62
63         // check edge cases
64         assertTrue(params.toBuilder().maxGets(0).build().validate(CONTAINER).isValid());
65         assertFalse(params.toBuilder().waitSecGet(0).build().validate(CONTAINER).isValid());
66         assertTrue(params.toBuilder().waitSecGet(1).build().validate(CONTAINER).isValid());
67     }
68
69     @Test
70     public void testBuilder_testToBuilder() {
71         assertEquals(CLIENT, params.getClientName());
72
73         assertEquals(PATH_GET, params.getPathGet());
74         assertEquals(MAX_GETS, params.getMaxGets());
75         assertEquals(WAIT_SEC_GETS, params.getWaitSecGet());
76
77         assertEquals(params, params.toBuilder().build());
78     }
79
80     private void testValidateField(String fieldName, String expected,
81                     @SuppressWarnings("rawtypes") Function<SoParamsBuilder, HttpParamsBuilder> makeInvalid) {
82
83         // original params should be valid
84         ValidationResult result = params.validate(CONTAINER);
85         assertTrue(fieldName, result.isValid());
86
87         // make invalid params
88         result = makeInvalid.apply(params.toBuilder()).build().validate(CONTAINER);
89         assertFalse(fieldName, result.isValid());
90         assertThat(result.getResult()).contains(fieldName).contains(expected);
91     }
92 }