BUG-50 : added tests for Keepalive/Close message. 49/2349/1
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 4 Nov 2013 09:38:44 +0000 (10:38 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Mon, 4 Nov 2013 09:38:44 +0000 (10:38 +0100)
Change-Id: I78963897fb65dd95ab191a753f8f16d8021dda05
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/api/src/main/yang/pcep-types.yang
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java
pcep/impl/src/test/resources/PCClose.1.bin [deleted file]
pcep/impl/src/test/resources/PCEPCloseMessage1.bin

index 2c006a97b00dfd8dbb069406e64623b0f9bc35aa..cb6380c79e969cfe6cf1e5629e9faa812ac14350 100644 (file)
@@ -756,15 +756,17 @@ module pcep-types {
                description "CLOSE Object";
                reference "https://tools.ietf.org/html/rfc5440#section-7.17";
 
-               uses object;
-
-               leaf reason {
-                       type uint8;
-                       mandatory true;
-               }
-               
-               container tlvs {
-
+               container c-close {
+                       uses object;
+       
+                       leaf reason {
+                               type uint8;
+                               mandatory true;
+                       }
+                       
+                       container tlvs {
+       
+                       }
                }
        }
 
@@ -1192,9 +1194,7 @@ module pcep-types {
 
                        uses message-header;
 
-                       container c-close {
-                               uses close-object;
-                       }
+                       uses close-object;
                }
        }
 
index 81eca718830a5520ee28b4d478712330f7a73492..dbb4acc5ea2768b0a71eeaca0365f3459c76e889 100644 (file)
@@ -27,7 +27,7 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
        private final static int COMMON_OBJECT_HEADER_LENGTH = 4;
 
        private final static int OC_F_LENGTH = 1;
-       private final static int OT_FLAGS_MF_LENGTH = 1; // multi-field
+       private final static int OT_FLAGS_MF_LENGTH = 1;
        private final static int OBJ_LENGTH_F_LENGTH = 2;
 
        private final static int OC_F_OFFSET = 0;
@@ -67,10 +67,10 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
                final byte[] retBytes = new byte[COMMON_OBJECT_HEADER_LENGTH + valueBytes.length];
 
                // objClass
-               retBytes[OC_F_OFFSET] = (byte) serializer.getObjectClass();
+               retBytes[OC_F_OFFSET] = UnsignedBytes.checkedCast(serializer.getObjectClass());
 
                // objType_flags multi-field
-               retBytes[OT_FLAGS_MF_OFFSET] = (byte) (serializer.getObjectType() << (Byte.SIZE - OT_SF_LENGTH));
+               retBytes[OT_FLAGS_MF_OFFSET] = UnsignedBytes.checkedCast(serializer.getObjectType() << (Byte.SIZE - OT_SF_LENGTH));
                if (object.isProcessingRule()) {
                        retBytes[OT_FLAGS_MF_OFFSET] |= 1 << Byte.SIZE - (P_FLAG_OFFSET) - 1;
                }
@@ -79,11 +79,10 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
                }
 
                // objLength
-               System.arraycopy(ByteArray.intToBytes(valueBytes.length), Integer.SIZE / Byte.SIZE - OBJ_LENGTH_F_LENGTH, retBytes,
-                               OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH);
-
-               System.arraycopy(valueBytes, 0, retBytes, COMMON_OBJECT_HEADER_LENGTH, valueBytes.length);
+               System.arraycopy(ByteArray.intToBytes(valueBytes.length + COMMON_OBJECT_HEADER_LENGTH), Integer.SIZE / Byte.SIZE
+                               - OBJ_LENGTH_F_LENGTH, retBytes, OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH);
 
+               ByteArray.copyWhole(valueBytes, retBytes, COMMON_OBJECT_HEADER_LENGTH);
                return retBytes;
        }
 
@@ -96,7 +95,7 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
                                                + COMMON_OBJECT_HEADER_LENGTH + ".");
                        }
 
-                       final int objClass = ByteArray.bytesToInt(Arrays.copyOfRange(bytes, OC_F_OFFSET, OC_F_OFFSET + OC_F_LENGTH));
+                       final int objClass = UnsignedBytes.toInt(bytes[OC_F_OFFSET]);
 
                        final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(bytes[OT_FLAGS_MF_OFFSET], OT_SF_OFFSET, OT_SF_LENGTH));
 
index 458d6758e1c266da5496a7d89a5be9322b900c27..7667880b7076f6629e5deb1194faf51f422d1b01 100644 (file)
@@ -82,7 +82,6 @@ import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
@@ -111,6 +110,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.error.code.tlv.LspErrorCode;
@@ -289,7 +289,7 @@ public final class Activator implements PCEPExtensionProviderActivator {
                context.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg));
                context.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
                context.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
