--- /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;
+
+import static org.junit.Assert.assertArrayEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+
+public class EROSubobjectUtilTest {
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPrivateConstructor() throws Throwable {
+ final Constructor<EROSubobjectUtil> c = EROSubobjectUtil.class.getDeclaredConstructor();
+ c.setAccessible(true);
+ try {
+ c.newInstance();
+ } catch (final InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+
+ @Test
+ public void testFormatSubobject1() {
+ final byte[] array = new byte[] {2, 3};
+ final byte[] expected = new byte[] {(byte)0x81, 4, 2, 3};
+ final ByteBuf body = Unpooled.copiedBuffer(array);
+ final ByteBuf aggregator = Unpooled.buffer(4);
+ EROSubobjectUtil.formatSubobject(1, Boolean.TRUE, body, aggregator);
+ assertArrayEquals(expected, aggregator.array());
+ }
+
+ @Test
+ public void testFormatSubobject2() {
+ final byte[] array = new byte[] {2, 3};
+ final byte[] expected = new byte[] {1, 4, 2, 3};
+ final ByteBuf body = Unpooled.copiedBuffer(array);
+ final ByteBuf aggregator = Unpooled.buffer(4);
+ EROSubobjectUtil.formatSubobject(1, Boolean.FALSE, body, aggregator);
+ assertArrayEquals(expected, aggregator.array());
+ }
+
+ @Test
+ public void testFormatSubobject3() {
+ final byte[] array = new byte[] {2, 3};
+ final byte[] expected = new byte[] {1, 4, 2, 3};
+ final ByteBuf body = Unpooled.copiedBuffer(array);
+ final ByteBuf aggregator = Unpooled.buffer(4);
+ EROSubobjectUtil.formatSubobject(1, null, body, aggregator);
+ assertArrayEquals(expected, aggregator.array());
+ }
+}
--- /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.subobjects;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.Unnumbered;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
+
+public class CUISubobjectParserTest {
+ private final Long routerId = 3735928559L;
+ private final Long interfaceId = 3736059631L;
+ CommonUnnumberedInterfaceSubobjectParser parser = new CommonUnnumberedInterfaceSubobjectParser();
+ final Unnumbered unnumbered1 = new UnnumberedBuilder().setRouterId(null).build();
+ final Unnumbered unnumbered2 = new UnnumberedBuilder().setRouterId(1L).setInterfaceId(null).build();
+
+ @Test
+ public void testProcessing() {
+ final ByteBuf input = Unpooled.buffer(8);
+ input.writeInt(this.routerId.intValue());
+ input.writeInt(this.interfaceId.intValue());
+ final UnnumberedCase output = this.parser.parseUnnumeredInterface(input);
+ assertEquals(this.routerId, output.getUnnumbered().getRouterId());
+ assertEquals(this.interfaceId, output.getUnnumbered().getInterfaceId());
+
+ final ByteBuf bytebuf = Unpooled.buffer(8);
+ this.parser.serializeUnnumeredInterface(output.getUnnumbered(), bytebuf);
+ assertArrayEquals(input.array(), bytebuf.array());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testException1() {
+ this.parser.serializeUnnumeredInterface(this.unnumbered1, Unpooled.EMPTY_BUFFER);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testException2() {
+ this.parser.serializeUnnumeredInterface(this.unnumbered2, Unpooled.buffer(4));
+ }
+
+}
--- /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.subobjects;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+
+public class CommonPathKeyParserTest {
+ private final CommonPathKeyParser parser = new CommonPathKeyParser();
+ private PathKey key1;
+ private PathKey key2;
+ private PathKey key3;
+ private final byte[] bytes = new byte[] {0,1,2,3};
+
+ @Before
+ public void setUp() {
+ this.key1 = new PathKeyBuilder().build();
+ this.key2 = new PathKeyBuilder()
+ .setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey(1))
+ .build();
+ this.key3 = new PathKeyBuilder()
+ .setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey(1))
+ .setPceId(new PceId(new byte[] {2, 3}))
+ .build();
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testSerializationExcption1() {
+ this.parser.serializePathKey(this.key1);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testSerializationExcption2() {
+ this.parser.serializePathKey(this.key2);
+ }
+
+ @Test
+ public void testSerialization() {
+ final ByteBuf output = this.parser.serializePathKey(this.key3);
+ assertArrayEquals(this.bytes, output.readBytes(output.readableBytes()).array());
+ }
+
+ @Test
+ public void testParsing() {
+ assertEquals(this.key3, this.parser.parsePathKey(2, Unpooled.copiedBuffer(this.bytes)));
+ }
+}
--- /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.subobjects;
+
+import static org.junit.Assert.assertArrayEquals;
+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 java.util.Arrays;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectRegistry;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
+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.explicit.route.subobjects.list.SubobjectContainer;
+
+public class EROSubobjectListParserTest {
+
+ private final EROSubobjectRegistry registry = Mockito.mock(EROSubobjectRegistry.class);
+ private final SubobjectContainer subObj = Mockito.mock(SubobjectContainer.class);
+ private final RsvpTeObject rsvpTeObj = Mockito.mock(RsvpTeObject.class);
+ private final EroListParser parser = new EroListParser(this.registry);
+ private final byte[] inputList = new byte[] {1, 3, 1, 2, 4, 1, 2};
+ private final byte[] emptyInput = new byte[] {1, 2};
+ private final byte[] wrongInput = new byte[] {1, 3};
+ private final List<SubobjectContainer> subobjects = Arrays.asList(this.subObj, this.subObj);
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ if (((ByteBuf) invocation.getArguments()[1]).readableBytes() == 0) {
+ return null;
+ }
+ return EROSubobjectListParserTest.this.subObj;
+ }
+ }).when(this.registry).parseSubobject(Mockito.anyInt(), Mockito.any(ByteBuf.class), Mockito.anyBoolean());
+ Mockito.doReturn("lala").when(this.subObj).toString();
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ ((ByteBuf) invocation.getArguments()[1]).writeByte(1);
+ return null;
+ }
+ }).when(this.registry).serializeSubobject(Mockito.any(SubobjectContainer.class), Mockito.any(ByteBuf.class));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testParsingException() throws RSVPParsingException {
+ this.parser.parseList(null);
+ }
+
+ @Test(expected=RSVPParsingException.class)
+ public void testWrongInput() throws RSVPParsingException {
+ this.parser.parseList(Unpooled.copiedBuffer(this.wrongInput));
+ }
+
+ @Test
+ public void testParseList() throws RSVPParsingException {
+ assertEquals(0, this.parser.parseList(Unpooled.copiedBuffer(this.emptyInput)).size());
+ final ByteBuf toBeParsed = Unpooled.copiedBuffer(this.inputList);
+ assertEquals(2, this.parser.parseList(toBeParsed).size());
+ }
+
+ @Test
+ public void testSerializeList() {
+ final ByteBuf buffer = Unpooled.buffer(2);
+ assertEquals(0, buffer.readableBytes());
+ this.parser.serializeList(this.subobjects, buffer);
+ assertEquals(2, buffer.readableBytes());
+ }
+
+ @Test
+ public void testAbstractRSVPObjParser() throws RSVPParsingException {
+ final ByteBuf byteAggregator = Unpooled.buffer(4);
+ byte[] output = new byte[] {0, 1, 2, 3};
+ this.parser.serializeAttributeHeader(1, (short) 2, (short) 3, byteAggregator);
+ assertArrayEquals(output, byteAggregator.array());
+
+ final ByteBuf body = Unpooled.buffer(4);
+ output = new byte[] {0, 0, 0, 1};
+ final AttributeFilter filter = new AttributeFilter(1L);
+ this.parser.writeAttributeFilter(filter, body);
+ assertArrayEquals(output, body.array());
+
+ final ByteBuf parseTeObj = Unpooled.buffer(1);
+ assertNotNull(this.parser.parseObject(parseTeObj));
+ assertNull(this.parser.parseObject(null));
+
+ assertEquals(0, parseTeObj.readableBytes());
+ this.parser.serializeObject(null, parseTeObj);
+ assertEquals(0, parseTeObj.readableBytes());
+ this.parser.serializeObject(this.rsvpTeObj, parseTeObj);
+ assertEquals(1, parseTeObj.readableBytes());
+ assertEquals((short) 3, parseTeObj.readUnsignedByte());
+ }
+
+ private class EroListParser extends EROSubobjectListParser {
+ public EroListParser(final EROSubobjectRegistry subobjReg) {
+ super(subobjReg);
+ }
+ @Override
+ protected void localSerializeObject(final RsvpTeObject rsvpTeObject, final ByteBuf output) {
+ output.writeByte(3);
+ }
+ @Override
+ protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
+ return EROSubobjectListParserTest.this.rsvpTeObj;
+ }
+ }
+}
--- /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.subobjects;
+
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectRegistry;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+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.record.route.subobjects.list.SubobjectContainer;
+
+public class RROSubobjectListParserTest {
+
+ private final RROSubobjectRegistry registry = Mockito.mock(RROSubobjectRegistry.class);
+ private final SubobjectContainer subObj = Mockito.mock(SubobjectContainer.class);
+ private final RroListParser parser = new RroListParser(this.registry);
+ private final byte[] inputList = new byte[] {1, 3, 1, 2, 4, 1, 2};
+ private final byte[] emptyInput = new byte[] {1, 2};
+ private final byte[] wrongInput = new byte[] {1, 3};
+ private final List<SubobjectContainer> subobjects = Arrays.asList(this.subObj, this.subObj);
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ if (((ByteBuf) invocation.getArguments()[1]).readableBytes() == 0) {
+ return null;
+ }
+ return RROSubobjectListParserTest.this.subObj;
+ }
+ }).when(this.registry).parseSubobject(Mockito.anyInt(), Mockito.any(ByteBuf.class));
+ Mockito.doReturn("lala").when(this.subObj).toString();
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ ((ByteBuf) invocation.getArguments()[1]).writeByte(1);
+ return null;
+ }
+ }).when(this.registry).serializeSubobject(Mockito.any(SubobjectContainer.class), Mockito.any(ByteBuf.class));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testParsingException() throws RSVPParsingException {
+ this.parser.parseList(null);
+ }
+
+ @Test(expected=RSVPParsingException.class)
+ public void testWrongInput() throws RSVPParsingException {
+ this.parser.parseList(Unpooled.copiedBuffer(this.wrongInput));
+ }
+
+ @Test
+ public void testParseList() throws RSVPParsingException {
+ assertEquals(0, this.parser.parseList(Unpooled.copiedBuffer(this.emptyInput)).size());
+ final ByteBuf toBeParsed = Unpooled.copiedBuffer(this.inputList);
+ assertEquals(2, this.parser.parseList(toBeParsed).size());
+ }
+
+ @Test
+ public void testSerializeList() {
+ final ByteBuf buffer = Unpooled.buffer(2);
+ assertEquals(0, buffer.readableBytes());
+ this.parser.serializeList(this.subobjects, buffer);
+ assertEquals(2, buffer.readableBytes());
+ }
+
+ private class RroListParser extends RROSubobjectListParser {
+ public RroListParser(final RROSubobjectRegistry subobjReg) {
+ super(subobjReg);
+ }
+ @Override
+ protected void localSerializeObject(final RsvpTeObject rsvpTeObject, final ByteBuf output) {
+ }
+ @Override
+ protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
+ return null;
+ }
+ }
+}
--- /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.subobjects;
+
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.XROSubobjectRegistry;
+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.exclude.route.object.exclude.route.object.SubobjectContainer;
+
+public class XROSubobjectListParserTest {
+
+ private final XROSubobjectRegistry registry = Mockito.mock(XROSubobjectRegistry.class);
+ private final SubobjectContainer subObj = Mockito.mock(SubobjectContainer.class);
+ private final XroListParser parser = new XroListParser(this.registry);
+ private final byte[] inputList = new byte[] {1, 3, 1, 2, 4, 1, 2};
+ private final byte[] emptyInput = new byte[] {1, 2};
+ private final byte[] wrongInput = new byte[] {1, 3};
+ private final List<SubobjectContainer> subobjects = Arrays.asList(this.subObj, this.subObj);
+
+ @Before
+ public void setUp() throws RSVPParsingException {
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ if (((ByteBuf) invocation.getArguments()[1]).readableBytes() == 0) {
+ return null;
+ }
+ return XROSubobjectListParserTest.this.subObj;
+ }
+ }).when(this.registry).parseSubobject(Mockito.anyInt(), Mockito.any(ByteBuf.class), Mockito.anyBoolean());
+ Mockito.doReturn("lala").when(this.subObj).toString();
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ ((ByteBuf) invocation.getArguments()[1]).writeByte(1);
+ return null;
+ }
+ }).when(this.registry).serializeSubobject(Mockito.any(SubobjectContainer.class), Mockito.any(ByteBuf.class));
+ }
+
+ @Test(expected=RSVPParsingException.class)
+ public void testWrongInput() throws RSVPParsingException {
+ this.parser.parseList(Unpooled.copiedBuffer(this.wrongInput));
+ }
+
+ @Test
+ public void testParseList() throws RSVPParsingException {
+ assertEquals(0, this.parser.parseList(Unpooled.copiedBuffer(this.emptyInput)).size());
+ final ByteBuf toBeParsed = Unpooled.copiedBuffer(this.inputList);
+ assertEquals(2, this.parser.parseList(toBeParsed).size());
+ }
+
+ @Test
+ public void testSerializeList() {
+ final ByteBuf buffer = Unpooled.buffer(2);
+ assertEquals(0, buffer.readableBytes());
+ this.parser.serializeList(this.subobjects, buffer);
+ assertEquals(2, buffer.readableBytes());
+ }
+
+ private class XroListParser extends XROSubobjectListParser {
+ public XroListParser(final XROSubobjectRegistry subobjReg) {
+ super(subobjReg);
+ }
+ @Override
+ protected void localSerializeObject(final RsvpTeObject rsvpTeObject, final ByteBuf output) {
+ }
+ @Override
+ protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
+ return null;
+ }
+ }
+}