Unit test: PCCEndPointIpv4ObjectParser 83/22883/4
authorIveta Halanova <iveta.halanova@pantheon.sk>
Thu, 18 Jun 2015 13:07:07 +0000 (15:07 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 19 Jun 2015 10:00:56 +0000 (10:00 +0000)
Test coverage from 5.6% to 100%

Change-Id: I33855fba9d89d30cfaef9cec325020833d4a41e7
Signed-off-by: Iveta Halanova <iveta.halanova@pantheon.sk>
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCEndPointIpv4ObjectParserTest.java [new file with mode: 0644]

diff --git a/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCEndPointIpv4ObjectParserTest.java b/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCEndPointIpv4ObjectParserTest.java
new file mode 100644 (file)
index 0000000..ce6d862
--- /dev/null
@@ -0,0 +1,56 @@
+package org.opendaylight.protocol.pcep.pcc.mock;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Case;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
+
+public class PCCEndPointIpv4ObjectParserTest {
+
+    private final static String ip1 = "1.2.3.4";
+    private final static String ip2 = "1.2.3.5";
+
+    @Test(expected=PCEPDeserializerException.class)
+    public void testParseEmptyObject() throws PCEPDeserializerException {
+        final ObjectHeader header = new ObjectHeaderImpl(false, false);
+        final ByteBuf bytes = Unpooled.buffer();
+        bytes.writeByte(4);
+        new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
+    }
+
+    @Test
+    public void testParseObject() throws PCEPDeserializerException {
+        final ObjectHeader header = new ObjectHeaderImpl(false, false);
+        final ByteBuf bytes = Unpooled.buffer();
+        bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4Address(this.ip1)));
+        bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4Address(this.ip2)));
+        final EndpointsObj output = (EndpointsObj) new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
+
+        assertEquals(this.ip1, ((Ipv4Case) output.getAddressFamily()).getIpv4().getSourceIpv4Address().getValue());
+        assertEquals(this.ip2, ((Ipv4Case) output.getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue());
+        assertFalse(output.isIgnore());
+        assertFalse(output.isProcessingRule());
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullBytes() throws PCEPDeserializerException {
+        final ObjectHeader header = new ObjectHeaderImpl(false, false);
+        final ByteBuf bytes = null;
+        new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testEmptyBytes() throws PCEPDeserializerException {
+        final ObjectHeader header = new ObjectHeaderImpl(false, false);
+        final ByteBuf bytes = Unpooled.buffer();
+        new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
+    }
+}