Test coverage: rsvp-spi 38/30438/1
authorIveta Halanova <ihalanov@cisco.com>
Mon, 30 Nov 2015 14:28:53 +0000 (15:28 +0100)
committerIveta Halanova <ihalanov@cisco.com>
Tue, 1 Dec 2015 14:01:00 +0000 (15:01 +0100)
Change-Id: I4cdcecd0610c667e3d1f4bbe3e4871b77c869c7f
Signed-off-by: Iveta Halanova <ihalanov@cisco.com>
rsvp/spi/src/test/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/ServiceLoaderRSVPExtensionProviderContextTest.java
rsvp/spi/src/test/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/SimpleEROSubobjectRegistryTest.java
rsvp/spi/src/test/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/SimpleRROSubobjectRegistryTest.java
rsvp/spi/src/test/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/SimpleRSVPObjectRegistryTest.java
rsvp/spi/src/test/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/SimpleXROSubobjectRegistryTest.java

index 87809706d3797e302696598a18bc40941220d9d9..75633fe1b3f81ea3635a895cebda693dc5b166a3 100644 (file)
 
 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
index 84a06cd8a3729a1683817073dfe3bde86aed12b3..f2dfeafcf3cba6614fe8248433a6eb3605ffa2cb 100644 (file)
@@ -11,7 +11,6 @@ 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;
@@ -20,19 +19,20 @@ import org.mockito.ArgumentCaptor;
 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
@@ -42,13 +42,18 @@ public class SimpleEROSubobjectRegistryTest {
     @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
@@ -67,7 +72,7 @@ public class SimpleEROSubobjectRegistryTest {
         final int wrongType = 65536;
         try {
             this.simpleEROSubobjectRegistry.parseSubobject(wrongType, this.input, false);
-        } catch (RSVPParsingException e) {
+        } catch (final RSVPParsingException e) {
         }
     }
 
@@ -78,21 +83,21 @@ public class SimpleEROSubobjectRegistryTest {
     }
 
     @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
index 5fc4b00982513b229c2cfe37b950a66bb0da6b31..83a564f6f6b56a4d5a212ce942e71168cc01bcb0 100644 (file)
@@ -11,7 +11,6 @@ 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;
@@ -20,20 +19,21 @@ import org.mockito.ArgumentCaptor;
 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
@@ -43,12 +43,18 @@ public class SimpleRROSubobjectRegistryTest {
     @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
@@ -67,7 +73,7 @@ public class SimpleRROSubobjectRegistryTest {
         final int wrongType = 65536;
         try {
             this.simpleRROSubobjectRegistry.parseSubobject(wrongType, this.input);
-        } catch (RSVPParsingException e) {
+        } catch (final RSVPParsingException e) {
         }
     }
 
@@ -78,21 +84,21 @@ public class SimpleRROSubobjectRegistryTest {
     }
 
     @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
index fa2b2f10699152058dbc9fde64c4910c350ca142..2b94326379517bd8fb37e19a8da2e5ac2d8ec537 100644 (file)
@@ -12,7 +12,6 @@ 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;
@@ -27,13 +26,12 @@ 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();
+    private final SimpleRSVPObjectRegistry simpleRSVPObjectRegistry = new SimpleRSVPObjectRegistry();
     @Mock
     private RSVPTeObjectParser rsvpTeObjectParser;
     @Mock
@@ -42,7 +40,7 @@ public class SimpleRSVPObjectRegistryTest {
     @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);
@@ -52,7 +50,7 @@ public class SimpleRSVPObjectRegistryTest {
 
     @Test
     public void testParserRegistration() {
-        this.simpleRSVPObjectRegistry.registerRsvpObjectParser(subObjectTypeOne, subObjectCTypeOne, this.rsvpTeObjectParser);
+        this.simpleRSVPObjectRegistry.registerRsvpObjectParser(this.subObjectTypeOne, this.subObjectCTypeOne, this.rsvpTeObjectParser);
     }
 
     @Test
@@ -63,13 +61,13 @@ public class SimpleRSVPObjectRegistryTest {
     @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());
@@ -77,7 +75,7 @@ public class SimpleRSVPObjectRegistryTest {
 
     @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);
 
@@ -90,19 +88,13 @@ public class SimpleRSVPObjectRegistryTest {
     @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
index ab9add06a31010178351c303176950d53a85f423..142c0e34bcdf07be3ee3ff123ce453fd94c954f1 100644 (file)
@@ -11,7 +11,6 @@ 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;
@@ -20,19 +19,20 @@ import org.mockito.ArgumentCaptor;
 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
@@ -42,13 +42,19 @@ public class SimpleXROSubobjectRegistryTest {
     @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
@@ -67,7 +73,7 @@ public class SimpleXROSubobjectRegistryTest {
         final int wrongType = 65536;
         try {
             this.simpleXROSubobjectRegistry.parseSubobject(wrongType, this.input, false);
-        } catch (RSVPParsingException e) {
+        } catch (final RSVPParsingException e) {
         }
     }
 
@@ -78,21 +84,21 @@ public class SimpleXROSubobjectRegistryTest {
     }
 
     @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