package org.opendaylight.protocol.rsvp.parser.spi.pojo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
+import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
+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.protocol.rsvp.parser.spi.RSVPTeObjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
+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.RsvpTeObject;
+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.exclude.route.object.exclude.route.object.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
public class ServiceLoaderRSVPExtensionProviderContextTest {
+
+ private final SimpleRSVPExtensionProviderContext context = (SimpleRSVPExtensionProviderContext) ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance();
+
+ private final RSVPTeObjectParser rsvpTeParser = Mockito.mock(RSVPTeObjectParser.class);
+ private final RSVPTeObjectSerializer rsvpTeSerializer = Mockito.mock(RSVPTeObjectSerializer.class);
+ private final RsvpTeObject parsedRsvpTeObj = Mockito.mock(RsvpTeObject.class);
+
+ private final XROSubobjectParser xroObjParser = Mockito.mock(XROSubobjectParser.class);
+ private final XROSubobjectSerializer xroObjSerializer = Mockito.mock(XROSubobjectSerializer.class);
+ private final SubobjectContainer subObj = Mockito.mock(SubobjectContainer.class);
+ private final SubobjectType subObjType = Mockito.mock(SubobjectType.class);
+
+ private final RROSubobjectParser rroParser = Mockito.mock(RROSubobjectParser.class);
+ private final RROSubobjectSerializer rroSerializer = Mockito.mock(RROSubobjectSerializer.class);
+ private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer rroSubObj = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer.class);
+ private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType rroSubObjType = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType.class);
+
+ private final EROSubobjectParser eroParser = Mockito.mock(EROSubobjectParser.class);
+ private final EROSubobjectSerializer eroSerializer = Mockito.mock(EROSubobjectSerializer.class);
+ private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer eroSubObj = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer.class);
+
+ private final LabelParser labelParser = Mockito.mock(LabelParser.class);
+ private final LabelSerializer labelSerializer = Mockito.mock(LabelSerializer.class);
+ private final LabelType labelType = Mockito.mock(LabelType.class);
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ Mockito.doReturn(this.parsedRsvpTeObj).when(this.rsvpTeParser).parseObject(Mockito.any(ByteBuf.class));
+ Mockito.doReturn(RsvpTeObject.class).when(this.parsedRsvpTeObj).getImplementedInterface();
+ Mockito.doReturn("parsedRsvpTeObj").when(this.parsedRsvpTeObj).toString();
+ Mockito.doNothing().when(this.rsvpTeSerializer).serializeObject(Mockito.any(RsvpTeObject.class), Mockito.any(ByteBuf.class));
+
+ Mockito.doReturn(this.subObj).when(this.xroObjParser).parseSubobject(Mockito.any(ByteBuf.class), Mockito.any(Boolean.class));
+ Mockito.doReturn(this.subObjType).when(this.subObj).getSubobjectType();
+ Mockito.doReturn("SubobjectContainer").when(this.subObj).toString();
+ Mockito.doReturn(SubobjectType.class).when(this.subObjType).getImplementedInterface();
+ Mockito.doNothing().when(this.xroObjSerializer).serializeSubobject(Mockito.any(SubobjectContainer.class), Mockito.any(ByteBuf.class));
+
+ Mockito.doReturn(this.rroSubObj).when(this.rroParser).parseSubobject(Mockito.any(ByteBuf.class));
+ Mockito.doReturn(this.rroSubObjType).when(this.rroSubObj).getSubobjectType();
+ Mockito.doReturn("SubobjectContainer").when(this.rroSubObj).toString();
+ Mockito.doReturn(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType.class).when(this.rroSubObjType).getImplementedInterface();
+ Mockito.doNothing().when(this.rroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer.class), Mockito.any(ByteBuf.class));
+
+ Mockito.doReturn(this.eroSubObj).when(this.eroParser).parseSubobject(Mockito.any(ByteBuf.class), Mockito.any(Boolean.class));
+ Mockito.doReturn(this.subObjType).when(this.eroSubObj).getSubobjectType();
+ Mockito.doReturn("EROSubobjectContainer").when(this.eroSubObj).toString();
+ Mockito.doReturn(SubobjectType.class).when(this.subObjType).getImplementedInterface();
+ Mockito.doNothing().when(this.eroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer.class), Mockito.any(ByteBuf.class));
+
+ Mockito.doReturn(this.labelType).when(this.labelParser).parseLabel(Mockito.any(ByteBuf.class));
+ Mockito.doReturn(LabelType.class).when(this.labelType).getImplementedInterface();
+ Mockito.doReturn("LabelType").when(this.labelType).toString();
+ Mockito.doNothing().when(this.labelSerializer).serializeLabel(Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(LabelType.class), Mockito.any(ByteBuf.class));
+ }
+
+ @Test
+ public void testReferenceCache() {
+ assertNotNull(this.context.getReferenceCache());
+ }
+
+ @Test
+ public void testServiceForRsvpObject() throws RSVPParsingException {
+ this.context.registerRsvpObjectParser(1, 1, this.rsvpTeParser);
+ final ByteBuf buffer = Unpooled.buffer();
+ assertEquals(this.parsedRsvpTeObj, this.context.getRsvpRegistry().parseRSPVTe(1, 1, buffer));
+ this.context.registerRsvpObjectSerializer(RsvpTeObject.class, this.rsvpTeSerializer);
+ this.context.getRsvpRegistry().serializeRSPVTe(this.parsedRsvpTeObj, buffer);
+ Mockito.verify(this.rsvpTeSerializer).serializeObject(Mockito.any(RsvpTeObject.class), Mockito.any(ByteBuf.class));
+ }
+
+ @Test
+ public void testServiceForXROSubobject() throws RSVPParsingException {
+ this.context.registerXROSubobjectParser(2, this.xroObjParser);
+ final ByteBuf buffer = Unpooled.buffer();
+ assertEquals(this.subObj, this.context.getXROSubobjectHandlerRegistry().parseSubobject(2, buffer, false));
+ this.context.registerXROSubobjectSerializer(SubobjectType.class, this.xroObjSerializer);
+ this.context.getXROSubobjectHandlerRegistry().serializeSubobject(this.subObj, buffer);
+ Mockito.verify(this.xroObjSerializer).serializeSubobject(this.subObj, buffer);
+ }
+
+ @Test
+ public void testServiceForRROSubobject() throws RSVPParsingException {
+ this.context.registerRROSubobjectParser(3, this.rroParser);
+ final ByteBuf buffer = Unpooled.buffer();
+ assertEquals(this.rroSubObj, this.context.getRROSubobjectHandlerRegistry().parseSubobject(3, buffer));
+ this.context.registerRROSubobjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType.class, this.rroSerializer);
+ this.context.getRROSubobjectHandlerRegistry().serializeSubobject(this.rroSubObj, buffer);
+ Mockito.verify(this.rroSerializer).serializeSubobject(this.rroSubObj, buffer);
+ }
+
+ @Test
+ public void testServiceForEROSubobject() throws RSVPParsingException {
+ this.context.registerEROSubobjectParser(4, this.eroParser);
+ final ByteBuf buffer = Unpooled.buffer();
+ assertEquals(this.eroSubObj, this.context.getEROSubobjectHandlerRegistry().parseSubobject(4, buffer, false));
+ this.context.registerEROSubobjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType.class, this.eroSerializer);
+ this.context.getEROSubobjectHandlerRegistry().serializeSubobject(this.eroSubObj, buffer);
+ Mockito.verify(this.eroSerializer).serializeSubobject(this.eroSubObj, buffer);
+ }
+
+ @Test
+ public void testServiceForLabel() throws RSVPParsingException {
+ this.context.registerLabelParser(5, this.labelParser);
+ final ByteBuf buffer = Unpooled.buffer();
+ assertEquals(this.labelType, this.context.getLabelHandlerRegistry().parseLabel(5, buffer));
+ this.context.registerLabelSerializer(LabelType.class, this.labelSerializer);
+ this.context.getLabelHandlerRegistry().serializeLabel(false, false, this.labelType, buffer);
+ Mockito.verify(this.labelSerializer).serializeLabel(false, false, this.labelType, buffer);
+ }
+
@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) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
+
}
\ No newline at end of file
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.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
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.LabelCase;
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();
+ private final SimpleEROSubobjectRegistry simpleEROSubobjectRegistry = new SimpleEROSubobjectRegistry();
@Mock
private EROSubobjectParser rroSubobjectParser;
@Mock
@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);
+ this.simpleEROSubobjectRegistry.registerSubobjectParser(this.subObjectTypeOne, this.rroSubobjectParser);
+ 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());
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ final Object[] args = invocation.getArguments();
+ ((ByteBuf) args[1]).writeBoolean(Boolean.TRUE);
+ return null;
+ }
+ }).when(this.rroSubobjectSerializer).serializeSubobject(arg.capture(), bufArg.capture());
}
@Test
final int wrongType = 65536;
try {
this.simpleEROSubobjectRegistry.parseSubobject(wrongType, this.input, false);
- } catch (RSVPParsingException e) {
+ } catch (final RSVPParsingException e) {
}
}
}
@Test
- public void testParserRegistration() {
- assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this
+ public void testParserRegistration() throws RSVPParsingException {
+ assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectParser(this.subObjectTypeOne, this
.rroSubobjectParser));
+ assertNotNull(this.simpleEROSubobjectRegistry.parseSubobject(this.subObjectTypeOne, this.input, false));
}
@Test
public void testSerializerRegistration() {
- assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this
+ assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectSerializer(LabelCase.class, this
.rroSubobjectSerializer));
+ final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new
+ LabelCaseBuilder().build()).build();
+ final ByteBuf output = Unpooled.buffer();
+ this.simpleEROSubobjectRegistry.serializeSubobject(container, output);
+ assertEquals(1, output.readableBytes());
}
- private final class MockRROSubObjectClass implements SubobjectType {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return MockRROSubObjectClass.class;
- }
- }
}
\ No newline at end of file
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.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
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.LabelCase;
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();
+ private final SimpleRROSubobjectRegistry simpleRROSubobjectRegistry = new SimpleRROSubobjectRegistry();
@Mock
private RROSubobjectParser rroSubobjectParser;
@Mock
@Before
public void setUp() throws RSVPParsingException {
MockitoAnnotations.initMocks(this);
- this.simpleRROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this.rroSubobjectParser);
- this.simpleRROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this.rroSubobjectSerializer);
+ this.simpleRROSubobjectRegistry.registerSubobjectParser(this.subObjectTypeOne, this.rroSubobjectParser);
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());
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ final Object[] args = invocation.getArguments();
+ ((ByteBuf) args[1]).writeBoolean(Boolean.TRUE);
+ return null;
+ }
+ }).when(this.rroSubobjectSerializer).serializeSubobject(arg.capture(), bufArg.capture());
}
@Test
final int wrongType = 65536;
try {
this.simpleRROSubobjectRegistry.parseSubobject(wrongType, this.input);
- } catch (RSVPParsingException e) {
+ } catch (final RSVPParsingException e) {
}
}
}
@Test
- public void testParserRegistration() {
- assertNotNull(this.simpleRROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this
+ public void testParserRegistration() throws RSVPParsingException {
+ assertNotNull(this.simpleRROSubobjectRegistry.registerSubobjectParser(this.subObjectTypeOne, this
.rroSubobjectParser));
+ assertNotNull(this.simpleRROSubobjectRegistry.parseSubobject(this.subObjectTypeOne, this.input));
}
@Test
public void testSerializerRegistration() {
- assertNotNull(this.simpleRROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this
+ assertNotNull(this.simpleRROSubobjectRegistry.registerSubobjectSerializer(LabelCase.class, this
.rroSubobjectSerializer));
+ final ByteBuf output = Unpooled.buffer();
+ final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new
+ LabelCaseBuilder().build()).build();
+ this.simpleRROSubobjectRegistry.serializeSubobject(container, output);
+ assertEquals(1, output.readableBytes());
}
- private final class MockRROSubObjectClass implements SubobjectType {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return MockRROSubObjectClass.class;
- }
- }
}
\ No newline at end of file
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.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();
+ private final SimpleRSVPObjectRegistry simpleRSVPObjectRegistry = new SimpleRSVPObjectRegistry();
@Mock
private RSVPTeObjectParser rsvpTeObjectParser;
@Mock
@Before
public void setUp() throws RSVPParsingException {
MockitoAnnotations.initMocks(this);
- this.simpleRSVPObjectRegistry.registerRsvpObjectParser(subObjectTypeOne, subObjectCTypeOne, this.rsvpTeObjectParser);
+ this.simpleRSVPObjectRegistry.registerRsvpObjectParser(this.subObjectTypeOne, this.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);
@Test
public void testParserRegistration() {
- this.simpleRSVPObjectRegistry.registerRsvpObjectParser(subObjectTypeOne, subObjectCTypeOne, this.rsvpTeObjectParser);
+ this.simpleRSVPObjectRegistry.registerRsvpObjectParser(this.subObjectTypeOne, this.subObjectCTypeOne, this.rsvpTeObjectParser);
}
@Test
@Test
public void testParseWrongType() throws RSVPParsingException {
final int wrongType = 65536;
- assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(wrongType, subObjectCTypeOne, this.input));
+ assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(wrongType, this.subObjectCTypeOne, this.input));
}
@Test
public void testUnrecognizedType() throws RSVPParsingException {
final int wrongType = 99;
- assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(wrongType, subObjectCTypeOne, this.input));
+ assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(wrongType, this.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);
+ final RsvpTeObject output = this.simpleRSVPObjectRegistry.parseRSPVTe(this.subObjectTypeOne, this.subObjectCTypeOne, this.input);
assertNotNull(output);
assertTrue(output instanceof SecondaryExplicitRouteObject);
@Test
public void testRegisterWrongCType() throws RSVPParsingException {
final int wrongCType = 65536;
- assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(subObjectTypeOne, wrongCType, this.input));
+ assertNull(this.simpleRSVPObjectRegistry.parseRSPVTe(this.subObjectTypeOne, wrongCType, this.input));
}
@Test(expected = IllegalArgumentException.class)
public void testRegisterWrongType() {
final int wrongType = 65536;
- this.simpleRSVPObjectRegistry.registerRsvpObjectParser(wrongType, subObjectCTypeOne, this.rsvpTeObjectParser);
+ this.simpleRSVPObjectRegistry.registerRsvpObjectParser(wrongType, this.subObjectCTypeOne, this.rsvpTeObjectParser);
}
- private final class MockRsvpTeObjectClass implements RsvpTeObject {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return MockRsvpTeObjectClass.class;
- }
- }
}
\ No newline at end of file
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.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
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.LabelCase;
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();
+ private final SimpleXROSubobjectRegistry simpleXROSubobjectRegistry = new SimpleXROSubobjectRegistry();
@Mock
private XROSubobjectParser rroSubobjectParser;
@Mock
@Before
public void setUp() throws RSVPParsingException {
MockitoAnnotations.initMocks(this);
- this.simpleXROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this.rroSubobjectParser);
- this.simpleXROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this.rroSubobjectSerializer);
+ this.simpleXROSubobjectRegistry.registerSubobjectParser(this.subObjectTypeOne, this.rroSubobjectParser);
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());
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ final Object[] args = invocation.getArguments();
+ ((ByteBuf) args[1]).writeBoolean(Boolean.TRUE);
+ return null;
+ }
+ }).when(this.rroSubobjectSerializer).serializeSubobject(arg.capture(), bufArg.capture());
}
@Test
final int wrongType = 65536;
try {
this.simpleXROSubobjectRegistry.parseSubobject(wrongType, this.input, false);
- } catch (RSVPParsingException e) {
+ } catch (final RSVPParsingException e) {
}
}
}
@Test
- public void testParserRegistration() {
- assertNotNull(this.simpleXROSubobjectRegistry.registerSubobjectParser(subObjectTypeOne, this
+ public void testParserRegistration() throws RSVPParsingException {
+ assertNotNull(this.simpleXROSubobjectRegistry.registerSubobjectParser(this.subObjectTypeOne, this
.rroSubobjectParser));
+ assertNotNull(this.simpleXROSubobjectRegistry.parseSubobject(this.subObjectTypeOne, this.input, false));
}
@Test
public void testSerializerRegistration() {
- assertNotNull(this.simpleXROSubobjectRegistry.registerSubobjectSerializer(MockRROSubObjectClass.class, this
+ assertNotNull(this.simpleXROSubobjectRegistry.registerSubobjectSerializer(LabelCase.class, this
.rroSubobjectSerializer));
+ final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new
+ LabelCaseBuilder().build()).build();
+ final ByteBuf output = Unpooled.buffer();
+ this.simpleXROSubobjectRegistry.serializeSubobject(container, output);
+ assertEquals(1, output.readableBytes());
}
- private final class MockRROSubObjectClass implements SubobjectType {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return MockRROSubObjectClass.class;
- }
- }
}
\ No newline at end of file