Strengthens independence between UTs in OLM 95/93695/1
authorGilles Thouenon <gilles.thouenon@orange.com>
Sat, 24 Oct 2020 07:27:49 +0000 (09:27 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Mon, 9 Nov 2020 16:05:26 +0000 (17:05 +0100)
Use the adequate method of AbstracTest (getNewDataBroker())to be sure
that the same datastore context will not be shared between two UT.

Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Ie0e8a7aac6dd87f310c9e800eec83a77b24dfcf9

olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtTest.java
olm/src/test/java/org/opendaylight/transportpce/olm/service/OlmPowerServiceImplTest.java
pce/src/test/java/org/opendaylight/transportpce/pce/PceSendingPceRPCsTest.java

index 3307bb035d7ed0f7b2613c4242fb6897a40ffeeb..21ffdcfba91b97e690e1147946591b92e60a1fe3 100644 (file)
@@ -13,6 +13,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.MountPoint;
 import org.opendaylight.mdsal.binding.api.MountPointService;
 import org.opendaylight.transportpce.common.StringConstants;
@@ -42,7 +43,6 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev17
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 
 public class PowerMgmtTest extends AbstractTest {
-
     private MountPoint mountPoint;
     private MountPointService mountPointService;
     private DeviceTransactionManager deviceTransactionManager;
@@ -57,13 +57,15 @@ public class PowerMgmtTest extends AbstractTest {
     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
     private PortMappingVersion221 portMappingVersion22;
     private PortMappingVersion121 portMappingVersion121;
+    private DataBroker dataBroker;
 
     @Before
     public void setUp() {
-        this.mountPoint = new MountPointStub(this.getDataBroker());
+        dataBroker = this.getNewDataBroker();
+        this.mountPoint = new MountPointStub(dataBroker);
         this.mountPointService = new MountPointServiceStub(mountPoint);
         // this.mappingUtils = new MappingUtilsImpl(getDataBroker());
-        this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
+        this.mappingUtils = Mockito.spy(new MappingUtilsImpl(dataBroker));
         Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
                 .getOpenRoadmVersion(Mockito.anyString());
         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
@@ -77,13 +79,13 @@ public class PowerMgmtTest extends AbstractTest {
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
         this.portMappingVersion22 =
-                new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
+                new PortMappingVersion221(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
         this.portMappingVersion121 =
-                new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
-        this.portMapping = new PortMappingImpl(getDataBroker(),
+                new PortMappingVersion121(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
+        this.portMapping = new PortMappingImpl(dataBroker,
                 this.portMappingVersion22, this.portMappingVersion121);
         this.portMapping = Mockito.spy(this.portMapping);
-        this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
+        this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
                 this.deviceTransactionManager);
     }
 
@@ -147,7 +149,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(1000);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
@@ -159,7 +161,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes2() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
@@ -171,7 +173,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes3() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
@@ -195,7 +197,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes312() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
+            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, "deg");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
@@ -207,7 +209,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes32() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
@@ -219,7 +221,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes4() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "network");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
@@ -244,7 +246,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes42() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
@@ -256,7 +258,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes422() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
@@ -268,7 +270,7 @@ public class PowerMgmtTest extends AbstractTest {
     public void testSetPowerPresentNodes43() throws InterruptedException {
         List<NodeId> nodes = TransactionUtils.getNodeIds();
         for (NodeId nodeId : nodes) {
-            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
+            TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
             Thread.sleep(500);
         }
         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
index 29c2b7dde4cbeabd07dfad64695aa6c78b6618ca..78d4c01b9d8f8302dc1611478ba2a3b3e675166b 100644 (file)
@@ -97,10 +97,11 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
 
     @Before
     public void setUp() {
-        this.mountPoint = new MountPointStub(this.getDataBroker());
+        this.dataBroker =  getNewDataBroker();
+        this.mountPoint = new MountPointStub(this.dataBroker);
         this.mountPointService = new MountPointServiceStub(mountPoint);
         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
-        this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
+        this.mappingUtils = Mockito.spy(new MappingUtilsImpl(dataBroker));
         Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
                 .getOpenRoadmVersion(Mockito.anyString());
         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
@@ -113,18 +114,17 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
         this.portMappingVersion22 =
-                new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
+                new PortMappingVersion221(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
         this.portMappingVersion121 =
-                new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
-        this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.portMappingVersion121);
+                new PortMappingVersion121(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
+        this.portMapping = new PortMappingImpl(dataBroker, this.portMappingVersion22, this.portMappingVersion121);
         this.portMapping = Mockito.spy(this.portMapping);
-        this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
+        this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
             this.deviceTransactionManager);
-        this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
+        this.olmPowerService = new OlmPowerServiceImpl(this.dataBroker, this.powerMgmt,
             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
-        this.dataBroker =  PowerMockito.spy(getDataBroker());
         this.powerMgmtMock = PowerMockito.mock(PowerMgmtImpl.class);
-        this.olmPowerServiceMock = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmtMock,
+        this.olmPowerServiceMock = new OlmPowerServiceImpl(this.dataBroker, this.powerMgmtMock,
             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
         this.olmPowerServiceMock = Mockito.mock(OlmPowerServiceImpl.class);
         MockitoAnnotations.initMocks(this);
@@ -201,7 +201,7 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
             .augmentation(Network1.class)
             .build();
         Network1 network = TransactionUtils.getNetwork();
-        TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
+        TransactionUtils.writeTransaction(this.dataBroker, networkIID, network);
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
@@ -225,7 +225,7 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
             .augmentation(Network1.class)
             .build();
         Network1 network = TransactionUtils.getEmptyNetwork();
-        TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
+        TransactionUtils.writeTransaction(this.dataBroker, networkIID, network);
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
@@ -245,7 +245,7 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
             .augmentation(Network1.class)
             .build();
         Network1 network = TransactionUtils.getNullNetwork();
-        TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
+        TransactionUtils.writeTransaction(this.dataBroker, networkIID, network);
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
@@ -272,7 +272,7 @@ public class OlmPowerServiceImplTest  extends AbstractTest {
             .augmentation(Network1.class)
             .build();
         Network1 network = TransactionUtils.getNetwork();
-        TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
+        TransactionUtils.writeTransaction(this.dataBroker, networkIID, network);
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
index 342edf8eccf8ccbdf8db2815d239294641312b61..5291e5ce081735cc2de0a6c670b49942a7cdccd4 100644 (file)
@@ -14,6 +14,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
 import org.opendaylight.transportpce.common.network.RequestProcessor;
@@ -34,12 +35,14 @@ public class PceSendingPceRPCsTest extends AbstractTest {
     @Mock
     private BindingDOMCodecServices bindingDOMCodecServices;
     private JerseyServer jerseyServer = new JerseyServer();
+    private DataBroker dataBroker;
 
 
     @Before
     public void setUp() {
-        networkTransaction = new NetworkTransactionImpl(new RequestProcessor(this.getDataBroker()));
-        PceTestUtils.writeNetworkInDataStore(this.getDataBroker());
+        this.dataBroker = getNewDataBroker();
+        networkTransaction = new NetworkTransactionImpl(new RequestProcessor(this.dataBroker));
+        PceTestUtils.writeNetworkInDataStore(this.dataBroker);
         pceSendingPceRPCs = new PceSendingPceRPCs(PceTestData.getPCE_test1_request_54(),
                         networkTransaction, bindingDOMCodecServices);
     }