import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
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.OfId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
public class AbstractObjectWithTlvsTest {
+ private static final EnterpriseNumber EN = new EnterpriseNumber(0L);
+
private Tlv tlv;
+ private VendorInformationTlv viTlv;
+
@Mock
private TlvRegistry tlvRegistry;
}
@Override
- public Object parseObject(ObjectHeader header, ByteBuf buffer) throws PCEPDeserializerException {
+ public Object parseObject(ObjectHeader header, ByteBuf buffer) {
return null;
}
protected void addVendorInformationTlvs(TlvsBuilder builder, List<VendorInformationTlv> tlvs) {
builder.setVendorInformationTlv(tlvs);
}
- };
+ }
@Before
public void setUp() throws PCEPDeserializerException {
MockitoAnnotations.initMocks(this);
this.tlv = new OfListBuilder().setCodes(Lists.newArrayList(new OfId(10))).build();
+ this.viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(EN).build();
+ Mockito.doNothing().when(this.viTlvRegistry).serializeVendorInformationTlv(Mockito.any(VendorInformationTlv.class), Mockito.any(ByteBuf.class));
+ Mockito.doReturn(Optional.of(this.viTlv)).when(this.viTlvRegistry).parseVendorInformationTlv(EN, Unpooled.wrappedBuffer(new byte[0]));
Mockito.doNothing().when(this.tlvRegistry).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));
Mockito.doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 }));
}
ByteBuf buffer = Unpooled.buffer();
a.serializeTlv(this.tlv, buffer);
- Mockito.verify(this.tlvRegistry, Mockito.only()).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));;
+ Mockito.verify(this.tlvRegistry, Mockito.only()).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));
TlvsBuilder b = new TlvsBuilder();
a.parseTlvs(b, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 }));
assertEquals(this.tlv, b.getOfList());
}
+
+ @Test
+ public void testParseVendorInformationTlv() throws PCEPDeserializerException {
+ final Abs parser = new Abs(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf buffer = Unpooled.buffer();
+
+ parser.serializeVendorInformationTlvs(Lists.newArrayList(this.viTlv), buffer);
+ Mockito.verify(this.viTlvRegistry, Mockito.only()).serializeVendorInformationTlv(Mockito.any(VendorInformationTlv.class), Mockito.any(ByteBuf.class));
+
+ final TlvsBuilder tlvsBuilder = new TlvsBuilder();
+ parser.parseTlvs(tlvsBuilder, Unpooled.wrappedBuffer(new byte[] { 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 }));
+ assertEquals(this.viTlv, tlvsBuilder.getVendorInformationTlv().get(0));
+ }
}