import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+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.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
public class HelloInputMessageFactoryTest {
private static final Logger LOGGER = LoggerFactory.getLogger(HelloInputMessageFactoryTest.class);
-
+ private SerializerRegistry registry;
+ private OFSerializer<HelloInput> helloFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ helloFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, HelloInput.class));
+ }
+
/**
* Testing of {@link HelloInputMessageFactory} for correct translation from POJO
* @throws Exception
HelloInput hi = hib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();
- himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);
+ helloFactory.serialize(hi, out);
- BufferHelper.checkHeaderV13(out, himf.getMessageType(), himf.computeLength(hi));
+ BufferHelper.checkHeaderV13(out,(byte) 0, EncodeConstants.OFHEADER_SIZE);
}
/**
HelloInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ helloFactory.serialize(message, out);
LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out));
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 0, 16);
Elements element = readElement(out).get(0);
Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
Elements comparation = createComparationElement(lengthOfBitmap).get(0);
HelloInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ helloFactory.serialize(message, out);
LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out));
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 0, 24);
Elements element = readElement(out).get(0);
Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
Elements comparation = createComparationElement(lengthOfBitmap).get(0);
int elementLength = input.readUnsignedShort();
if (type == HelloElementType.VERSIONBITMAP.getIntValue()) {
elementsBuilder.setType(HelloElementType.forValue(type));
- int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4];
+ int[] versionBitmap = new int[(elementLength - 4) / 4];
for (int i = 0; i < versionBitmap.length; i++) {
versionBitmap[i] = (int) input.readUnsignedInt();
}