BUG-50: added more object tests.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPNoPathObjectParser.java
index 8d5f41a0b0b80eaf61e902affeaf8610ded703ed..b03de62ff65451dc2000f895850d89b1ee8e5947 100644 (file)
@@ -11,22 +11,20 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
-import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
+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.message.rev131007.pcrep.pcrep.message.replies.result.failure.NoPath;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.pcrep.pcrep.message.replies.result.failure.no.path.Tlvs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
 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.pcrep.message.pcrep.message.replies.result.failure.NoPath;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.Tlvs;
 
 /**
  * Parser for {@link NoPathObject}
  */
-public class PCEPNoPathObjectParser extends AbstractObjectParser<NoPathBuilder> {
+public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<NoPathBuilder> {
 
        public static final int CLASS = 3;
 
@@ -54,15 +52,16 @@ public class PCEPNoPathObjectParser extends AbstractObjectParser<NoPathBuilder>
 
        public static final int C_FLAG_OFFSET = 0;
 
-       public PCEPNoPathObjectParser(final HandlerRegistry registry) {
-               super(registry);
+       public PCEPNoPathObjectParser(final TlvHandlerRegistry tlvReg) {
+               super(tlvReg);
        }
 
        @Override
        public NoPathObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
                        PCEPDocumentedException {
-               if (bytes == null || bytes.length == 0)
+               if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+               }
 
                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
 
@@ -86,19 +85,22 @@ public class PCEPNoPathObjectParser extends AbstractObjectParser<NoPathBuilder>
 
        @Override
        public byte[] serializeObject(final Object object) {
-               if (!(object instanceof NoPathObject))
+               if (!(object instanceof NoPathObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed NoPathObject.");
+               }
 
                final NoPathObject nPObj = (NoPathObject) object;
 
                final byte[] tlvs = serializeTlvs(((NoPath) nPObj).getTlvs());
                int tlvsLength = 0;
-               if (tlvs != null)
+               if (tlvs != null) {
                        tlvsLength = tlvs.length;
-               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               }
+               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
-               if (tlvs != null)
+               if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
+               }
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
                flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
                retBytes[NI_F_OFFSET] = ByteArray.shortToBytes(nPObj.getNatureOfIssue())[1];