Promote MessageRegistry to pcep-api
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / PCCEndPointIpv4ObjectParserTest.java
1 /*
2  * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.pcep.pcc.mock;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
18 import org.opendaylight.protocol.util.Ipv4Util;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObj;
23
24 public class PCCEndPointIpv4ObjectParserTest {
25
26     private static final String IP1 = "1.2.3.4";
27     private static final String IP2 = "1.2.3.5";
28
29     @Test(expected = PCEPDeserializerException.class)
30     public void testParseEmptyObject() throws PCEPDeserializerException {
31         final ObjectHeader header = new ObjectHeaderImpl(false, false);
32         final ByteBuf bytes = Unpooled.buffer();
33         bytes.writeByte(4);
34         new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
35     }
36
37     @Test
38     public void testParseObject() throws PCEPDeserializerException {
39         final ObjectHeader header = new ObjectHeaderImpl(false, false);
40         final ByteBuf bytes = Unpooled.buffer();
41         bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4AddressNoZone(IP1)));
42         bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4AddressNoZone(IP2)));
43         final EndpointsObj output = (EndpointsObj) new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
44
45         assertEquals(IP1, ((Ipv4Case) output.getAddressFamily()).getIpv4().getSourceIpv4Address().getValue());
46         assertEquals(IP2, ((Ipv4Case) output.getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue());
47         assertFalse(output.getIgnore());
48         assertFalse(output.getProcessingRule());
49     }
50
51     @Test(expected = IllegalArgumentException.class)
52     public void testNullBytes() throws PCEPDeserializerException {
53         final ObjectHeader header = new ObjectHeaderImpl(false, false);
54         final ByteBuf bytes = null;
55         new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
56     }
57
58     @Test(expected = IllegalArgumentException.class)
59     public void testEmptyBytes() throws PCEPDeserializerException {
60         final ObjectHeader header = new ObjectHeaderImpl(false, false);
61         final ByteBuf bytes = Unpooled.buffer();
62         new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
63     }
64 }