X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=renderer%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Frenderer%2Fprovisiondevice%2FDeviceRendererServiceImplSetupTest.java;fp=renderer%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Frenderer%2Fprovisiondevice%2FDeviceRendererServiceImplTest.java;h=bc69d17a07f90eecf5f6ef636b9cc6bba749b025;hb=d609ca3b1012e9d52ff6cd1ed9376425d22e6246;hp=f0a59bd799e7cb1b95259eadd0d8156479e3f4a7;hpb=810038f95e82b0564c11ad5ba0f3f2813bc04a48;p=transportpce.git diff --git a/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplTest.java b/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplSetupTest.java similarity index 51% rename from renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplTest.java rename to renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplSetupTest.java index f0a59bd79..bc69d17a0 100644 --- a/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplTest.java +++ b/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplSetupTest.java @@ -10,9 +10,9 @@ package org.opendaylight.transportpce.renderer.provisiondevice; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; import org.junit.Assert; import org.junit.Test; +import org.mockito.Mockito; import org.opendaylight.controller.md.sal.binding.api.MountPoint; import org.opendaylight.controller.md.sal.binding.api.MountPointService; import org.opendaylight.transportpce.common.crossconnect.CrossConnect; @@ -21,42 +21,41 @@ import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl; import org.opendaylight.transportpce.common.mapping.PortMapping; import org.opendaylight.transportpce.common.mapping.PortMappingImpl; +import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException; import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces; import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl; import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory; import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection; import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub; -import org.opendaylight.transportpce.renderer.stub.MountPointStub; import org.opendaylight.transportpce.renderer.utils.MountPointUtils; -import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils; +import org.opendaylight.transportpce.renderer.utils.ServiceImplementationDataUtils; import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterface; -import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceKey; import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererRollbackInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererRollbackInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererRollbackOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutput; -public class DeviceRendererServiceImplTest extends AbstractTest { - - private MountPointService mountPointService; +public class DeviceRendererServiceImplSetupTest extends AbstractTest { private DeviceTransactionManager deviceTransactionManager; private DeviceRendererService deviceRendererService; + private CrossConnect crossConnect; + private PortMapping portMapping; + private OpenRoadmInterfaces openRoadmInterfaces; + private void setMountPoint(MountPoint mountPoint) { - this.mountPointService = new MountPointServiceStub(mountPoint); - this.deviceTransactionManager = new DeviceTransactionManagerImpl(this.mountPointService, 3000); - OpenRoadmInterfaces openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager); - PortMapping portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager, - openRoadmInterfaces); - OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(portMapping, - openRoadmInterfaces); - CrossConnect crossConnect = new CrossConnectImpl(this.deviceTransactionManager); + MountPointService mountPointService = new MountPointServiceStub(mountPoint); + this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000); + this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager); + this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces); + this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager, + this.openRoadmInterfaces); + this.portMapping = Mockito.spy(this.portMapping); + OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.portMapping, + this.openRoadmInterfaces); + this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager); + this.crossConnect = Mockito.spy(this.crossConnect); this.deviceRendererService = new DeviceRendererServiceImpl(this.getDataBroker(), this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect, portMapping); @@ -65,7 +64,7 @@ public class DeviceRendererServiceImplTest extends AbstractTest { @Test public void testSetupServiceWhenDeviceIsNotMounted() { setMountPoint(null); - ServicePathInput servicePathInput = ServiceDataUtils.buildServicePathInputs(); + ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(); for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) { ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput, servicePathDirection); @@ -76,31 +75,49 @@ public class DeviceRendererServiceImplTest extends AbstractTest { } @Test - public void testSetupServiceUsingCrossConnectEmptyPorts() throws ExecutionException, InterruptedException { + public void testSetupServicemptyPorts() { setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker())); - testSetupService(true); + String nodeId = "node1"; + String srcTP = OpenRoadmInterfacesImpl.TTP_TOKEN; + String dstTp = OpenRoadmInterfacesImpl.PP_TOKEN; + List nodes = new ArrayList<>(); + nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp)); + ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes); + for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) { + ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput, + servicePathDirection); + Assert.assertFalse(servicePathOutput.isSuccess()); + } } @Test - public void testSetupServiceUsingCrossConnectWithPorts() throws ExecutionException, InterruptedException { + public void testSetupServiceCannotCrossConnect() { setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker())); - testSetupService(true); + String nodeId = "node1"; + String srcTP = OpenRoadmInterfacesImpl.TTP_TOKEN; + String dstTp = OpenRoadmInterfacesImpl.PP_TOKEN; + MountPointUtils.writeMapping(nodeId, srcTP, this.deviceTransactionManager); + MountPointUtils.writeMapping(nodeId, dstTp, this.deviceTransactionManager); + List nodes = new ArrayList<>(); + nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp)); + ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes); + Mockito.doReturn(java.util.Optional.empty()).when(this.crossConnect).postCrossConnect(nodeId, 20L, srcTP, + dstTp); + ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput, + ServicePathDirection.A_TO_Z); + Assert.assertFalse(servicePathOutput.isSuccess()); } -// @Test -// public void testSetupServiceWithoutCrossConnect() throws ExecutionException, InterruptedException { -// setMountPoint(new MountPointStub(getDataBroker())); -// -// testSetupService(false); -// } - - private void testSetupService(boolean crossConnect) throws ExecutionException, InterruptedException { + @Test + public void testSetupService() throws OpenRoadmInterfaceException { + setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker())); + Mockito.doNothing().when(this.openRoadmInterfaces).postEquipmentState(Mockito.anyString(), + Mockito.anyString(), Mockito.anyBoolean()); String [] interfaceTokens = { OpenRoadmInterfacesImpl.NETWORK_TOKEN, OpenRoadmInterfacesImpl.CLIENT_TOKEN, OpenRoadmInterfacesImpl.TTP_TOKEN, - OpenRoadmInterfacesImpl.PP_TOKEN, - "" + OpenRoadmInterfacesImpl.PP_TOKEN }; String nodeId = "node1"; @@ -122,59 +139,50 @@ public class DeviceRendererServiceImplTest extends AbstractTest { connectingUsingCrossConnect = false; } - if (connectingUsingCrossConnect != crossConnect) { - continue; - } - List nodes = new ArrayList<>(); - nodes.add(ServiceDataUtils.createNode(nodeId, srcTP, dstTp)); - ServicePathInput servicePathInput = ServiceDataUtils.buildServicePathInputs(nodes); + nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp)); + ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes); for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) { ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput, servicePathDirection); Assert.assertTrue(servicePathOutput.isSuccess()); String expectedResult = "Roadm-connection successfully created for nodes: "; - if (crossConnect) { + if (connectingUsingCrossConnect) { expectedResult = expectedResult + nodeId; } Assert.assertEquals(expectedResult, servicePathOutput.getResult()); Assert.assertEquals(1, servicePathOutput.getNodeInterface().size()); Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId()); + if (!connectingUsingCrossConnect) { // No need to try both directions if not cross connect + break; + } } } } } @Test - public void testRollbackEmptyInterface() { - setMountPoint(new MountPointStub(getDataBroker())); - RendererRollbackInput rendererRollbackInput = ServiceDataUtils.buildRendererRollbackInput(); - RendererRollbackOutput rendererRollbackOutput = - this.deviceRendererService.rendererRollback(rendererRollbackInput); - Assert.assertTrue(rendererRollbackOutput.isSuccess()); - Assert.assertTrue(rendererRollbackOutput.getFailedToRollback().isEmpty()); - } + public void testSetupServiceNulls() throws OpenRoadmInterfaceException { + setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker())); + String nodeId = "node1"; + String srcTP = null; + String dstTp = null; + boolean connectingUsingCrossConnect = true; - @Test - public void testRollbackConnectionIdNotExist() { - setMountPoint(new MountPointStub(getDataBroker())); - - NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder(); - nodeInterfaceBuilder.setNodeId("node1"); - nodeInterfaceBuilder.withKey(new NodeInterfaceKey("node1")); - List connectionID = new ArrayList<>(); - connectionID.add("node1-PP"); - nodeInterfaceBuilder.setConnectionId(connectionID); - List nodeInterfaces = new ArrayList<>(); - nodeInterfaces.add(nodeInterfaceBuilder.build()); - RendererRollbackInputBuilder rendererRollbackInputBuilder = new RendererRollbackInputBuilder(); - rendererRollbackInputBuilder.setNodeInterface(nodeInterfaces); - - RendererRollbackOutput rendererRollbackOutput = - this.deviceRendererService.rendererRollback(rendererRollbackInputBuilder.build()); - Assert.assertFalse(rendererRollbackOutput.isSuccess()); - Assert.assertEquals(1, rendererRollbackOutput.getFailedToRollback().size()); - Assert.assertEquals("node1", rendererRollbackOutput.getFailedToRollback().get(0).getNodeId()); + List nodes = new ArrayList<>(); + nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp)); + ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes); + + for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) { + ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput, + servicePathDirection); + Assert.assertTrue(servicePathOutput.isSuccess()); + String expectedResult = "Roadm-connection successfully created for nodes: "; + expectedResult = expectedResult + nodeId; + Assert.assertEquals(expectedResult, servicePathOutput.getResult()); + Assert.assertEquals(1, servicePathOutput.getNodeInterface().size()); + Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId()); + } } }