import io.netty.buffer.UnpooledByteBufAllocator;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
public class SetConfigMessageFactoryTest {
private static final byte MESSAGE_TYPE = 9;
private static final int MESSAGE_LENGTH = 12;
-
+ private SerializerRegistry registry;
+ private OFSerializer<SetConfigInput> setConfigFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ setConfigFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetConfigInput.class));
+ }
+
/**
* Testing of {@link SetConfigMessageFactory} for correct translation from POJO
* @throws Exception
SetConfigInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ setConfigFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort());
SetConfigInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ setConfigFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort());