2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2019 Nordix Foundation.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.policy;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.List;
30 import org.junit.Ignore;
31 import org.junit.Test;
32 import org.onap.aai.domain.yang.Pnf;
33 import org.onap.policy.common.utils.io.Serializer;
34 import org.onap.policy.sdc.Resource;
35 import org.onap.policy.sdc.ResourceType;
36 import org.onap.policy.sdc.Service;
38 public class ControlLoopTest {
40 private static final String SERVICE2 = "service2";
41 private static final String SERVICE1 = "service1";
42 private static final String RESOURCE2 = "resource2";
43 private static final String RESOURCE1 = "resource1";
44 private static final String PNF1 = "pnf 1";
45 private String controlLoopName = "control loop 1";
46 private String version = "1.0.1";
47 private String triggerPolicy = FinalResult.FINAL_OPENLOOP.toString();
48 private Integer timeout = 100;
49 private Boolean abatement = false;
52 public void testEqualsSameInstance() {
53 ControlLoop controlLoop1 = new ControlLoop();
54 assertTrue(controlLoop1.equals(controlLoop1));
58 public void testEqualsNull() {
59 ControlLoop controlLoop1 = new ControlLoop();
60 assertFalse(controlLoop1.equals(null));
64 public void testEqualsInstanceOfDiffClass() {
65 ControlLoop controlLoop1 = new ControlLoop();
66 assertFalse(controlLoop1.equals(""));
70 public void testEqualsNoServicesAndResourcesOrTimeout() {
71 final Pnf pnf = new Pnf();
74 ControlLoop controlLoop1 = new ControlLoop();
75 controlLoop1.setControlLoopName(controlLoopName);
76 controlLoop1.setVersion(version);
77 controlLoop1.setPnf(pnf);
78 controlLoop1.setTrigger_policy(triggerPolicy);
79 controlLoop1.setAbatement(abatement);
81 ControlLoop controlLoop2 = new ControlLoop();
82 controlLoop2.setControlLoopName(controlLoopName);
83 controlLoop2.setVersion(version);
84 controlLoop2.setPnf(pnf);
85 controlLoop2.setTrigger_policy(triggerPolicy);
86 controlLoop2.setAbatement(abatement);
88 assertTrue(controlLoop1.equals(controlLoop2));
92 public void testEquals() throws IOException {
93 final Pnf pnf = new Pnf();
96 ControlLoop controlLoop1 = new ControlLoop();
97 controlLoop1.setControlLoopName(controlLoopName);
98 controlLoop1.setVersion(version);
99 Service service1 = new Service(SERVICE1);
100 Service service2 = new Service(SERVICE2);
101 List<Service> services = new ArrayList<>();
102 services.add(service1);
103 services.add(service2);
104 controlLoop1.setServices(services);
105 Resource resource1 = new Resource(RESOURCE1, ResourceType.VF);
106 Resource resource2 = new Resource(RESOURCE2, ResourceType.VFC);
107 List<Resource> resources = new ArrayList<>();
108 resources.add(resource1);
109 resources.add(resource2);
110 controlLoop1.setResources(resources);
111 controlLoop1.setPnf(pnf);
112 controlLoop1.setTrigger_policy(triggerPolicy);
113 controlLoop1.setTimeout(timeout);
114 controlLoop1.setAbatement(abatement);
116 ControlLoop controlLoop2 = new ControlLoop();
117 controlLoop2.setControlLoopName(controlLoopName);
118 controlLoop2.setVersion(version);
119 Service controlLoop2Service1 = new Service(SERVICE1);
120 Service controlLoop2Service2 = new Service(SERVICE2);
121 List<Service> controlLoop2Services = new ArrayList<>();
122 controlLoop2Services.add(controlLoop2Service1);
123 controlLoop2Services.add(controlLoop2Service2);
124 controlLoop2.setServices(controlLoop2Services);
125 Resource controlLoop2Resource1 = new Resource(RESOURCE1, ResourceType.VF);
126 Resource controlLoop2Resource2 = new Resource(RESOURCE2, ResourceType.VFC);
127 List<Resource> controlLoop2Resources = new ArrayList<>();
128 controlLoop2Resources.add(controlLoop2Resource1);
129 controlLoop2Resources.add(controlLoop2Resource2);
130 controlLoop2.setResources(controlLoop2Resources);
131 controlLoop2.setPnf(pnf);
132 controlLoop2.setTrigger_policy(triggerPolicy);
133 controlLoop2.setTimeout(timeout);
134 controlLoop1.setAbatement(abatement);
136 assertTrue(controlLoop1.equals(controlLoop2));
137 assertEquals(controlLoop1.hashCode(), controlLoop2.hashCode());
139 controlLoop2 = Serializer.roundTrip(controlLoop1);
140 assertTrue(controlLoop1.equals(controlLoop2));
141 assertEquals(controlLoop1.hashCode(), controlLoop2.hashCode());
146 // I'VE MARKED THIS TEST CASE AS IGNORE BECAUSE THE TEST CASE FAILS
147 // This test case fails because the ControlLoop(ControlLoop controlLoop) constructor.
148 // does not copy the value of pnf and version into the newly created object
149 // PLEASE ADVISE IF THE EXISTING BEHAVIOUR IS CORRECT
150 public void testControlLoop() {
151 final Pnf pnf = new Pnf();
152 pnf.setPnfName(PNF1);
154 ControlLoop controlLoop1 = new ControlLoop();
155 controlLoop1.setControlLoopName(controlLoopName);
156 controlLoop1.setVersion(version);
157 Service service1 = new Service(SERVICE1);
158 Service service2 = new Service(SERVICE2);
159 List<Service> services = new ArrayList<>();
160 services.add(service1);
161 services.add(service2);
162 controlLoop1.setServices(services);
163 Resource resource1 = new Resource(RESOURCE1, ResourceType.VF);
164 Resource resource2 = new Resource(RESOURCE2, ResourceType.VFC);
165 List<Resource> resources = new ArrayList<>();
166 resources.add(resource1);
167 resources.add(resource2);
168 controlLoop1.setResources(resources);
169 controlLoop1.setPnf(pnf);
170 controlLoop1.setTrigger_policy(triggerPolicy);
171 controlLoop1.setAbatement(abatement);
173 ControlLoop controlLoop2 = new ControlLoop(controlLoop1);
175 assertEquals(controlLoop1.getControlLoopName(), controlLoop2.getControlLoopName());
176 assertEquals(controlLoop1.getVersion(), controlLoop2.getVersion());
177 assertEquals(controlLoop1.getServices(), controlLoop2.getServices());
178 assertEquals(controlLoop1.getResources(), controlLoop2.getResources());
179 assertEquals(controlLoop1.getPnf(), controlLoop2.getPnf());
180 assertEquals(controlLoop1.getTrigger_policy(), controlLoop2.getTrigger_policy());
181 assertEquals(controlLoop1.getAbatement(), controlLoop2.getAbatement());
183 assertTrue(controlLoop1.equals(controlLoop2));