2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.rsvp.parser.spi.pojo;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import java.lang.reflect.Constructor;
17 import java.lang.reflect.InvocationTargetException;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mockito;
21 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
22 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
23 import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
24 import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
25 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
26 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
27 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
28 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
29 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
30 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
31 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
37 public class ServiceLoaderRSVPExtensionProviderContextTest {
39 private final SimpleRSVPExtensionProviderContext context = (SimpleRSVPExtensionProviderContext)
40 ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance();
42 private final RSVPTeObjectParser rsvpTeParser = Mockito.mock(RSVPTeObjectParser.class);
43 private final RSVPTeObjectSerializer rsvpTeSerializer = Mockito.mock(RSVPTeObjectSerializer.class);
44 private final RsvpTeObject parsedRsvpTeObj = Mockito.mock(RsvpTeObject.class);
46 private final XROSubobjectParser xroObjParser = Mockito.mock(XROSubobjectParser.class);
47 private final XROSubobjectSerializer xroObjSerializer = Mockito.mock(XROSubobjectSerializer.class);
48 private final SubobjectContainer subObj = Mockito.mock(SubobjectContainer.class);
49 private final SubobjectType subObjType = Mockito.mock(SubobjectType.class);
51 private final RROSubobjectParser rroParser = Mockito.mock(RROSubobjectParser.class);
52 private final RROSubobjectSerializer rroSerializer = Mockito.mock(RROSubobjectSerializer.class);
53 private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route
54 .subobjects.list.SubobjectContainer rroSubObj = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight
55 .params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer.class);
56 private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route
57 .subobjects.SubobjectType rroSubObjType = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params
58 .xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType.class);
60 private final EROSubobjectParser eroParser = Mockito.mock(EROSubobjectParser.class);
61 private final EROSubobjectSerializer eroSerializer = Mockito.mock(EROSubobjectSerializer.class);
62 private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
63 .subobjects.list.SubobjectContainer eroSubObj = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight
64 .params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer.class);
66 private final LabelParser labelParser = Mockito.mock(LabelParser.class);
67 private final LabelSerializer labelSerializer = Mockito.mock(LabelSerializer.class);
68 private final LabelType labelType = Mockito.mock(LabelType.class);
71 public void setUp() throws RSVPParsingException {
72 Mockito.doReturn(this.parsedRsvpTeObj).when(this.rsvpTeParser).parseObject(Mockito.any(ByteBuf.class));
73 Mockito.doReturn(RsvpTeObject.class).when(this.parsedRsvpTeObj).getImplementedInterface();
74 Mockito.doReturn("parsedRsvpTeObj").when(this.parsedRsvpTeObj).toString();
75 Mockito.doNothing().when(this.rsvpTeSerializer).serializeObject(Mockito.any(RsvpTeObject.class),
76 Mockito.any(ByteBuf.class));
78 Mockito.doReturn(this.subObj).when(this.xroObjParser).parseSubobject(Mockito.any(ByteBuf.class),
79 Mockito.any(Boolean.class));
80 Mockito.doReturn(this.subObjType).when(this.subObj).getSubobjectType();
81 Mockito.doReturn("SubobjectContainer").when(this.subObj).toString();
82 Mockito.doReturn(SubobjectType.class).when(this.subObjType).getImplementedInterface();
83 Mockito.doNothing().when(this.xroObjSerializer).serializeSubobject(Mockito.any(SubobjectContainer.class),
84 Mockito.any(ByteBuf.class));
86 Mockito.doReturn(this.rroSubObj).when(this.rroParser).parseSubobject(Mockito.any(ByteBuf.class));
87 Mockito.doReturn(this.rroSubObjType).when(this.rroSubObj).getSubobjectType();
88 Mockito.doReturn("SubobjectContainer").when(this.rroSubObj).toString();
89 Mockito.doReturn(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route
90 .subobjects.SubobjectType.class).when(this.rroSubObjType).getImplementedInterface();
91 Mockito.doNothing().when(this.rroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn
92 .opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer.class),
93 Mockito.any(ByteBuf.class));
95 Mockito.doReturn(this.eroSubObj).when(this.eroParser).parseSubobject(Mockito.any(ByteBuf.class),
96 Mockito.any(Boolean.class));
97 Mockito.doReturn(this.subObjType).when(this.eroSubObj).getSubobjectType();
98 Mockito.doReturn("EROSubobjectContainer").when(this.eroSubObj).toString();
99 Mockito.doReturn(SubobjectType.class).when(this.subObjType).getImplementedInterface();
100 Mockito.doNothing().when(this.eroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn
101 .opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer.class),
102 Mockito.any(ByteBuf.class));
104 Mockito.doReturn(this.labelType).when(this.labelParser).parseLabel(Mockito.any(ByteBuf.class));
105 Mockito.doReturn(LabelType.class).when(this.labelType).getImplementedInterface();
106 Mockito.doReturn("LabelType").when(this.labelType).toString();
107 Mockito.doNothing().when(this.labelSerializer).serializeLabel(Mockito.anyBoolean(), Mockito.anyBoolean(),
108 Mockito.any(LabelType.class), Mockito.any(ByteBuf.class));
112 public void testReferenceCache() {
113 assertNotNull(this.context.getReferenceCache());
117 public void testServiceForRsvpObject() throws RSVPParsingException {
118 this.context.registerRsvpObjectParser(1, 1, this.rsvpTeParser);
119 final ByteBuf buffer = Unpooled.buffer();
120 assertEquals(this.parsedRsvpTeObj, this.context.getRsvpRegistry().parseRSPVTe(1, 1, buffer));
121 this.context.registerRsvpObjectSerializer(RsvpTeObject.class, this.rsvpTeSerializer);
122 this.context.getRsvpRegistry().serializeRSPVTe(this.parsedRsvpTeObj, buffer);
123 Mockito.verify(this.rsvpTeSerializer).serializeObject(Mockito.any(RsvpTeObject.class),
124 Mockito.any(ByteBuf.class));
128 public void testServiceForXROSubobject() throws RSVPParsingException {
129 this.context.registerXROSubobjectParser(2, this.xroObjParser);
130 final ByteBuf buffer = Unpooled.buffer();
131 assertEquals(this.subObj, this.context.getXROSubobjectHandlerRegistry().parseSubobject(2, buffer, false));
132 this.context.registerXROSubobjectSerializer(SubobjectType.class, this.xroObjSerializer);
133 this.context.getXROSubobjectHandlerRegistry().serializeSubobject(this.subObj, buffer);
134 Mockito.verify(this.xroObjSerializer).serializeSubobject(this.subObj, buffer);
138 public void testServiceForRROSubobject() throws RSVPParsingException {
139 this.context.registerRROSubobjectParser(3, this.rroParser);
140 final ByteBuf buffer = Unpooled.buffer();
141 assertEquals(this.rroSubObj, this.context.getRROSubobjectHandlerRegistry().parseSubobject(3, buffer));
142 this.context.registerRROSubobjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
143 .rsvp.rev150820.record.route.subobjects.SubobjectType.class, this.rroSerializer);
144 this.context.getRROSubobjectHandlerRegistry().serializeSubobject(this.rroSubObj, buffer);
145 Mockito.verify(this.rroSerializer).serializeSubobject(this.rroSubObj, buffer);
149 public void testServiceForEROSubobject() throws RSVPParsingException {
150 this.context.registerEROSubobjectParser(4, this.eroParser);
151 final ByteBuf buffer = Unpooled.buffer();
152 assertEquals(this.eroSubObj, this.context.getEROSubobjectHandlerRegistry().parseSubobject(4, buffer, false));
153 this.context.registerEROSubobjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
154 .rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType.class, this.eroSerializer);
155 this.context.getEROSubobjectHandlerRegistry().serializeSubobject(this.eroSubObj, buffer);
156 Mockito.verify(this.eroSerializer).serializeSubobject(this.eroSubObj, buffer);
160 public void testServiceForLabel() throws RSVPParsingException {
161 this.context.registerLabelParser(5, this.labelParser);
162 final ByteBuf buffer = Unpooled.buffer();
163 assertEquals(this.labelType, this.context.getLabelHandlerRegistry().parseLabel(5, buffer));
164 this.context.registerLabelSerializer(LabelType.class, this.labelSerializer);
165 this.context.getLabelHandlerRegistry().serializeLabel(false, false, this.labelType, buffer);
166 Mockito.verify(this.labelSerializer).serializeLabel(false, false, this.labelType, buffer);
169 @Test(expected = UnsupportedOperationException.class)
170 @SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" })
171 public void testPrivateConstructor() throws Throwable {
172 final Constructor<ServiceLoaderRSVPExtensionProviderContext> c =
173 ServiceLoaderRSVPExtensionProviderContext.class.getDeclaredConstructor();
174 c.setAccessible(true);
177 } catch (final InvocationTargetException e) {