Upgrade Java 17 in policy-drools-apps
[policy/drools-applications.git] / controlloop / common / eventmanager / src / test / java / org / onap / policy / controlloop / drl / legacy / ControlLoopParamsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.drl.legacy;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25
26 import com.openpojo.reflection.impl.PojoClassFactory;
27 import com.openpojo.validation.ValidatorBuilder;
28 import com.openpojo.validation.test.impl.GetterTester;
29 import com.openpojo.validation.test.impl.SetterTester;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32
33
34 class ControlLoopParamsTest {
35     private static final String CONTROL_LOOP_NAME = "c";
36     private static final String POLICY_NAME = "m";
37     private static final String POLICY_SCOPE = "s";
38     private static final String POLICY_VERSION = "v";
39
40     private final ControlLoopParams  clp = new ControlLoopParams();
41
42     /**
43      * Prepare tests.
44      */
45     @BeforeEach
46     public void setUp() {
47         clp.setClosedLoopControlName(CONTROL_LOOP_NAME);
48         clp.setPolicyName(POLICY_NAME);
49         clp.setPolicyScope(POLICY_SCOPE);
50         clp.setPolicyVersion(POLICY_VERSION);
51     }
52
53     @Test
54     void testPojo() {
55         var controlLoopParams = PojoClassFactory.getPojoClass(ControlLoopParams.class);
56         var validator = ValidatorBuilder.create()
57                                       .with(new SetterTester(), new GetterTester()).build();
58         validator.validate(controlLoopParams);
59     }
60
61     @Test
62     void getClosedLoopControlName() {
63         assertEquals(CONTROL_LOOP_NAME, clp.getClosedLoopControlName());
64     }
65
66     @Test
67     void getPolicyName() {
68         assertEquals(POLICY_NAME, clp.getPolicyName());
69     }
70
71     @Test
72     void getPolicyScope() {
73         assertEquals(POLICY_SCOPE, clp.getPolicyScope());
74     }
75
76     @Test
77     void getPolicyVersion() {
78         assertEquals(POLICY_VERSION, clp.getPolicyVersion());
79     }
80
81     @Test
82     void setClosedLoopControlName() {
83         clp.setClosedLoopControlName(CONTROL_LOOP_NAME.toUpperCase());
84         assertEquals(CONTROL_LOOP_NAME.toUpperCase(), clp.getClosedLoopControlName());
85     }
86
87     @Test
88     void setPolicyName() {
89         clp.setPolicyName(POLICY_NAME.toUpperCase());
90         assertEquals(POLICY_NAME.toUpperCase(), clp.getPolicyName());
91     }
92
93     @Test
94     void setPolicyScope() {
95         clp.setPolicyScope(POLICY_SCOPE.toUpperCase());
96         assertEquals(POLICY_SCOPE.toUpperCase(), clp.getPolicyScope());
97     }
98
99     @Test
100     void setPolicyVersion() {
101         clp.setPolicyVersion(POLICY_VERSION.toUpperCase());
102         assertEquals(POLICY_VERSION.toUpperCase(), clp.getPolicyVersion());
103     }
104
105     @Test
106     void testTwo() {
107         var other = new ControlLoopParams();
108         other.setClosedLoopControlName(CONTROL_LOOP_NAME);
109         other.setPolicyName(POLICY_NAME);
110         other.setPolicyScope(POLICY_SCOPE);
111         other.setPolicyVersion(POLICY_VERSION);
112
113         assertEquals(clp, other);
114         assertEquals(clp.hashCode(), other.hashCode());
115         assertEquals(clp.toString(), other.toString());
116     }
117 }