Switch common parsers to utils
[bgpcep.git] / rsvp / spi / src / test / java / org / opendaylight / protocol / rsvp / parser / spi / subobjects / UnnumberedInterfaceSubobjectUtilsTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.Unnumbered;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
19 import org.opendaylight.yangtools.yang.common.Uint32;
20
21 public class UnnumberedInterfaceSubobjectUtilsTest {
22     private final Uint32 routerId = Uint32.valueOf(3735928559L);
23     private final Uint32 interfaceId = Uint32.valueOf(3736059631L);
24     private final Unnumbered unnumbered1 = new UnnumberedBuilder().setRouterId((Uint32) null).build();
25     private final Unnumbered unnumbered2 = new UnnumberedBuilder().setRouterId(Uint32.ONE).setInterfaceId((Uint32) null)
26             .build();
27
28     @Test
29     public void testProcessing() {
30         final ByteBuf input = Unpooled.buffer(8);
31         input.writeInt(this.routerId.intValue());
32         input.writeInt(this.interfaceId.intValue());
33         final UnnumberedCase output = UnnumberedInterfaceSubobjectUtils.parseUnnumeredInterface(input);
34         assertEquals(this.routerId, output.getUnnumbered().getRouterId());
35         assertEquals(this.interfaceId, output.getUnnumbered().getInterfaceId());
36
37         final ByteBuf bytebuf = Unpooled.buffer(8);
38         UnnumberedInterfaceSubobjectUtils.serializeUnnumeredInterface(output.getUnnumbered(), bytebuf);
39         assertArrayEquals(input.array(), bytebuf.array());
40     }
41
42     @Test(expected = IllegalArgumentException.class)
43     public void testException1() {
44         UnnumberedInterfaceSubobjectUtils.serializeUnnumeredInterface(this.unnumbered1, Unpooled.EMPTY_BUFFER);
45     }
46
47     @Test(expected = IllegalArgumentException.class)
48     public void testException2() {
49         UnnumberedInterfaceSubobjectUtils.serializeUnnumeredInterface(this.unnumbered2, Unpooled.buffer(4));
50     }
51 }