aboutsummaryrefslogtreecommitdiffstats
path: root/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java
blob: b12af00338c46c0f51340fec08b0f5f8ca207a7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nordix Foundation.
 *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.distribution.reception.parameters;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
import org.onap.policy.distribution.reception.handling.DummyDecoder;

/**
 * Class for unit testing ReceptionHandlerParameters class.
 *
 * @author Adheli Tavares (adheli.tavares@est.tech)
 *
 */
public class TestReceptionHandlerParameters {

    @Test
    public void testValidate_ClassNotFound() {
        final String className = "org.onap.policy.distribution.reception.testclasses.NotExistent";

        ReceptionHandlerParameters sutParams = getReceptionHandlerParameters(className);
        sutParams.setName(className);

        assertThat(sutParams.validate().getResult()).contains("class is not in the classpath");
    }

    @Test
    public void testValidate_ReceptionHandlerTypeNullEmpty() {
        final String className = DummyDecoder.class.getName();
        final PluginHandlerParameters pHParameters =
                new PluginHandlerParameters(getPolicyDecoders(), getPolicyForwarders());

        ReceptionHandlerParameters nullType = new ReceptionHandlerParameters(null, className, className, pHParameters);

        assertThat(nullType.validate().getResult())
                        .contains("\"receptionHandlerType\" value \"null\" INVALID, is null");

        ReceptionHandlerParameters emptyType = new ReceptionHandlerParameters("", className, className, pHParameters);

        assertThat(emptyType.validate().getResult()).contains("\"receptionHandlerType\" value \"\" INVALID, is blank")
                        .doesNotContain("classpath");
    }

    @Test
    public void testValidate_ReceptionHandlerClassNameNullEmpty() {
        final PluginHandlerParameters pHParameters =
                new PluginHandlerParameters(getPolicyDecoders(), getPolicyForwarders());

        ReceptionHandlerParameters nullType = new ReceptionHandlerParameters("DummyReceptionHandler", null,
                "dummyReceptionHandlerConfiguration", pHParameters);

        assertThat(nullType.validate().getResult())
                .contains("\"receptionHandlerClassName\" value \"null\" INVALID, is null");

        ReceptionHandlerParameters emptyType = new ReceptionHandlerParameters("DummyReceptionHandler", "",
                "dummyReceptionHandlerConfiguration", pHParameters);

        assertThat(emptyType.validate().getResult())
                .contains("\"receptionHandlerClassName\" value \"\" INVALID, is blank");
    }

    @Test
    public void testValidate_PluginHandlerParametersNull() {
        final String className = "org.onap.policy.distribution.reception.testclasses.DummyReceptionHandler";

        ReceptionHandlerParameters sutParams = new ReceptionHandlerParameters("DummyReceptionHandler", className,
                "dummyReceptionHandlerConfiguration", null);

        assertThat(sutParams.validate().getResult())
                .contains("\"pluginHandlerParameters\" value \"null\" INVALID, is null");
    }

    private ReceptionHandlerParameters getReceptionHandlerParameters(String className) {
        final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders();
        final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders();
        final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
        final ReceptionHandlerParameters rhParameters = new ReceptionHandlerParameters("DummyReceptionHandler",
                className, "dummyReceptionHandlerConfiguration", pHParameters);
        return rhParameters;
    }

    private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
        final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>();

        final PolicyDecoderParameters pDParameters =
                new PolicyDecoderParameters("DummyDecoder", DummyDecoder.class.getName(), "dummyDecoderConfiguration");
        policyDecoders.put("DummyDecoder", pDParameters);

        return policyDecoders;
    }

    private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
        final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>();

        final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("DummyForwarder",
                        DummyDecoder.class.getName(), "dummyForwarderConfiguration");
        policyForwarders.put("DummyForwarder", pFParameters);

        return policyForwarders;
    }

}