-               context.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
+               context.registerObjectSerializer(CClose.class, new PCEPCloseObjectParser(tlvReg));
                context.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(eroSubReg));
                context.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
                context.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
index 11de5e9f3ea5920227cf8d1719a629b99c40ef60..61add80e3c17cb838305c98cb407cfabf867a0ba 100644 (file)
@@ -36,7 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
 import org.slf4j.Logger;
@@ -187,7 +187,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
        /**
         * Sends message to serialization.
-        *
+        * 
         * @param msg to be sent
         */
        @Override
@@ -238,7 +238,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
        @Override
        public Tlvs getRemoteTlvs() {
-               return remoteOpen.getTlvs();
+               return this.remoteOpen.getTlvs();
        }
 
        @Override
@@ -268,7 +268,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
        /**
         * Sends PCEP Error Message with one PCEPError and Open Object.
-        *
+        * 
         * @param value
         * @param open
         */
@@ -281,7 +281,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
         * sent (CAPABILITY_NOT_SUPPORTED) and the method checks if the MAX_UNKNOWN_MSG per minute wasn't overstepped.
         * Second, any other error occurred that is specified by rfc. In this case, the an error message is generated and
         * sent.
-        *
+        * 
         * @param error documented error in RFC5440 or draft
         */
        @VisibleForTesting
@@ -302,7 +302,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
        /**
         * Handles incoming message. If the session is up, it notifies the user. The user is notified about every message
         * except KeepAlive.
-        *
+        * 
         * @param msg incoming message
         */
        @Override
index b54e773a817165ca0848c3e0d3cfee9f7537d12d..63c7604eaf2f09636a7800baf3f723efb56bb8ea 100644 (file)
@@ -22,10 +22,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CClose;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
 
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPCloseMessage PCEPCloseMessage}
+ * Parser for {@link CloseMessage}
  */
 public class PCEPCloseMessageParser extends AbstractMessageParser {
 
@@ -55,7 +55,6 @@ public class PCEPCloseMessageParser extends AbstractMessageParser {
                        throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
                }
                final List<Object> objs = parseObjects(buffer);
-
                return validate(objs);
        }
 
@@ -63,19 +62,15 @@ public class PCEPCloseMessageParser extends AbstractMessageParser {
                if (objects == null) {
                        throw new IllegalArgumentException("Passed list can't be null.");
                }
-
                if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) {
                        throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
                }
-
                final Object o = objects.get(0);
                final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build();
                objects.remove(0);
-
                if (!objects.isEmpty()) {
                        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
                }
-
                return new CloseBuilder().setCCloseMessage(msg).build();
        }
 
index 22ebf6e7b661d2938f20037d7b6b34d4ccb4ed35..91ebd82b93966fcf4d51f92631515d05c0c83e60 100644 (file)
@@ -33,7 +33,6 @@ public class PCEPKeepAliveMessageParser extends AbstractMessageParser {
                        throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass()
                                        + ". Nedded KeepaliveMessage.");
                }
-
                buffer.writeBytes(new byte[0]);
        }
 
index d6a608b7887c8255d6eedecab05be26f5428a8cd..111cc078e1d5b090a28d76107e32ac858915a26a 100644 (file)
@@ -11,13 +11,12 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 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.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CClose;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.Tlvs;
 
 import com.google.common.primitives.UnsignedBytes;
 
@@ -52,7 +51,7 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
        }
 
        @Override
-       public CloseObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
+       public CClose parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Byte array is mandatory.");
                }
@@ -71,10 +70,10 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
 
        @Override
        public byte[] serializeObject(final Object object) {
-               if (!(object instanceof CloseObject)) {
+               if (!(object instanceof CClose)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed CloseObject.");
                }
-               final CloseObject obj = (CloseObject) object;
+               final CClose obj = (CClose) object;
 
                final byte[] tlvs = serializeTlvs(obj.getTlvs());
                int tlvsLength = 0;
@@ -86,7 +85,7 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
                if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
                }
-               retBytes[REASON_F_OFFSET] = UnsignedBytes.checkedCast(((CClose) obj).getReason());
+               retBytes[REASON_F_OFFSET] = UnsignedBytes.checkedCast(obj.getReason());
                return retBytes;
        }
 
