From 2eabec589d64e5da79a79c71a41183da954d5b67 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Tue, 21 Oct 2014 12:36:46 +0200 Subject: [PATCH] Increased unit test coverage for the rest of deserialization factories Change-Id: I6dcf3094071fcb8013084469574dc0af48f293bf Signed-off-by: Michal Polkorab --- .../GetAsyncReplyMessageFactoryTest.java | 32 +++++------- .../OF10PacketInMessageFactoryTest.java | 12 ++++- .../PortStatusMessageFactoryTest.java | 29 ++++++++++- .../MultipartReplyExperimenterTest.java | 14 +---- .../OF10StatsReplyExperimenterTest.java | 52 +++++++++++++++++++ 5 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java index 6dd6558d..937f7d8c 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java @@ -57,29 +57,27 @@ public class GetAsyncReplyMessageFactoryTest { */ @Test public void testGetAsyncReplyMessage() { - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 06 "+ - "00 00 00 05 "+ + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 07 "+ + "00 00 00 00 "+ "00 00 00 07 "+ "00 00 00 00 "+ - "00 00 00 03 "+ - "00 00 00 0A"); + "00 00 00 0F "+ + "00 00 00 00"); GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong packetInMask",createPacketInMask(), - builtByFactory.getPacketInMask()); - Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), - builtByFactory.getPortStatusMask()); - Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), - builtByFactory.getFlowRemovedMask()); + Assert.assertEquals("Wrong packetInMask",createPacketInMask(), builtByFactory.getPacketInMask()); + Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), builtByFactory.getPortStatusMask()); + Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), builtByFactory.getFlowRemovedMask()); } - + private static List createPacketInMask() { List inMasks = new ArrayList<>(); PacketInMaskBuilder maskBuilder; // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER maskBuilder = new PacketInMaskBuilder(); List reasons = new ArrayList<>(); + reasons.add(PacketInReason.OFPRNOMATCH); reasons.add(PacketInReason.OFPRACTION); reasons.add(PacketInReason.OFPRINVALIDTTL); maskBuilder.setMask(reasons); @@ -87,13 +85,11 @@ public class GetAsyncReplyMessageFactoryTest { // OFPCR_ROLE_SLAVE maskBuilder = new PacketInMaskBuilder(); reasons = new ArrayList<>(); - reasons.add(PacketInReason.OFPRNOMATCH); - reasons.add(PacketInReason.OFPRINVALIDTTL); maskBuilder.setMask(reasons); inMasks.add(maskBuilder.build()); return inMasks; } - + private static List createPortStatusMask() { List inMasks = new ArrayList<>(); PortStatusMaskBuilder maskBuilder; @@ -111,7 +107,7 @@ public class GetAsyncReplyMessageFactoryTest { inMasks.add(maskBuilder.build()); return inMasks; } - + private static List createFlowRemovedMask() { List inMasks = new ArrayList<>(); FlowRemovedMaskBuilder maskBuilder; @@ -120,15 +116,15 @@ public class GetAsyncReplyMessageFactoryTest { List reasons = new ArrayList<>(); reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT); reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); + reasons.add(FlowRemovedReason.OFPRRDELETE); + reasons.add(FlowRemovedReason.OFPRRGROUPDELETE); maskBuilder.setMask(reasons); inMasks.add(maskBuilder.build()); // OFPCR_ROLE_SLAVE maskBuilder = new FlowRemovedMaskBuilder(); reasons = new ArrayList<>(); - reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); - reasons.add(FlowRemovedReason.OFPRRGROUPDELETE); maskBuilder.setMask(reasons); inMasks.add(maskBuilder.build()); return inMasks; } -} +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java index a632ba45..62387806 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java @@ -56,4 +56,14 @@ public class OF10PacketInMessageFactoryTest { Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); } -} + /** + * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO + */ + @Test + public void testWithNoAdditionalData(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00"); + PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); + + Assert.assertNull("Wrong data", builtByFactory.getData()); + } +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java index b538e856..cf0499ae 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java @@ -91,4 +91,31 @@ public class PortStatusMessageFactoryTest { Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue()); Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue()); } -} + + /** + * Testing {@link PortStatusMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDifferentBitmaps(){ + ByteBuf bb = BufferHelper.buildBuffer("01 00 00 00 00 00 00 00 " + //reason, padding + "00 01 02 03 00 00 00 00 " + //port no, padding + "08 00 27 00 B0 EB 00 00 " + //mac address, padding + "73 31 2d 65 74 68 31 00 00 00 00 00 00 00 00 00 " + // port name, String "s1-eth1" + "00 00 00 24 " + //port config + "00 00 00 02 " + //port state + "00 00 00 81 00 00 00 A1 " + //current + advertised features + "00 00 FF FF 00 00 00 00 " + //supported + peer features + "00 00 00 81 00 00 00 80" //curr speed, max speed + ); + PortStatusMessage message = BufferHelper.deserialize(statusFactory, bb); + + Assert.assertEquals("Wrong portConfig", new PortConfig(true, false, true, false), message.getConfig()); + Assert.assertEquals("Wrong portState", new PortState(true, false, false), message.getState()); + Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true), + message.getSupportedFeatures()); + Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false, + false, false, false, false, false, false, false, false, false, false, + false, false), message.getPeerFeatures()); + } +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/MultipartReplyExperimenterTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/MultipartReplyExperimenterTest.java index 61110453..6e4de3f9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/MultipartReplyExperimenterTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/MultipartReplyExperimenterTest.java @@ -40,18 +40,8 @@ public class MultipartReplyExperimenterTest { @Test public void testMultipartReplyExperimenter() { factory.injectDeserializerRegistry(registry); - ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "+ - "00 00 00 0F "+// types - "00 00 00 0F "+// capabilities - "00 00 00 01 "+// max groups - "00 00 00 02 "+// max groups - "00 00 00 03 "+// max groups - "00 00 00 04 "+// max groups - "0F FF 98 01 "+// actions bitmap (all actions included) - "00 00 00 00 "+// actions bitmap (no actions included) - "00 00 00 00 "+// actions bitmap (no actions included) - "00 00 00 00"// actions bitmap (no actions included) - ); + ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 " + + "00 00 00 01 00 00 00 02"); // expID, expType MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb); BufferHelper.checkHeaderV13(builtByFactory); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java new file mode 100644 index 00000000..6ef4153d --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.deserialization.factories.multipart; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +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.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; + +/** + * @author michal.polkorab + * + */ +@RunWith(MockitoJUnitRunner.class) +public class OF10StatsReplyExperimenterTest { + + @Mock DeserializerRegistry registry; + + /** + * Tests {@link OF10StatsReplyMessageFactory} for experimenter body translation + */ + @Test + public void test() { + OF10StatsReplyMessageFactory factory = new OF10StatsReplyMessageFactory(); + factory.injectDeserializerRegistry(registry); + + ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 " + + "00 00 00 01"); // expID + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong type", 65535, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + Mockito.verify(registry, Mockito.times(1)).getDeserializer(Matchers.any(MessageCodeKey.class)); + } +} \ No newline at end of file -- 2.36.6