9d6a78d0f89ade0e61bc7765e486013cf50d4fdd
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.reception.parameters;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import java.util.HashMap;
26 import java.util.Map;
27 import org.junit.Test;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
30
31 /**
32  * Class for unit testing PluginHandlerParameters class.
33  *
34  * @author Adheli Tavares (adheli.tavares@est.tech)
35  *
36  */
37 public class TestPluginHandlerParameters {
38
39     @Test
40     public void testValidate_PolicyDecodersEmpty() {
41         PluginHandlerParameters emptyDecoder = new PluginHandlerParameters(new HashMap<>(), getPolicyForwarders());
42
43         GroupValidationResult result = emptyDecoder.validate();
44
45         assertThat(result.getResult())
46                 .contains("parameter group map \"policyDecoders\" INVALID, must have at least one policy decoder");
47         assertThat(result.getResult()).doesNotContain(
48                 "parameter group map \"policyForwarders\" INVALID, must have at least one policy forwarder");
49     }
50
51     @Test
52     public void testValidate_PolicyForwardersNullEmpty() {
53         PluginHandlerParameters emptyDecoder = new PluginHandlerParameters(getPolicyDecoders(), new HashMap<>());
54
55         GroupValidationResult result = emptyDecoder.validate();
56
57         assertThat(result.getResult())
58                 .contains("parameter group map \"policyForwarders\" INVALID, must have at least one policy forwarder");
59         assertThat(result.getResult()).doesNotContain(
60                 "parameter group map \"policyDecoders\" INVALID, must have at least one policy decoder");
61     }
62
63     private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
64         final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>();
65         final PolicyDecoderParameters pDParameters =
66                 new PolicyDecoderParameters("DummyDecoder", "DummyDecoder", "dummyDecoderConfiguration");
67         policyDecoders.put("DummyDecoder", pDParameters);
68
69         return policyDecoders;
70     }
71
72     private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
73         final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>();
74         final PolicyForwarderParameters pFParameters =
75                 new PolicyForwarderParameters("DummyForwarder", "DummyForwarder", "dummyForwarderConfiguration");
76         policyForwarders.put("DummyForwarder", pFParameters);
77
78         return policyForwarders;
79     }
80
81 }