Add ByteBufUtils
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPXROSubobjectParserTest.java
index 65c9d74b218b667b473ee383e5c60728d5a81dd3..f11ccd1904b861b410df42872bb80b8d1424d844 100644 (file)
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
-import java.io.IOException;
-import java.util.List;
-
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Test;
-import org.opendaylight.protocol.concepts.Ipv4Util;
-import org.opendaylight.protocol.concepts.Ipv6Util;
-import org.opendaylight.protocol.concepts.SharedRiskLinkGroup;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROIPv4PrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROIPv6PrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
+import org.opendaylight.protocol.pcep.parser.subobject.XROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.parser.subobject.XROIpv4PrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.parser.subobject.XROIpv6PrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.parser.subobject.XROPathKey128SubobjectParser;
+import org.opendaylight.protocol.pcep.parser.subobject.XROPathKey32SubobjectParser;
+import org.opendaylight.protocol.pcep.parser.subobject.XROSRLGSubobjectParser;
+import org.opendaylight.protocol.pcep.parser.subobject.XROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.srlg._case.SrlgBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
 
 public class PCEPXROSubobjectParserTest {
 
-       @Test
-       public void testSerDeser() throws PCEPDeserializerException, IOException {
-               final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfXROSubobjects.bin");
-               final List<ExcludeRouteSubobject> objsToTest = PCEPXROSubobjectParser.parse(bytesFromFile);
-
-               assertEquals(5, objsToTest.size());
-
-               assertEquals(
-                               objsToTest.get(0),
-                               new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 0 }, 16)), true, XROSubobjectAttribute.NODE));
-               assertEquals(
-                               objsToTest.get(1),
-                               new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
-                                               (byte) 0x78, (byte) 0x90, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0x12,
-                                               (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0, (byte) 0 }, 112)), true, XROSubobjectAttribute.INTERFACE));
-               // assertEquals(objsToTest.get(2), new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0,
-               // (byte) 0, (byte) 0,
-               // (byte) 0x20 }), new UnnumberedInterfaceIdentifier(0x1234L), false, XROSubobjectAttribute.SRLG));
-               assertEquals(objsToTest.get(3), new XROAsNumberSubobject(new AsNumber((long) 0x1234), false));
-               assertEquals(objsToTest.get(4), new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
-
-               // assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest));
-
-       }
-
-       @Test
-       public void testDifferentLengthExceptions() {
-               final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data for parsing subobjects
-
-               try {
-                       XROAsNumberSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
-
-               try {
-                       XROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
-
-               try {
-                       XROIPv4PrefixSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
-
-               try {
-                       XROIPv6PrefixSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
-       }
-
-       @Test
-       public void testNullExceptions() throws PCEPDeserializerException {
-               final byte[] bytes = null; // not empty but not enought data for parsing subobjects
-
-               try {
-                       XROAsNumberSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROIPv4PrefixSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROIPv6PrefixSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-       }
-
-       @Test
-       public void testUnknownInstanceExceptions() {
-
-               final ExcludeRouteSubobject instance = new ExcludeRouteSubobject(true) {
-               };
-
-               try {
-                       XROAsNumberSubobjectParser.put(instance);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROUnnumberedInterfaceSubobjectParser.put(instance);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROIPv4PrefixSubobjectParser.put(instance);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       final byte[] ipv6addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
-                                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
-                       XROIPv4PrefixSubobjectParser.put(new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(ipv6addr, 1)), false, XROSubobjectAttribute.INTERFACE));
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROIPv6PrefixSubobjectParser.put(instance);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       final byte[] ipv4addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
-                       XROIPv6PrefixSubobjectParser.put(new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(ipv4addr, 1)), false, XROSubobjectAttribute.INTERFACE));
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-       }
-
-       @Test
-       public void testEmptyExceptions() throws PCEPDeserializerException {
-               final byte[] bytes = {}; // not empty but not enought data for parsing subobjects
-
-               try {
-                       XROAsNumberSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROIPv4PrefixSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       XROIPv6PrefixSubobjectParser.parse(bytes, true);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-       }
-
+    private static final byte[] IP4_PREFIX_BYTES = {
+        (byte) 0x01, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00
+    };
+    private static final byte[] IP6_PREFIX_BYTES = {
+        (byte) 0x82, (byte) 0x14, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+        (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+        (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x01
+    };
+    private static final byte[] SRLG_BYTES = {
+        (byte) 0xa2, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x00, (byte) 0x02
+    };
+    private static final byte[] UNNUMBERED_BYTES = {
+        (byte) 0x84, (byte) 0x0c, (byte) 0x00, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+        (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
+    };
+    private static final byte[] AS_NUMBER_BYTES = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 };
+    private static final byte[] PATH_KEY32_BYTES = {
+        (byte) 0xc0, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00
+    };
+    private static final byte[] PATH_KEY128_BYTES = {
+        (byte) 0xc1, (byte) 0x14, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+        (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00,
+        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+    };
+
+    @Test
+    public void testXROIp4PrefixSubobject() throws PCEPDeserializerException {
+        final XROIpv4PrefixSubobjectParser parser = new XROIpv4PrefixSubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(false);
+        subs.setAttribute(Attribute.Interface);
+        subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(
+            new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build());
+        assertEquals(subs.build(), parser.parseSubobject(
+            Unpooled.wrappedBuffer(ByteArray.cutBytes(IP4_PREFIX_BYTES, 2)), false));
+        final ByteBuf buff = Unpooled.buffer();
+        parser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(IP4_PREFIX_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+    }
+
+    @Test
+    public void testXROIp6PrefixSubobject() throws PCEPDeserializerException {
+        final XROIpv6PrefixSubobjectParser parser = new XROIpv6PrefixSubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(true);
+        subs.setAttribute(Attribute.Node);
+        subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(
+            new IpPrefixBuilder().setIpPrefix(
+                new IpPrefix(Ipv6Util.prefixForBytes(new byte[] {
+                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
+                }, 22)))
+            .build()).build());
+        assertEquals(
+            subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(IP6_PREFIX_BYTES, 2)), true));
+        final ByteBuf buff = Unpooled.buffer();
+        parser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(IP6_PREFIX_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+        }
+    }
+
+    @Test
+    public void testXROSrlgSubobject() throws PCEPDeserializerException {
+        final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(true);
+        subs.setAttribute(Attribute.Srlg);
+        subs.setSubobjectType(
+            new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build()).build());
+        assertEquals(subs.build(),
+            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(SRLG_BYTES, 2)), true));
+        final ByteBuf buff = Unpooled.buffer();
+        parser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(SRLG_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+    }
+
+    @Test
+    public void testXROUnnumberedSubobject() throws PCEPDeserializerException {
+        final XROUnnumberedInterfaceSubobjectParser parser = new XROUnnumberedInterfaceSubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(true);
+        subs.setAttribute(Attribute.Node);
+        subs.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(
+                new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build()).build());
+        assertEquals(
+            subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(UNNUMBERED_BYTES, 2)), true));
+        final ByteBuf buff = Unpooled.buffer();
+        parser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(UNNUMBERED_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+    }
+
+    @Test
+    public void testXROAsNumberSubobject() throws PCEPDeserializerException {
+        final XROAsNumberSubobjectParser parser = new XROAsNumberSubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(true);
+        subs.setSubobjectType(
+            new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build())
+                .build());
+        assertEquals(subs.build(),
+            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(AS_NUMBER_BYTES, 2)), true));
+        final ByteBuf buff = Unpooled.buffer();
+        parser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(AS_NUMBER_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+    }
+
+    @Test
+    public void testXROPathKey32Subobject() throws PCEPDeserializerException {
+        final XROPathKey32SubobjectParser parser = new XROPathKey32SubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(true);
+        final PathKeyBuilder pBuilder = new PathKeyBuilder();
+        pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+        pBuilder.setPathKey(new PathKey(4660));
+        subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
+        assertEquals(subs.build(),
+            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY32_BYTES, 2)), true));
+        final ByteBuf buff = Unpooled.buffer();
+        parser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(PATH_KEY32_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+    }
+
+    @Test
+    public void testXROPathKey128Subobject() throws PCEPDeserializerException {
+        final XROPathKey128SubobjectParser parser = new XROPathKey128SubobjectParser();
+        final SubobjectBuilder subs = new SubobjectBuilder();
+        subs.setMandatory(true);
+        final PathKeyBuilder pBuilder = new PathKeyBuilder();
+        pBuilder.setPceId(new PceId(new byte[] {
+            (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12,
+            (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+        }));
+        pBuilder.setPathKey(new PathKey(4660));
+        subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
+        assertEquals(subs.build(),
+            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY128_BYTES, 2)), true));
+        final ByteBuf buff = Unpooled.buffer();
+        XROPathKey128SubobjectParser.serializeSubobject(subs.build(), buff);
+        assertArrayEquals(PATH_KEY128_BYTES, ByteArray.getAllBytes(buff));
+
+        try {
+            parser.parseSubobject(null, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+        try {
+            parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
+        }
+    }
 }