Search in sources :

Example 1 with SerializerRegistryInjector

use of org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector in project openflowplugin by opendaylight.

the class BundleAddMessageFactoryTest method testSerialize.

private void testSerialize(final boolean withProperty, final BundleInnerMessage innerMessage) {
    final BundleAddMessageOnfBuilder builder = new BundleAddMessageOnfBuilder();
    final OnfAddMessageGroupingDataBuilder dataBuilder = new OnfAddMessageGroupingDataBuilder();
    dataBuilder.setBundleId(new BundleId(1L));
    dataBuilder.setFlags(new BundleFlags(true, false));
    dataBuilder.setBundleInnerMessage(innerMessage);
    if (withProperty) {
        dataBuilder.setBundleProperty(new ArrayList<>(Collections.singleton(BundleTestUtils.createExperimenterProperty(propertyExperimenterData))));
        Mockito.when(registry.getSerializer(Matchers.any())).thenReturn(caseSerializer).thenReturn(propertySerializer);
    } else {
        Mockito.when(registry.getSerializer(Matchers.any())).thenReturn(caseSerializer);
    }
    builder.setOnfAddMessageGroupingData(dataBuilder.build());
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
    factory.serialize(builder.build(), out);
    Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt());
    long padding = out.readUnsignedShort();
    Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());
    Mockito.verify(caseSerializer).serialize(Mockito.any(), Mockito.any());
    if (withProperty) {
        Mockito.verify(propertySerializer).serialize(propertyExperimenterData, out);
    }
}
Also used : BundleId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId) OnfAddMessageGroupingDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.add.message.onf.OnfAddMessageGroupingDataBuilder) SerializerRegistryInjector(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector) ByteBuf(io.netty.buffer.ByteBuf) BundleAddMessageOnfBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleAddMessageOnfBuilder) BundleFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags)

Example 2 with SerializerRegistryInjector

use of org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector in project openflowplugin by opendaylight.

the class ExperimenterInputMessageFactoryTest method startUp.

/**
 * Sets up ExperimenterInputMessageFactory.
 * @param real true if setup should use real registry, false when mock is desired
 */
public void startUp(boolean real) {
    MockitoAnnotations.initMocks(this);
    expFactory = new ExperimenterInputMessageFactory();
    if (real) {
        SerializerRegistry realRegistry = new SerializerRegistryImpl();
        realRegistry.init();
        ((SerializerRegistryInjector) expFactory).injectSerializerRegistry(realRegistry);
    } else {
        ((SerializerRegistryInjector) expFactory).injectSerializerRegistry(registry);
    }
}
Also used : SerializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry) SerializerRegistryInjector(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector) SerializerRegistryImpl(org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl)

Example 3 with SerializerRegistryInjector

use of org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector in project openflowplugin by opendaylight.

the class BundleControlFactoryTest method testSerialize.

private void testSerialize(final boolean withProperty) {
    final OnfControlGroupingDataBuilder dataBuilder = new OnfControlGroupingDataBuilder();
    dataBuilder.setBundleId(new BundleId(1L));
    dataBuilder.setType(BundleControlType.ONFBCTOPENREQUEST);
    dataBuilder.setFlags(new BundleFlags(true, true));
    if (withProperty) {
        dataBuilder.setBundleProperty(new ArrayList<>(Collections.singleton(BundleTestUtils.createExperimenterProperty(propertyExperimenterData))));
        Mockito.when(registry.getSerializer(Matchers.any())).thenReturn(propertySerializer);
        ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
    }
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(new BundleControlOnfBuilder().setOnfControlGroupingData(dataBuilder.build()).build(), out);
    Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt());
    Assert.assertEquals("Wrong type", BundleControlType.ONFBCTOPENREQUEST.getIntValue(), out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
    if (withProperty) {
        Assert.assertEquals("Wrong property type", BundlePropertyType.ONFETBPTEXPERIMENTER.getIntValue(), out.readUnsignedShort());
        // length
        out.readUnsignedShort();
        Assert.assertEquals("Wrong experimenter ID", 1, out.readUnsignedInt());
        Assert.assertEquals("Wrong experimenter type", 2, out.readUnsignedInt());
        Mockito.verify(propertySerializer, Mockito.times(1)).serialize(propertyExperimenterData, out);
    } else {
        Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
    }
}
Also used : BundleId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId) OnfControlGroupingDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.control.onf.OnfControlGroupingDataBuilder) SerializerRegistryInjector(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector) BundleControlOnfBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnfBuilder) ByteBuf(io.netty.buffer.ByteBuf) BundleFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags)

Aggregations

SerializerRegistryInjector (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector)3 ByteBuf (io.netty.buffer.ByteBuf)2 BundleFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags)2 BundleId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId)2 SerializerRegistry (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry)1 SerializerRegistryImpl (org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl)1 BundleAddMessageOnfBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleAddMessageOnfBuilder)1 BundleControlOnfBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnfBuilder)1 OnfAddMessageGroupingDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.add.message.onf.OnfAddMessageGroupingDataBuilder)1 OnfControlGroupingDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.control.onf.OnfControlGroupingDataBuilder)1