f636e08f6a2c8c0d0b225f90b5f54afb37691445
[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  * ================================================================================
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.drl.legacy;
22
23 import static org.junit.Assert.assertEquals;
24
25 import com.openpojo.reflection.PojoClass;
26 import com.openpojo.reflection.impl.PojoClassFactory;
27 import com.openpojo.validation.Validator;
28 import com.openpojo.validation.ValidatorBuilder;
29 import com.openpojo.validation.test.impl.GetterTester;
30 import com.openpojo.validation.test.impl.SetterTester;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 public 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 ControlLoopParams  clp = new ControlLoopParams();
41
42     /**
43      * Prepare tests.
44      */
45     @Before
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     public void testPojo() {
55         PojoClass controlLoopParams = PojoClassFactory.getPojoClass(ControlLoopParams.class);
56         Validator validator = ValidatorBuilder.create()
57                                       .with(new SetterTester(), new GetterTester()).build();
58         validator.validate(controlLoopParams);
59     }
60
61     @Test
62     public void getClosedLoopControlName() {
63         assertEquals(CONTROL_LOOP_NAME, clp.getClosedLoopControlName());
64     }
65
66     @Test
67     public void getPolicyName() {
68         assertEquals(POLICY_NAME, clp.getPolicyName());
69     }
70
71     @Test
72     public void getPolicyScope() {
73         assertEquals(POLICY_SCOPE, clp.getPolicyScope());
74     }
75
76     @Test
77     public void getPolicyVersion() {
78         assertEquals(POLICY_VERSION, clp.getPolicyVersion());
79     }
80
81     @Test
82     public void setClosedLoopControlName() {
83         clp.setClosedLoopControlName(CONTROL_LOOP_NAME.toUpperCase());
84         assertEquals(CONTROL_LOOP_NAME.toUpperCase(), clp.getClosedLoopControlName());
85     }
86
87     @Test
88     public void setPolicyName() {
89         clp.setPolicyName(POLICY_NAME.toUpperCase());
90         assertEquals(POLICY_NAME.toUpperCase(), clp.getPolicyName());
91     }
92
93     @Test
94     public void setPolicyScope() {
95         clp.setPolicyScope(POLICY_SCOPE.toUpperCase());
96         assertEquals(POLICY_SCOPE.toUpperCase(), clp.getPolicyScope());
97     }
98
99     @Test
100     public void setPolicyVersion() {
101         clp.setPolicyVersion(POLICY_VERSION.toUpperCase());
102         assertEquals(POLICY_VERSION.toUpperCase(), clp.getPolicyVersion());
103     }
104
105     @Test
106     public void testTwo() {
107         ControlLoopParams 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 }