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
8 package org.opendaylight.protocol.rsvp.parser.spi.pojo;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
19 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
20 import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
21 import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
22 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
23 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
24 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
25 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
26 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
27 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
28 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
34 public class ServiceLoaderRSVPExtensionProviderContextTest {
36 private final SimpleRSVPExtensionProviderContext context = (SimpleRSVPExtensionProviderContext)
37 ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance();
39 private final RSVPTeObjectParser rsvpTeParser = Mockito.mock(RSVPTeObjectParser.class);
40 private final RSVPTeObjectSerializer rsvpTeSerializer = Mockito.mock(RSVPTeObjectSerializer.class);
41 private final RsvpTeObject parsedRsvpTeObj = Mockito.mock(RsvpTeObject.class);
43 private final XROSubobjectParser xroObjParser = Mockito.mock(XROSubobjectParser.class);
44 private final XROSubobjectSerializer xroObjSerializer = Mockito.mock(XROSubobjectSerializer.class);
45 private final SubobjectContainer subObj = Mockito.mock(SubobjectContainer.class);
46 private final SubobjectType subObjType = Mockito.mock(SubobjectType.class);
48 private final RROSubobjectParser rroParser = Mockito.mock(RROSubobjectParser.class);
49 private final RROSubobjectSerializer rroSerializer = Mockito.mock(RROSubobjectSerializer.class);
50 private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route
51 .subobjects.list.SubobjectContainer rroSubObj = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight
52 .params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.list.SubobjectContainer.class);
53 private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route
54 .subobjects.SubobjectType rroSubObjType = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params
55 .xml.ns.yang.rsvp.rev150820._record.route.subobjects.SubobjectType.class);
57 private final EROSubobjectParser eroParser = Mockito.mock(EROSubobjectParser.class);
58 private final EROSubobjectSerializer eroSerializer = Mockito.mock(EROSubobjectSerializer.class);
59 private final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
60 .subobjects.list.SubobjectContainer eroSubObj = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight
61 .params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer.class);
63 private final LabelParser labelParser = Mockito.mock(LabelParser.class);
64 private final LabelSerializer labelSerializer = Mockito.mock(LabelSerializer.class);
65 private final LabelType labelType = Mockito.mock(LabelType.class);
68 public void setUp() throws RSVPParsingException {
69 Mockito.doReturn(this.parsedRsvpTeObj).when(this.rsvpTeParser).parseObject(Mockito.any(ByteBuf.class));
70 Mockito.doReturn(RsvpTeObject.class).when(this.parsedRsvpTeObj).implementedInterface();
71 Mockito.doReturn("parsedRsvpTeObj").when(this.parsedRsvpTeObj).toString();
72 Mockito.doNothing().when(this.rsvpTeSerializer).serializeObject(Mockito.any(RsvpTeObject.class),
73 Mockito.any(ByteBuf.class));
75 Mockito.doReturn(this.subObj).when(this.xroObjParser).parseSubobject(Mockito.any(ByteBuf.class),
76 Mockito.any(Boolean.class));
77 Mockito.doReturn(this.subObjType).when(this.subObj).getSubobjectType();
78 Mockito.doReturn("SubobjectContainer").when(this.subObj).toString();
79 Mockito.doReturn(SubobjectType.class).when(this.subObjType).implementedInterface();
80 Mockito.doNothing().when(this.xroObjSerializer).serializeSubobject(Mockito.any(SubobjectContainer.class),
81 Mockito.any(ByteBuf.class));
83 Mockito.doReturn(this.rroSubObj).when(this.rroParser).parseSubobject(Mockito.any(ByteBuf.class));
84 Mockito.doReturn(this.rroSubObjType).when(this.rroSubObj).getSubobjectType();
85 Mockito.doReturn("SubobjectContainer").when(this.rroSubObj).toString();
86 Mockito.doReturn(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route
87 .subobjects.SubobjectType.class).when(this.rroSubObjType).implementedInterface();
88 Mockito.doNothing().when(this.rroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn
89 .opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.list.SubobjectContainer.class),
90 Mockito.any(ByteBuf.class));
92 Mockito.doReturn(this.eroSubObj).when(this.eroParser).parseSubobject(Mockito.any(ByteBuf.class),
93 Mockito.any(Boolean.class));
94 Mockito.doReturn(this.subObjType).when(this.eroSubObj).getSubobjectType();
95 Mockito.doReturn("EROSubobjectContainer").when(this.eroSubObj).toString();
96 Mockito.doReturn(SubobjectType.class).when(this.subObjType).implementedInterface();
97 Mockito.doNothing().when(this.eroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn
98 .opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer.class),
99 Mockito.any(ByteBuf.class));
101 Mockito.doReturn(this.labelType).when(this.labelParser).parseLabel(Mockito.any(ByteBuf.class));
102 Mockito.doReturn(LabelType.class).when(this.labelType).implementedInterface();
103 Mockito.doReturn("LabelType").when(this.labelType).toString();
104 Mockito.doNothing().when(this.labelSerializer).serializeLabel(Mockito.anyBoolean(), Mockito.anyBoolean(),
105 Mockito.any(LabelType.class), Mockito.any(ByteBuf.class));
109 public void testReferenceCache() {
110 assertNotNull(this.context.getReferenceCache());
114 public void testServiceForRsvpObject() throws RSVPParsingException {
115 this.context.registerRsvpObjectParser(1, 1, this.rsvpTeParser);
116 final ByteBuf buffer = Unpooled.buffer();
117 assertEquals(this.parsedRsvpTeObj, this.context.getRsvpRegistry().parseRSPVTe(1, 1, buffer));
118 this.context.registerRsvpObjectSerializer(RsvpTeObject.class, this.rsvpTeSerializer);
119 this.context.getRsvpRegistry().serializeRSPVTe(this.parsedRsvpTeObj, buffer);
120 Mockito.verify(this.rsvpTeSerializer).serializeObject(Mockito.any(RsvpTeObject.class),
121 Mockito.any(ByteBuf.class));
125 public void testServiceForXROSubobject() throws RSVPParsingException {
126 this.context.registerXROSubobjectParser(2, this.xroObjParser);
127 final ByteBuf buffer = Unpooled.buffer();
128 assertEquals(this.subObj, this.context.getXROSubobjectHandlerRegistry().parseSubobject(2, buffer, false));
129 this.context.registerXROSubobjectSerializer(SubobjectType.class, this.xroObjSerializer);
130 this.context.getXROSubobjectHandlerRegistry().serializeSubobject(this.subObj, buffer);
131 Mockito.verify(this.xroObjSerializer).serializeSubobject(this.subObj, buffer);
135 public void testServiceForRROSubobject() throws RSVPParsingException {
136 this.context.registerRROSubobjectParser(3, this.rroParser);
137 final ByteBuf buffer = Unpooled.buffer();
138 assertEquals(this.rroSubObj, this.context.getRROSubobjectHandlerRegistry().parseSubobject(3, buffer));
139 this.context.registerRROSubobjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
140 .rsvp.rev150820._record.route.subobjects.SubobjectType.class, this.rroSerializer);
141 this.context.getRROSubobjectHandlerRegistry().serializeSubobject(this.rroSubObj, buffer);
142 Mockito.verify(this.rroSerializer).serializeSubobject(this.rroSubObj, buffer);
146 public void testServiceForEROSubobject() throws RSVPParsingException {
147 this.context.registerEROSubobjectParser(4, this.eroParser);
148 final ByteBuf buffer = Unpooled.buffer();
149 assertEquals(this.eroSubObj, this.context.getEROSubobjectHandlerRegistry().parseSubobject(4, buffer, false));
150 this.context.registerEROSubobjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
151 .rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType.class, this.eroSerializer);
152 this.context.getEROSubobjectHandlerRegistry().serializeSubobject(this.eroSubObj, buffer);
153 Mockito.verify(this.eroSerializer).serializeSubobject(this.eroSubObj, buffer);
157 public void testServiceForLabel() throws RSVPParsingException {
158 this.context.registerLabelParser(5, this.labelParser);
159 final ByteBuf buffer = Unpooled.buffer();
160 assertEquals(this.labelType, this.context.getLabelHandlerRegistry().parseLabel(5, buffer));
161 this.context.registerLabelSerializer(LabelType.class, this.labelSerializer);
162 this.context.getLabelHandlerRegistry().serializeLabel(false, false, this.labelType, buffer);
163 Mockito.verify(this.labelSerializer).serializeLabel(false, false, this.labelType, buffer);