X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fdevice%2Flistener%2FOpenflowProtocolListenerFullImplTest.java;h=2de02d448ef9364a17c4faca4a33493e5fa4df17;hb=b7a5e5d534f1345d75aa998f8d7feee70c0b9d62;hp=a0c77bf030bf85d698040cf7f1f035d910a20089;hpb=85402516167a7fade85c8c4ee624d6b109611915;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/OpenflowProtocolListenerFullImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/OpenflowProtocolListenerFullImplTest.java index a0c77bf030..2de02d448e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/OpenflowProtocolListenerFullImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/OpenflowProtocolListenerFullImplTest.java @@ -1,26 +1,29 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.device.listener; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +import com.google.common.util.concurrent.Futures; +import java.net.InetSocketAddress; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; -import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder; @@ -35,122 +38,137 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; /** * openflowplugin-impl * org.opendaylight.openflowplugin.impl.connection.listener - *

- * test of {@link OpenflowProtocolListenerFullImpl} - lightweight version, using basic ways (TDD) + * test of {@link OpenflowProtocolListenerFullImpl} - lightweight version, using basic ways (TDD). * - * @author Vaclav Demcak - *

- * Created: Mar 26, 2015 + * @author Vaclav Demcak */ @RunWith(MockitoJUnitRunner.class) public class OpenflowProtocolListenerFullImplTest { - - private OpenflowProtocolListenerFullImpl ofProtocolListener; - @Mock private DeviceReplyProcessor deviceReplyProcessor; @Mock private ConnectionAdapter connectionAdapter; - private final long xid = 42L; + private final Uint32 xid = Uint32.valueOf(42); + + private OpenflowProtocolListenerFullImpl ofProtocolListener; @Before public void setUp() { // place for mocking method's general behavior for HandshakeContext and ConnectionContext ofProtocolListener = new OpenflowProtocolListenerFullImpl(connectionAdapter, deviceReplyProcessor); connectionAdapter.setMessageListener(ofProtocolListener); - Mockito.verify(connectionAdapter).setMessageListener(Matchers.any(OpenflowProtocolListener.class)); + when(connectionAdapter.getRemoteAddress()) + .thenReturn(InetSocketAddress.createUnresolved("ofp-junit.example.org", 6663)); + verify(connectionAdapter).setMessageListener(any(OpenflowProtocolListener.class)); } @After public void tearDown() { - Mockito.verifyNoMoreInteractions(connectionAdapter, deviceReplyProcessor); + verifyNoMoreInteractions(connectionAdapter, deviceReplyProcessor); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onEchoRequestMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onEchoRequestMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage)}. */ @Test public void testOnEchoRequestMessage() { - EchoRequestMessage echoRequestMessage = new EchoRequestMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); - ofProtocolListener.onEchoRequestMessage(echoRequestMessage); + when(connectionAdapter.echoReply(any())).thenReturn(Futures.immediateFuture(null)); + ofProtocolListener.onEchoRequestMessage( + new EchoRequestMessageBuilder().setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build()); - Mockito.verify(connectionAdapter).echoReply(Matchers.any(EchoReplyInput.class)); + verify(connectionAdapter).echoReply(any(EchoReplyInput.class)); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onErrorMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)}. */ @Test public void testOnErrorMessage() { ErrorMessage errorMessage = new ErrorMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); + .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build(); ofProtocolListener.onErrorMessage(errorMessage); - Mockito.verify(deviceReplyProcessor).processReply(Matchers.any(ErrorMessage.class)); + verify(deviceReplyProcessor).processReply(any(ErrorMessage.class)); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onExperimenterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onExperimenterMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage)}. */ @Test public void testOnExperimenterMessage() { ExperimenterMessage experimenterMessage = new ExperimenterMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); + .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build(); ofProtocolListener.onExperimenterMessage(experimenterMessage); - // NOOP + + verify(deviceReplyProcessor).processExperimenterMessage(any()); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onFlowRemovedMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onFlowRemovedMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage)}. */ @Test public void testOnFlowRemovedMessage() { FlowRemovedMessage flowRemovedMessage = new FlowRemovedMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); + .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build(); ofProtocolListener.onFlowRemovedMessage(flowRemovedMessage); - Mockito.verify(deviceReplyProcessor).processFlowRemovedMessage(Matchers.any(FlowRemovedMessage.class)); + verify(deviceReplyProcessor).processFlowRemovedMessage(any(FlowRemovedMessage.class)); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onHelloMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onHelloMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)}. */ @Test public void testOnHelloMessage() { HelloMessage helloMessage = new HelloMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); + .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build(); ofProtocolListener.onHelloMessage(helloMessage); - // NOOP + + verify(connectionAdapter).getRemoteAddress(); + verify(connectionAdapter).disconnect(); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onPacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onPacketInMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}. */ @Test public void testOnPacketInMessage() { PacketInMessage packetInMessage = new PacketInMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); + .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build(); ofProtocolListener.onPacketInMessage(packetInMessage); - Mockito.verify(deviceReplyProcessor).processPacketInMessage(Matchers.any(PacketInMessage.class)); + verify(deviceReplyProcessor).processPacketInMessage(any(PacketInMessage.class)); } /** - * Test method for {@link OpenflowProtocolListenerFullImpl#onPortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}. + * Test method for + * {@link OpenflowProtocolListenerFullImpl#onPortStatusMessage( + * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}. */ @Test public void testOnPortStatusMessage() { PortStatusMessage portStatusMessage = new PortStatusMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build(); + .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build(); ofProtocolListener.onPortStatusMessage(portStatusMessage); - Mockito.verify(deviceReplyProcessor).processPortStatusMessage(Matchers.any(PortStatusMessage.class)); + verify(deviceReplyProcessor).processPortStatusMessage(any(PortStatusMessage.class)); } - }