Update MRI upstreams for Phosphorus
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / test / java / org / opendaylight / openflowjava / nx / codec / match / UdpDstCodecTest.java
index 58bcff6d5ee9fd3d4f7ea1af539671395b9f8836..5b8ec214b644e5be50bd11db0cdf0b010f90d3a2 100644 (file)
@@ -1,18 +1,16 @@
-/**
+/*
  * Copyright (c) 2016 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.openflowjava.nx.codec.match;
 
 import static org.junit.Assert.assertEquals;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufAllocator;
-import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
@@ -20,25 +18,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfUdpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.UdpDstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.UdpDstCaseValueBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.dst.grouping.UdpDstValuesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValue;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValueBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
 
 public class UdpDstCodecTest {
+    private final ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
+    private final UdpDstCodec udpDstCodec = new UdpDstCodec();
 
-    UdpDstCodec udpDstCodec;
-    ByteBuf buffer;
-    MatchEntry input;
+    private MatchEntry input;
 
     private static final int VALUE_LENGTH = 4;
     private static final int NXM_FIELD_CODE = 12;
 
-    @Before
-    public void setUp() {
-        udpDstCodec = new UdpDstCodec();
-        buffer = ByteBufAllocator.DEFAULT.buffer();
-    }
-
     @Test
     public void serializeTest() {
         input = createMatchEntry();
@@ -59,37 +52,36 @@ public class UdpDstCodecTest {
 
         input = udpDstCodec.deserialize(buffer);
 
-        UdpDstCaseValue result = ((UdpDstCaseValue) input.getMatchEntryValue());
+        final UdpDstCaseValue result = (UdpDstCaseValue) input.getMatchEntryValue();
 
         assertEquals(Nxm0Class.class, input.getOxmClass());
         assertEquals(NxmOfUdpDst.class, input.getOxmMatchField());
-        assertEquals(true, input.isHasMask());
+        assertEquals(true, input.getHasMask());
         assertEquals(1, result.getUdpDstValues().getPort().getValue().shortValue());
         assertEquals(0xffff, result.getUdpDstValues().getMask().shortValue() & 0xffff);
     }
 
-
-    private MatchEntry createMatchEntry() {
+    private static MatchEntry createMatchEntry() {
         MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-        UdpDstCaseValueBuilder caseBuilder = new UdpDstCaseValueBuilder();
-        UdpDstValuesBuilder valuesBuilder = new UdpDstValuesBuilder();
+        final UdpDstCaseValueBuilder caseBuilder = new UdpDstCaseValueBuilder();
+        final UdpDstValuesBuilder valuesBuilder = new UdpDstValuesBuilder();
 
         matchEntryBuilder.setOxmClass(Nxm0Class.class);
         matchEntryBuilder.setOxmMatchField(NxmOfUdpDst.class);
         matchEntryBuilder.setHasMask(true);
 
-        valuesBuilder.setPort(new PortNumber(1));
-        valuesBuilder.setMask(0xffff);
+        valuesBuilder.setPort(new PortNumber(Uint16.ONE));
+        valuesBuilder.setMask(Uint16.MAX_VALUE);
 
         caseBuilder.setUdpDstValues(valuesBuilder.build());
         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
         return matchEntryBuilder.build();
     }
 
-    private void createBuffer(ByteBuf message) {
+    private static void createBuffer(final ByteBuf message) {
         message.writeShort(OxmMatchConstants.NXM_0_CLASS);
 
-        int fieldMask = (NXM_FIELD_CODE << 1);
+        int fieldMask = NXM_FIELD_CODE << 1;
         message.writeByte(fieldMask);
         message.writeByte(VALUE_LENGTH);
         //Port num = 1