initial olm unit testing commit
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / power / PowerMgmtTest.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.olm.power;
10
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
16 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
17 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
19 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
20 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
21 import org.opendaylight.transportpce.common.mapping.PortMapping;
22 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
23 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
24 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
25 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
26 import org.opendaylight.transportpce.olm.stub.MountPointStub;
27 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
28 import org.opendaylight.transportpce.olm.util.TransactionUtils;
29 import org.opendaylight.transportpce.test.AbstractTest;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
32
33 public class PowerMgmtTest extends AbstractTest {
34
35     private MountPoint mountPoint;
36     private MountPointService mountPointService;
37     private DeviceTransactionManager deviceTransactionManager;
38     private CrossConnect crossConnect;
39     private OpenRoadmInterfaces openRoadmInterfaces;
40     private PortMapping portMapping;
41     private PowerMgmt powerMgmt;
42
43     @Before
44     public void setUp() {
45         this.mountPoint = new MountPointStub(this.getDataBroker());
46         this.mountPointService = new MountPointServiceStub(mountPoint);
47         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
48         this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
49         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager));
50         this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
51             this.openRoadmInterfaces);
52         this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
53             this.deviceTransactionManager);
54     }
55
56     @Test
57     public void testSetPower() {
58
59         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
60         boolean output = this.powerMgmt.setPower(input);
61         Assert.assertEquals(true, output);
62
63     }
64
65     @Test
66     public void testSetPower2() {
67
68         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
69         boolean output = this.powerMgmt.setPower(input);
70         Assert.assertEquals(true, output);
71
72     }
73
74     @Test
75     public void testSetPower3() {
76
77         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
78         boolean output = this.powerMgmt.setPower(input);
79         Assert.assertEquals(true, output);
80
81     }
82
83     @Test
84     public void testSetPower4() {
85
86         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
87         boolean output = this.powerMgmt.setPower(input);
88         Assert.assertEquals(true, output);
89
90     }
91
92     @Test
93     public void testSetPowerPresentNodes() throws InterruptedException {
94         List<NodeId> nodes = TransactionUtils.getNodeIds();
95         for (NodeId nodeId : nodes) {
96             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
97             Thread.sleep(500);
98         }
99         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
100         boolean output = this.powerMgmt.setPower(input);
101         Assert.assertEquals(true, output);
102     }
103
104     @Test
105     public void testSetPowerPresentNodes2() throws InterruptedException {
106         List<NodeId> nodes = TransactionUtils.getNodeIds();
107         for (NodeId nodeId : nodes) {
108             TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
109             Thread.sleep(500);
110         }
111         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
112         boolean output = this.powerMgmt.setPower(input);
113         Assert.assertEquals(true, output);
114     }
115
116     @Test
117     public void testSetPowerPresentNodes3() throws InterruptedException {
118         List<NodeId> nodes = TransactionUtils.getNodeIds();
119         for (NodeId nodeId : nodes) {
120             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
121             Thread.sleep(500);
122         }
123         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
124         boolean output = this.powerMgmt.setPower(input);
125         Assert.assertEquals(true, output);
126     }
127
128     @Test
129     public void testSetPowerPresentNodes31() throws InterruptedException {
130         List<NodeId> nodes = TransactionUtils.getNodeIds();
131         for (NodeId nodeId : nodes) {
132             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
133             Thread.sleep(500);
134         }
135         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
136         boolean output = this.powerMgmt.setPower(input);
137         Assert.assertEquals(false, output);
138     }
139
140     @Test
141     public void testSetPowerPresentNodes312() throws InterruptedException {
142         List<NodeId> nodes = TransactionUtils.getNodeIds();
143         for (NodeId nodeId : nodes) {
144             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
145             Thread.sleep(500);
146         }
147         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
148         boolean output = this.powerMgmt.setPower(input);
149         Assert.assertEquals(true, output);
150     }
151
152     @Test
153     public void testSetPowerPresentNodes32() throws InterruptedException {
154         List<NodeId> nodes = TransactionUtils.getNodeIds();
155         for (NodeId nodeId : nodes) {
156             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
157             Thread.sleep(500);
158         }
159         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
160         boolean output = this.powerMgmt.setPower(input);
161         Assert.assertEquals(true, output);
162     }
163
164     @Test
165     public void testSetPowerPresentNodes4() throws InterruptedException {
166         List<NodeId> nodes = TransactionUtils.getNodeIds();
167         for (NodeId nodeId : nodes) {
168             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
169             Thread.sleep(500);
170         }
171         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
172         boolean output = this.powerMgmt.setPower(input);
173         Assert.assertEquals(true, output);
174     }
175
176     @Test
177     public void testSetPowerPresentNodes41() throws InterruptedException {
178         List<NodeId> nodes = TransactionUtils.getNodeIds();
179         for (NodeId nodeId : nodes) {
180             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
181             Thread.sleep(500);
182         }
183         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
184         boolean output = this.powerMgmt.setPower(input);
185         Assert.assertEquals(false, output);
186     }
187
188     @Test
189     public void testSetPowerPresentNodes42() throws InterruptedException {
190         List<NodeId> nodes = TransactionUtils.getNodeIds();
191         for (NodeId nodeId : nodes) {
192             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
193             Thread.sleep(500);
194         }
195         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
196         boolean output = this.powerMgmt.setPower(input);
197         Assert.assertEquals(true, output);
198     }
199
200     @Test
201     public void testSetPowerPresentNodes422() throws InterruptedException {
202         List<NodeId> nodes = TransactionUtils.getNodeIds();
203         for (NodeId nodeId : nodes) {
204             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
205             Thread.sleep(500);
206         }
207         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
208         boolean output = this.powerMgmt.setPower(input);
209         Assert.assertEquals(true, output);
210     }
211
212     @Test
213     public void testSetPowerPresentNodes43() throws InterruptedException {
214         List<NodeId> nodes = TransactionUtils.getNodeIds();
215         for (NodeId nodeId : nodes) {
216             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
217             Thread.sleep(500);
218         }
219         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
220         boolean output = this.powerMgmt.setPower(input);
221         Assert.assertEquals(true, output);
222     }
223
224 }