Use BigInteger.valueOf()
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / NxmExtensionsConvertorTest.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntry;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
26
27 /**
28  * Created by Martin Bobak mbobak@cisco.com on 9/17/14.
29  */
30 public class NxmExtensionsConvertorTest {
31
32
33     private static final Integer TCP_FLAG = new Integer(42);
34     private static final Ipv4Prefix IPV_4_PREFIX = new Ipv4Prefix("10.0.0.1/24");
35
36     @Test
37     /**
38      * Trivial test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.NxmExtensionsConvertor#toNxmTcpFlag(Integer)}  }
39      */
40     public void testToNxmTcpFlag() {
41         MatchEntries matchEntries = NxmExtensionsConvertor.toNxmTcpFlag(TCP_FLAG);
42         assertNotNull(matchEntries.getAugmentation(TcpFlagMatchEntry.class));
43         assertFalse(matchEntries.isHasMask());
44         assertEquals(Nxm1Class.class, matchEntries.getOxmClass());
45         assertEquals(TcpFlag.class, matchEntries.getOxmMatchField());
46     }
47
48     @Test
49     /**
50      * Trivial test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.NxmExtensionsConvertor#toNxmIpv4Tunnel(Class, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix)}  }
51      */
52     public void testToNxmIpv4Tunnel() {
53         MatchEntries matchEntries = NxmExtensionsConvertor.toNxmIpv4Tunnel(MockMatchField.class, IPV_4_PREFIX);
54         assertNotNull(matchEntries.getAugmentation(MaskMatchEntry.class));
55         assertNotNull(matchEntries.getAugmentation(Ipv4AddressMatchEntry.class));
56         assertTrue(matchEntries.isHasMask());
57         assertEquals(Nxm1Class.class, matchEntries.getOxmClass());
58         assertEquals(MockMatchField.class, matchEntries.getOxmMatchField());
59     }
60
61     @Test
62     /**
63      * Trivial test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.NxmExtensionsConvertor#addNxmIpv4PrefixAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix)}  }
64      */
65     public void testAddNxmIpv4PrefixAugmentation() {
66         assertTrue(NxmExtensionsConvertor.addNxmIpv4PrefixAugmentation(new MatchEntriesBuilder(), IPV_4_PREFIX));
67     }
68
69
70     @Test
71     /**
72      * Trivial test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.NxmExtensionsConvertor#addNxmMaskAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder, byte[])}  }
73      */
74     public void testAddNxmMaskAugmentation() {
75         MatchEntriesBuilder matchEntryBuilder = new MatchEntriesBuilder();
76         byte[] mask = new byte[0];
77         assertNull(matchEntryBuilder.getAugmentation(MaskMatchEntry.class));
78         NxmExtensionsConvertor.addNxmMaskAugmentation(matchEntryBuilder, mask);
79         assertNotNull(matchEntryBuilder.getAugmentation(MaskMatchEntry.class));
80     }
81
82
83     private class MockMatchField extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField {
84
85     }
86 }