index 3dab168f8a28dafb8b5fe8802136771a9a219090..84b87829bfb380818364ff651de24827b8563166 100644 (file)
@@ -59,7 +59,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
index ae8ed9cd7ce0baa44893611c9de999f7cd6c2d7c..92f6373fe2c29c1299be89e71cf0c1c8600a7f30 100644 (file)
@@ -7,9 +7,39 @@
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.framework.DeserializerException;
+import org.opendaylight.protocol.framework.DocumentedException;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
 
 public class PCEPValidatorTest {
 
+       private ObjectHandlerRegistry objectRegistry;
+
+       @Before
+       public void setUp() throws Exception {
+               this.objectRegistry = PCEPExtensionProviderContextImpl.create().getObjectHandlerRegistry();
+       }
+
        // private static final LspaObject lspa = new PCEPLspaObject(0L, 0L, 0L, (short) 0, (short) 0, false, false, false,
        // false);
        //
@@ -38,21 +68,6 @@ public class PCEPValidatorTest {
        // private final PCEPEndPointsObject<IPv4Address> endPoints = new PCEPEndPointsObject<IPv4Address>(this.ip4addr,
        // this.ip4addr);
        //
-       // private static final RawPCEPMessageFactory msgFactory = new RawPCEPMessageFactory();
-       //
-       // // private final PCEPClassTypeObject classType = new
-       // // PCEPClassTypeObject((short) 7);
-       // // private final PCEPClassTypeObjectProvider classTypeProvider = new
-       // // PCEPClassTypeObjectProvider((short) 7, true);
-       //
-       // private static List<Message> deserMsg(final String srcFile) throws IOException, DeserializerException,
-       // DocumentedException,
-       // PCEPDeserializerException {
-       // final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
-       // final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytesFromFile).get(0);
-       //
-       // return PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects());
-       // }
        //
        // @Test
        // public void testOpenMessageValidationFromBin() throws IOException, DeserializerException, DocumentedException,
@@ -73,34 +88,34 @@ public class PCEPValidatorTest {
        // new LSPStateDBVersionTlv(53))))).toString());
        // }
        //
-       // @Test
-       // public void testKeepAliveMessageValidationFromBin() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException,
-       // DeserializerException, DocumentedException {
-       // assertEquals(deserMsg("src/test/resources/PCEPKeepAliveMessage1.bin").toString(),
-       // asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString());
-       // assertEquals(deserMsg("src/test/resources/Keepalive.1.bin").toString(),
-       // asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString());
-       // }
-       //
-       // @Test
-       // @Ignore
-       // // FIXME: should be fixed when we remove PCEPObject
-       // public void testCloseMsg() throws PCEPDeserializerException, IOException, PCEPDocumentedException,
-       // DeserializerException,
-       // DocumentedException {
-       // assertEquals(
-       // deserMsg("src/test/resources/PCEPCloseMessage1.bin"),
-       // asList(new CloseBuilder().setCCloseMessage(
-       // new CCloseMessageBuilder().setCClose(
-       // new CCloseBuilder().setReason(TerminationReason.TooManyUnknownMsg.getShortValue()).build()).build()).build()));
-       // assertEquals(
-       // deserMsg("src/test/resources/Close.1.bin").toString(),
-       // asList(new CloseBuilder().setCCloseMessage(
-       // new CCloseMessageBuilder().setCClose(
-       // new CCloseBuilder().setReason(TerminationReason.Unknown.getShortValue()).build()).build()).build()));
-       // }
-       //
+
+       @Test
+       public void testKeepAliveMessageValidationFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException,
+                       DeserializerException, DocumentedException {
+               final byte[] result = new byte[] { 0, 0, 0, 0 };
+               final PCEPKeepAliveMessageParser parser = new PCEPKeepAliveMessageParser(this.objectRegistry);
+               final KeepaliveBuilder builder = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build());
+
+               assertEquals(builder.build(), parser.parseMessage(result));
+               final ByteBuf buf = Unpooled.buffer(result.length);
+               parser.serializeMessage(builder.build(), buf);
+               assertArrayEquals(result, buf.array());
+       }
+
+       @Test
+       public void testCloseMsg() throws PCEPDeserializerException, IOException, PCEPDocumentedException, DeserializerException,
+                       DocumentedException {
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin");
+
+               final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
+               final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(
+                               new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason((short) 5).build()).build());
+
+               assertEquals(builder.build(), parser.parseMessage(result));
+               final ByteBuf buf = Unpooled.buffer(result.length);
+               parser.serializeMessage(builder.build(), buf);
+               assertArrayEquals(result, buf.array());
+       }
        // @Test
        // public void testRequestMessageValidationFromBin() throws IOException, PCEPDeserializerException,
        // PCEPDocumentedException,
diff --git a/pcep/impl/src/test/resources/PCClose.1.bin b/pcep/impl/src/test/resources/PCClose.1.bin
deleted file mode 100644 (file)
index 0d69f0e..0000000
Binary files a/pcep/impl/src/test/resources/PCClose.1.bin and /dev/null differ
index e7f5a7d568c895c02dcdc3cee8c2c17698ab5cda..29dab1a54dd6109d95c9753026bfdf9e6dfb027d 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPCloseMessage1.bin and b/pcep/impl/src/test/resources/PCEPCloseMessage1.bin differ