Convert PowerMgmtImpl of olm into a Component
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / power / PowerMgmtPowerMockTest.java
index 36c8d097f70926ab8918e954bf530854df5eee9f..62fdb6b33b39bb944442780400b5338a63119750 100644 (file)
@@ -9,13 +9,14 @@
 package org.opendaylight.transportpce.olm.power;
 
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 import org.opendaylight.mdsal.binding.api.MountPoint;
@@ -47,13 +48,13 @@ import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
 import org.opendaylight.transportpce.olm.util.OlmUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.OpenroadmNodeVersion;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.nodes.NodeInfoBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.OpenroadmNodeVersion;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.NodesBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.nodes.NodeInfoBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RatioDB;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceBuilder;
@@ -63,7 +64,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfa
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
 import org.opendaylight.yangtools.yang.common.Decimal64;
 
-@Ignore
+@Disabled
 public class PowerMgmtPowerMockTest extends AbstractTest {
 
     private MountPoint mountPoint;
@@ -84,8 +85,8 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
     private PortMappingVersion221 portMappingVersion22;
     private PortMappingVersion121 portMappingVersion121;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         this.mountPoint = new MountPointStub(getDataBroker());
         this.mountPointService = new MountPointServiceStub(mountPoint);
         this.mappingUtils = new MappingUtilsImpl(getDataBroker());
@@ -103,32 +104,30 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
             this.portMappingVersion22, this.portMappingVersion121);
         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
-        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping,
-            this.portMappingVersion22);
-        this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping,
-            this.portMappingVersion710);
+        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping);
+        this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping);
         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
             this.openRoadmInterfacesImpl710);
         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
         this.portMapping = Mockito.spy(this.portMapping);
-        this.powerMgmt = new PowerMgmtImpl(getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
-                this.deviceTransactionManager, this.portMapping);
+        this.powerMgmt = new PowerMgmtImpl(this.openRoadmInterfaces, this.crossConnect,
+                this.deviceTransactionManager, this.portMapping, 1000, 1000);
     }
 
     @Test
-    public void testSetPowerMockingUtil() {
+    void testSetPowerMockingUtil() {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
                 .thenReturn(getXpdrNodesFromNodesBuilderDeg());
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
         boolean output = this.powerMgmt.setPower(input);
-        Assert.assertEquals(false, output);
+        assertEquals(false, output);
 
     }
 
     @Test
-    public void testSetPowerMockingUtilNetwokType() throws OpenRoadmInterfaceException {
+    void testSetPowerMockingUtilNetwokType() throws OpenRoadmInterfaceException {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.mockStatic(PowerMgmtVersion121.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
@@ -144,12 +143,12 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                 .thenReturn(Optional.empty());
         PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
         boolean output = powerMgmtImpl.setPower(input);
-        Assert.assertEquals(true, output);
+        assertEquals(true, output);
 
     }
 
     @Test
-    public void testSetPowerMockingUtilNetwokTypeMoreThanOneNode() throws OpenRoadmInterfaceException {
+    void testSetPowerMockingUtilNetwokTypeMoreThanOneNode() throws OpenRoadmInterfaceException {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.mockStatic(PowerMgmtVersion121.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
@@ -165,23 +164,23 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                 .thenReturn(Optional.empty());
         PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
         boolean output = powerMgmtImpl.setPower(input);
-        Assert.assertEquals(true, output);
+        assertEquals(true, output);
 
     }
 
     @Test
-    public void testSetPowerXpdrNodes() {
+    void testSetPowerXpdrNodes() {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
                 .thenReturn(getXpdrNodesFromNodesBuilderDeg());
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
         boolean output = this.powerMgmt.setPower(input);
-        Assert.assertEquals(true, output);
+        assertEquals(true, output);
 
     }
 
     @Test
-    public void testSetPowerRdmNodesReturnInterfaceEmpty() throws OpenRoadmInterfaceException {
+    void testSetPowerRdmNodesReturnInterfaceEmpty() throws OpenRoadmInterfaceException {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
                 .thenReturn(getRdmNodesFromNodesBuilder());
@@ -191,11 +190,11 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                 .thenReturn(Optional.empty());
         PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
         boolean output = powerMgmtImpl.setPower(input);
-        Assert.assertEquals(false, output);
+        assertEquals(false, output);
     }
 
     @Test
-    public void testSetPowerRdmNodesThrowsException() throws OpenRoadmInterfaceException {
+    void testSetPowerRdmNodesThrowsException() throws OpenRoadmInterfaceException {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
                 .thenReturn(getRdmNodesFromNodesBuilder());
@@ -205,11 +204,11 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                 .thenThrow(new OpenRoadmInterfaceException("error thrown by unit tests "));
         PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
         boolean output = powerMgmtImpl.setPower(input);
-        Assert.assertEquals(false, output);
+        assertEquals(false, output);
     }
 
     @Test
-    public void testSetPowerRdmNodesReturnInterface() throws OpenRoadmInterfaceException {
+    void testSetPowerRdmNodesReturnInterface() throws OpenRoadmInterfaceException {
         Mockito.mockStatic(OlmUtils.class);
         Mockito.when(this.portMapping.getNode(Mockito.anyString()))
                 .thenReturn(getRdmNodesFromNodesBuilder());
@@ -227,7 +226,7 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                         Mockito.anyString())).thenReturn(true);
         PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,crossConnectMock);
         boolean output = powerMgmtImpl.setPower(input);
-        Assert.assertEquals(true, output);
+        assertEquals(true, output);
     }
 
     private PowerMgmtImpl getNewPowerMgmt(OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy,
@@ -236,8 +235,8 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                 this.mappingUtils, openRoadmInterfacesImpl121Spy, this.openRoadmInterfacesImpl22,
             this.openRoadmInterfacesImpl710);
         openRoadmInterfacesSpy = Mockito.spy(openRoadmInterfacesSpy);
-        return new PowerMgmtImpl(getDataBroker(), openRoadmInterfacesSpy, crossConnectMock,
-                this.deviceTransactionManager, this.portMapping);
+        return new PowerMgmtImpl(openRoadmInterfacesSpy, crossConnectMock,
+                this.deviceTransactionManager, this.portMapping, 0, 0);
     }
 
     private Nodes getXpdrNodesFromNodesBuilderDeg() {