List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT
UnpooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.
Click Source Link
From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.ReResetInputFactoryTest.java
License:Open Source License
/** * Testing of {@link ReResetInputFactory} for correct translation from POJO * @throws Exception//from www.ja va 2 s. c o m */ @Test public void testElementsSet() throws Exception { ReResetInputBuilder hib = new ReResetInputBuilder(); BufferHelper.setupHeader(hib, OcpMsgType.valueOf("RESETREQ")); String msgTag = "resetReq"; //set xid Method m_t = hib.getClass().getMethod("setXid", Long.class); m_t.invoke(hib, new Long(0)); ReResetInput hi = hib.build(); LOG.debug("ReResetInputFactoryTest - hi Xid value = {}", hi.getXid()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); reResetFactory.serialize(hi, out); //Verify and check the bytebuf info LOG.debug("ReResetInputFactoryTest - out = {}", out.readableBytes()); byte[] bytes = new byte[out.readableBytes()]; int readerIndex = out.readerIndex(); out.getBytes(readerIndex, bytes); StringBuilder seq = new StringBuilder(""); seq.append("resetReq"); String buf = new String(bytes, "UTF-8"); boolean checkVal = buf.contains(seq); //Check and compare elements Assert.assertEquals("Wrong length", true, checkVal); }
From source file:org.opendaylight.ocpjava.protocol.impl.serialization.factories.SetTimeInputFactoryTest.java
License:Open Source License
/** * Testing of {@link SetTimeInputFactory} for correct translation from POJO * @throws Exception/*from ww w.jav a 2s. com*/ */ @Test public void testElementsSet() throws Exception { SetTimeInputBuilder hib = new SetTimeInputBuilder(); BufferHelper.setupHeader(hib, OcpMsgType.valueOf("SETTIMEREQ")); String testNewTime = "2016-04-26T10:23:00-05:00"; //set tcpLinkMonTimeout Method m_t = hib.getClass().getMethod("setNewTime", XsdDateTime.class); m_t.invoke(hib, new XsdDateTime(testNewTime)); //set xid Method m2_t = hib.getClass().getMethod("setXid", Long.class); m2_t.invoke(hib, new Long(0)); SetTimeInput hi = hib.build(); LOG.debug("HealthCheckInputMessageFactoryTest - hi testNewTime value = {}", hi.getNewTime().getValue().toString()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); setTimeInputFactory.serialize(hi, out); //Verify and check the bytebuf info LOG.debug("SetTimeInputFactoryTest - out = {}", out.readableBytes()); byte[] bytes = new byte[out.readableBytes()]; int readerIndex = out.readerIndex(); out.getBytes(readerIndex, bytes); StringBuilder seq = new StringBuilder(""); seq.append("<newTime>"); seq.append(testNewTime); seq.append("</newTime>"); String buf = new String(bytes, "UTF-8"); boolean checkVal = buf.contains(seq); //Check and compare elements Assert.assertEquals("Wrong length", true, checkVal); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.action.OF13SetFieldActionSerializerTest.java
License:Open Source License
/** * Test identify ExperimenterClass serializer *//*w ww . java 2 s .c om*/ @Test public void test() { OF13SetFieldActionSerializer ser = new OF13SetFieldActionSerializer(); ser.injectSerializerRegistry(registry); org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = new ActionBuilder(); long experimenterId = 12L; ExperimenterIdCaseBuilder expCaseBuilder = new ExperimenterIdCaseBuilder(); ExperimenterBuilder expBuilder = new ExperimenterBuilder(); expBuilder.setExperimenter(new ExperimenterId(experimenterId)); expCaseBuilder.setExperimenter(expBuilder.build()); MatchEntryBuilder meb = new MatchEntryBuilder(); meb.setOxmClass(ExperimenterClass.class); meb.setOxmMatchField(OxmMatchFieldClass.class); meb.setMatchEntryValue(expCaseBuilder.build()); List<MatchEntry> matchEntry = new ArrayList<>(); MatchEntry me = meb.build(); matchEntry.add(me); SetFieldCaseBuilder caseBuilder = new SetFieldCaseBuilder(); SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); setFieldBuilder.setMatchEntry(matchEntry); caseBuilder.setSetFieldAction(setFieldBuilder.build()); actionBuilder.setActionChoice(caseBuilder.build()); MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, ExperimenterClass.class, OxmMatchFieldClass.class); key.setExperimenterId(experimenterId); registry.registerSerializer(key, serializerMock); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); ser.serialize(actionBuilder.build(), out); Mockito.verify(serializerMock, Mockito.times(1)).serialize((MatchEntry) Mockito.anyObject(), (ByteBuf) Mockito.anyObject()); int lenght = out.readableBytes(); Assert.assertEquals("Wrong - bad field code", ActionConstants.SET_FIELD_CODE, out.readUnsignedShort()); Assert.assertEquals("Wrong - bad lenght", lenght, out.readUnsignedShort()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.AbstractBundleMessageFactoryTest.java
License:Open Source License
@Test public void writeBundleFlags() throws Exception { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); AbstractBundleMessageFactory.writeBundleFlags(new BundleFlags(true, true), out); Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactoryTest.java
License:Open Source License
@Test public void testSerializeWithoutProperties() { BundleAddMessageBuilder builder = new BundleAddMessageBuilder(); builder.setBundleId(new BundleId(1L)); builder.setFlags(new BundleFlags(true, false)); Message innerMessage = AbstractBundleMessageFactoryTest.createPortModCase(); builder.setMessage(innerMessage);/*from www. j a v a 2s.co m*/ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(portModSerializer); ((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(portModSerializer, Mockito.times(1)).serialize((PortMod) innerMessage, out); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactoryTest.java
License:Open Source License
@Test public void testSerializeWithExperimenterProperty() { BundleAddMessageBuilder builder = new BundleAddMessageBuilder(); builder.setBundleId(new BundleId(2L)); builder.setFlags(new BundleFlags(true, false)); Message innerMessage = AbstractBundleMessageFactoryTest.createPortModCase(); builder.setMessage(innerMessage);//from www .java 2 s. com BundleExperimenterPropertyData data = AbstractBundleMessageFactoryTest .createBundleExperimenterPropertyData(); builder.setBundleProperty(AbstractBundleMessageFactoryTest.createListWithBundleExperimenterProperty(data)); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(portModSerializer) .thenReturn(propertySerializer); ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry); factory.serialize(builder.build(), out); Assert.assertEquals("Wrong bundle ID", 2L, out.readUnsignedInt()); long padding = out.readUnsignedShort(); Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort()); Mockito.verify(portModSerializer, Mockito.times(1)).serialize((PortMod) innerMessage, out); Mockito.verify(propertySerializer, Mockito.times(1)).serialize(data, out); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleControlFactoryTest.java
License:Open Source License
@Test public void testSerializeWithoutProperties() { BundleControlBuilder builder = new BundleControlBuilder(); builder.setBundleId(new BundleId(1L)); builder.setType(BundleControlType.ONFBCTOPENREQUEST); builder.setFlags(new BundleFlags(true, true)); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(builder.build(), out); Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt()); Assert.assertEquals("Wrong type", BundleControlType.ONFBCTOPENREQUEST.getIntValue(), out.readUnsignedShort());/* w w w . jav a 2 s . c om*/ Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort()); Assert.assertTrue("Unexpected data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleControlFactoryTest.java
License:Open Source License
@Test public void testSerializeWithExperimenterProperty() { BundleControlBuilder builder = new BundleControlBuilder(); builder.setBundleId(new BundleId(3L)); builder.setType(BundleControlType.ONFBCTCOMMITREQUEST); builder.setFlags(new BundleFlags(false, true)); BundleExperimenterPropertyData data = AbstractBundleMessageFactoryTest .createBundleExperimenterPropertyData(); builder.setBundleProperty(AbstractBundleMessageFactoryTest.createListWithBundleExperimenterProperty(data)); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(serializer); ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry); factory.serialize(builder.build(), out); Assert.assertEquals("Wrong bundle ID", 3L, out.readUnsignedInt()); Assert.assertEquals("Wrong type", BundleControlType.ONFBCTCOMMITREQUEST.getIntValue(), out.readUnsignedShort());//from ww w . jav a 2 s .c om Assert.assertEquals("Wrong flags", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong property type", BundlePropertyType.ONFETBPTEXPERIMENTER.getIntValue(), out.readUnsignedShort()); int length = out.readUnsignedShort(); Assert.assertEquals("Wrong experimenter ID", 1, out.readUnsignedInt()); Assert.assertEquals("Wrong experimenter type", 2, out.readUnsignedInt()); Mockito.verify(serializer, Mockito.times(1)).serialize(data, out); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO * @throws Exception //from w w w . j a va 2 s .c o m */ @Test public void test() throws Exception { BarrierInputBuilder bib = new BarrierInputBuilder(); BufferHelper.setupHeader(bib, EncodeConstants.OF13_VERSION_ID); BarrierInput bi = bib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance(); bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi); BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { BarrierOutputBuilder builder = new BarrierOutputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); BarrierOutput message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 8); }