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