--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+
+public class ServiceLoaderRSVPExtensionProviderContextTest {
+ @Test(expected = UnsupportedOperationException.class)
+ public void testPrivateConstructor() throws Throwable {
+ final Constructor<ServiceLoaderRSVPExtensionProviderContext> c = ServiceLoaderRSVPExtensionProviderContext.class.getDeclaredConstructor();
+ c.setAccessible(true);
+ try {
+ c.newInstance();
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.LabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+public class SimpleEROSubobjectRegistryTest {
+ private final int subObjectTypeOne = 1;
+ private final ByteBuf input = Unpooled.wrappedBuffer(new byte[]{1, 2, 3});
+ private SimpleEROSubobjectRegistry simpleEROSubobjectRegistry = new SimpleEROSubobjectRegistry();
+ @Mock
+ private EROSubobjectParser rroSubobjectParser;
+ @Mock
+ private EROSubobjectSerializer rroSubobjectSerializer;
+
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ MockitoAnnotations.initMocks(this);
+ this.simpleEROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this.rroSubobjectParser);
+ this.simpleEROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this.rroSubobjectSerializer);
+ Mockito.doReturn(new SubobjectContainerBuilder().build()).when(this.rroSubobjectParser).parseSubobject(this
+ .input, false);
+ final ArgumentCaptor<SubobjectContainer> arg = ArgumentCaptor.forClass(SubobjectContainer.class);
+ final ArgumentCaptor<ByteBuf> bufArg = ArgumentCaptor.forClass(ByteBuf.class);
+ Mockito.doNothing().when(this.rroSubobjectSerializer).serializeSubobject(arg.capture(), bufArg.capture());
+ }
+
+ @Test
+ public void testUnrecognizedType() throws RSVPParsingException {
+ final int wrongType = 99;
+ assertNull(this.simpleEROSubobjectRegistry.parseSubobject(wrongType, this.input, false));
+ final ByteBuf output = Unpooled.EMPTY_BUFFER;
+ final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new
+ LabelCaseBuilder().build()).build();
+ this.simpleEROSubobjectRegistry.serializeSubobject(container, output);
+ assertEquals(0, output.readableBytes());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseWrongType() {
+ final int wrongType = 65536;
+ try {
+ this.simpleEROSubobjectRegistry.parseSubobject(wrongType, this.input, false);
+ } catch (RSVPParsingException e) {
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRegisterWrongType() {
+ final int wrongType = 65536;
+ this.simpleEROSubobjectRegistry.registerSubobjectParser(wrongType, this.rroSubobjectParser);
+ }
+
+ @Test
+ public void testParserRegistration() {
+ assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this
+ .rroSubobjectParser));
+ }
+
+ @Test
+ public void testSerializerRegistration() {
+ assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this
+ .rroSubobjectSerializer));
+ }
+
+ private final class MockRROSubObjectClass implements SubobjectType {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return MockRROSubObjectClass.class;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
+import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+public class SimpleLabelRegistryTest {
+ final short cTypeOne = 1;
+ private final SimpleLabelRegistry simpleLabelRegistry = new SimpleLabelRegistry();
+ private final ByteBuf input = Unpooled.wrappedBuffer(new byte[]{1, 2, 3});
+ @Mock
+ private LabelParser labelParser;
+ @Mock
+ private LabelSerializer labelSerializer;
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ MockitoAnnotations.initMocks(this);
+ this.simpleLabelRegistry.registerLabelParser(cTypeOne, this.labelParser);
+ this.simpleLabelRegistry.registerLabelSerializer(MockLabel.class, this.labelSerializer);
+ Mockito.doReturn(new MockLabel()).when(this.labelParser).parseLabel(this.input);
+ final ArgumentCaptor<LabelType> tlvArg = ArgumentCaptor.forClass(LabelType.class);
+ final ArgumentCaptor<ByteBuf> bufArg = ArgumentCaptor.forClass(ByteBuf.class);
+ Mockito.doNothing().when(this.labelSerializer).serializeLabel(Mockito.anyBoolean(), Mockito.anyBoolean(), tlvArg.capture(), bufArg.capture());
+ }
+
+ @Test
+ public void testParserRegistration() {
+ assertNotNull(this.simpleLabelRegistry.registerLabelParser(cTypeOne, this.labelParser));
+ }
+
+ @Test
+ public void testSerializerRegistration() {
+ assertNotNull(this.simpleLabelRegistry.registerLabelSerializer(MockLabelClass.class, this.labelSerializer));
+ }
+
+ @Test
+ public void testUnrecognizedType() throws RSVPParsingException {
+ final int wrongLabelType = 99;
+ assertNull(this.simpleLabelRegistry.parseLabel(wrongLabelType, this.input));
+ final ByteBuf output = Unpooled.EMPTY_BUFFER;
+ this.simpleLabelRegistry.serializeLabel(false, false, new MockLabel(), output);
+ assertEquals(0, output.readableBytes());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseWrongType() {
+ final int wrongType = 65536;
+ try {
+ this.simpleLabelRegistry.parseLabel(wrongType, this.input);
+ } catch (RSVPParsingException e) {
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRegisterWrongType() {
+ final int wrongType = 65536;
+ this.simpleLabelRegistry.registerLabelParser(wrongType, this.labelParser);
+ }
+
+ @Test
+ public void testParseLabel() throws RSVPParsingException {
+ final LabelType output = this.simpleLabelRegistry.parseLabel(cTypeOne, this.input);
+ assertNotNull(output);
+ assertTrue(output instanceof MockLabel);
+
+ final ByteBuf aggregator = Unpooled.EMPTY_BUFFER;
+ this.simpleLabelRegistry.serializeLabel(false, false, output, aggregator);
+ Mockito.verify(this.labelSerializer).serializeLabel(false, false, output, aggregator);
+ }
+
+ private final class MockLabelClass implements LabelType {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return MockLabelClass.class;
+ }
+ }
+
+ private final class MockLabel implements LabelType {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return MockLabel.class;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCaseBuilder;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+public class SimpleRROSubobjectRegistryTest {
+
+ private final int subObjectTypeOne = 1;
+ private final ByteBuf input = Unpooled.wrappedBuffer(new byte[]{1, 2, 3});
+ private SimpleRROSubobjectRegistry simpleRROSubobjectRegistry = new SimpleRROSubobjectRegistry();
+ @Mock
+ private RROSubobjectParser rroSubobjectParser;
+ @Mock
+ private RROSubobjectSerializer rroSubobjectSerializer;
+
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ MockitoAnnotations.initMocks(this);
+ this.simpleRROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this.rroSubobjectParser);
+ this.simpleRROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this.rroSubobjectSerializer);
+ Mockito.doReturn(new SubobjectContainerBuilder().build()).when(this.rroSubobjectParser).parseSubobject(this.input);
+ final ArgumentCaptor<SubobjectContainer> arg = ArgumentCaptor.forClass(SubobjectContainer.class);
+ final ArgumentCaptor<ByteBuf> bufArg = ArgumentCaptor.forClass(ByteBuf.class);
+ Mockito.doNothing().when(this.rroSubobjectSerializer).serializeSubobject(arg.capture(), bufArg.capture());
+ }
+
+ @Test
+ public void testUnrecognizedType() throws RSVPParsingException {
+ final int wrongType = 99;
+ assertNull(this.simpleRROSubobjectRegistry.parseSubobject(wrongType, this.input));
+ final ByteBuf output = Unpooled.EMPTY_BUFFER;
+ final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new
+ LabelCaseBuilder().build()).build();
+ this.simpleRROSubobjectRegistry.serializeSubobject(container, output);
+ assertEquals(0, output.readableBytes());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseWrongType() {
+ final int wrongType = 65536;
+ try {
+ this.simpleRROSubobjectRegistry.parseSubobject(wrongType, this.input);
+ } catch (RSVPParsingException e) {
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRegisterWrongType() {
+ final int wrongType = 65536;
+ this.simpleRROSubobjectRegistry.registerSubobjectParser(wrongType, this.rroSubobjectParser);
+ }
+
+ @Test
+ public void testParserRegistration() {
+ assertNotNull(this.simpleRROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this
+ .rroSubobjectParser));
+ }
+
+ @Test
+ public void testSerializerRegistration() {
+ assertNotNull(this.simpleRROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this
+ .rroSubobjectSerializer));
+ }
+
+ private final class MockRROSubObjectClass implements SubobjectType {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return MockRROSubObjectClass.class;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.SecondaryExplicitRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.SecondaryExplicitRouteObjectBuilder;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+public class SimpleRSVPObjectRegistryTest {
+ private final int subObjectTypeOne = 1;
+ private final int subObjectCTypeOne = 1;
+ private final ByteBuf input = Unpooled.wrappedBuffer(new byte[]{1, 2, 3});
+ private SimpleRSVPObjectRegistry simpleRSVPObjectRegistry = new SimpleRSVPObjectRegistry();
+ @Mock
+ private RSVPTeObjectParser rsvpTeObjectParser;
+ @Mock
+ private RSVPTeObjectSerializer rsvpTeObjectSerializer;
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ MockitoAnnotations.initMocks(this);
+ this.simpleRSVPObjectRegistry.registerRsvpObjectParser(subObjectTypeOne, subObjectCTypeOne, this.rsvpTeObjectParser);
+ this.simpleRSVPObjectRegistry.registerRsvpObjectSerializer(SecondaryExplicitRouteObject.class, this.rsvpTeObjectSerializer);
+ Mockito.doReturn(new SecondaryExplicitRouteObjectBuilder().build()).when(this.rsvpTeObjectParser).parseObject(this.input);
+ final ArgumentCaptor<RsvpTeObject> arg = ArgumentCaptor.forClass(RsvpTeObject.class);
+ final ArgumentCaptor<ByteBuf> bufArg = ArgumentCaptor.forClass(ByteBuf.class);
+ Mockito.doNothing().when(this.rsvpTeObjectSerializer).serializeObject(arg.capture(), bufArg.capture());
+ }
+
+ @Test
+ public void testParserRegistration() {
+ this.simpleRSVPObjectRegistry.registerRsvpObjectParser(subObjectTypeOne, subObjectCTypeOne, this.rsvpTeObjectParser);
+ }
+
+ @Test
+ public void testSerializerRegistration() {
+ this.simpleRSVPObjectRegistry.registerRsvpObjectSerializer(SecondaryExplicitRouteObject.class, this.rsvpTeObjectSerializer);
+ }
+
+ @Test
+ public void testParseWrongType() throws RSVPParsingException {
+ final int wrongType = 65536;
+ assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(wrongType, subObjectCTypeOne, this.input));
+ }
+
+ @Test
+ public void testUnrecognizedType() throws RSVPParsingException {
+ final int wrongType = 99;
+ assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(wrongType, subObjectCTypeOne, this.input));
+ final ByteBuf output = Unpooled.EMPTY_BUFFER;
+ this.simpleRSVPObjectRegistry.serializeRSPVTe(new SecondaryExplicitRouteObjectBuilder().build(), output);
+ assertEquals(0, output.readableBytes());
+ }
+
+ @Test
+ public void testParseRSVP() throws RSVPParsingException {
+ final RsvpTeObject output = this.simpleRSVPObjectRegistry.parseRSPVTe(subObjectTypeOne, subObjectCTypeOne, this.input);
+ assertNotNull(output);
+ assertTrue(output instanceof SecondaryExplicitRouteObject);
+
+ final ByteBuf aggregator = Unpooled.EMPTY_BUFFER;
+ this.simpleRSVPObjectRegistry.serializeRSPVTe(output, aggregator);
+ Mockito.verify(this.rsvpTeObjectSerializer).serializeObject(output, aggregator);
+ }
+
+
+ @Test
+ public void testRegisterWrongCType() throws RSVPParsingException {
+ final int wrongCType = 65536;
+ assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(subObjectTypeOne, wrongCType, this.input));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRegisterWrongType() {
+ final int wrongType = 65536;
+ this.simpleRSVPObjectRegistry.registerRsvpObjectParser(wrongType, subObjectCTypeOne, this.rsvpTeObjectParser);
+ }
+
+ private final class MockRsvpTeObjectClass implements RsvpTeObject {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return MockRsvpTeObjectClass.class;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.LabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+public class SimpleXROSubobjectRegistryTest {
+ private final int subObjectTypeOne = 1;
+ private final ByteBuf input = Unpooled.wrappedBuffer(new byte[]{1, 2, 3});
+ private SimpleXROSubobjectRegistry simpleXROSubobjectRegistry = new SimpleXROSubobjectRegistry();
+ @Mock
+ private XROSubobjectParser rroSubobjectParser;
+ @Mock
+ private XROSubobjectSerializer rroSubobjectSerializer;
+
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ MockitoAnnotations.initMocks(this);
+ this.simpleXROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this.rroSubobjectParser);
+ this.simpleXROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this.rroSubobjectSerializer);
+ Mockito.doReturn(new SubobjectContainerBuilder().build()).when(this.rroSubobjectParser).parseSubobject(this
+ .input, false);
+ final ArgumentCaptor<SubobjectContainer> arg = ArgumentCaptor.forClass(SubobjectContainer.class);
+ final ArgumentCaptor<ByteBuf> bufArg = ArgumentCaptor.forClass(ByteBuf.class);
+ Mockito.doNothing().when(this.rroSubobjectSerializer).serializeSubobject(arg.capture(), bufArg.capture());
+ }
+
+ @Test
+ public void testUnrecognizedType() throws RSVPParsingException {
+ final int wrongType = 99;
+ assertNull(this.simpleXROSubobjectRegistry.parseSubobject(wrongType, this.input, false));
+ final ByteBuf output = Unpooled.EMPTY_BUFFER;
+ final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new
+ LabelCaseBuilder().build()).build();
+ this.simpleXROSubobjectRegistry.serializeSubobject(container, output);
+ assertEquals(0, output.readableBytes());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseWrongType() {
+ final int wrongType = 65536;
+ try {
+ this.simpleXROSubobjectRegistry.parseSubobject(wrongType, this.input, false);
+ } catch (RSVPParsingException e) {
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRegisterWrongType() {
+ final int wrongType = 65536;
+ this.simpleXROSubobjectRegistry.registerSubobjectParser(wrongType, this.rroSubobjectParser);
+ }
+
+ @Test
+ public void testParserRegistration() {
+ assertNotNull(this.simpleXROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this
+ .rroSubobjectParser));
+ }
+
+ @Test
+ public void testSerializerRegistration() {
+ assertNotNull(this.simpleXROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this
+ .rroSubobjectSerializer));
+ }
+
+ private final class MockRROSubObjectClass implements SubobjectType {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return MockRROSubObjectClass.class;
+ }
+ }
+}
\ No newline at end of file