Bug 5543 - Bo: Update JUnit tests part_8 19/40719/2
authormiroslav.macko <miroslav.macko@pantheon.tech>
Wed, 22 Jun 2016 13:27:43 +0000 (15:27 +0200)
committermiroslav.macko <miroslav.macko@pantheon.tech>
Fri, 1 Jul 2016 08:42:07 +0000 (10:42 +0200)
- Added tests for openflowjava-extension-nicira

Change-Id: I5849585383d6188cbaa39ace7a48937f178e06d7
Signed-off-by: miroslav.macko <miroslav.macko@pantheon.tech>
extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NsiCodecTest.java [new file with mode: 0644]
extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NspCodecTest.java [new file with mode: 0644]
extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NxmHeaderTest.java [new file with mode: 0644]
extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/Reg0CodecTest.java [new file with mode: 0644]
extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/Reg1CodecTest.java [new file with mode: 0644]

diff --git a/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NsiCodecTest.java b/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NsiCodecTest.java
new file mode 100644 (file)
index 0000000..2230096
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * 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.opendaylight.openflow.oxm.rev150225.Nxm1Class;
+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.NxmNxNsi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsi.grouping.NsiValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NsiCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NsiCaseValueBuilder;
+
+public class NsiCodecTest {
+
+    NsiCodec nsiCodec;
+    ByteBuf buffer;
+    MatchEntry input;
+
+    private static final int VALUE_LENGTH = 1;
+    private static final int NXM_FIELD_CODE = 38;
+
+    @Before
+    public void setUp() {
+        nsiCodec = new NsiCodec();
+        buffer = ByteBufAllocator.DEFAULT.buffer();
+    }
+
+    @Test
+    public void serializeTest() {
+        input = createMatchEntry();
+        nsiCodec.serialize(input, buffer);
+
+        assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
+        short fieldMask = buffer.readUnsignedByte();
+        assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+        assertEquals(0, fieldMask & 1);
+        assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+        assertEquals(1, buffer.readUnsignedByte());
+    }
+
+    @Test
+    public void deserializeTest() {
+        createBuffer(buffer);
+
+        input = nsiCodec.deserialize(buffer);
+
+        NsiCaseValue result = ((NsiCaseValue) input.getMatchEntryValue());
+
+        assertEquals(Nxm1Class.class, input.getOxmClass());
+        assertEquals(NxmNxNsi.class, input.getOxmMatchField());
+        assertEquals(false, input.isHasMask());
+        assertEquals(2, result.getNsiValues().getNsi().shortValue());
+    }
+
+
+    private MatchEntry createMatchEntry() {
+        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+        NsiCaseValueBuilder caseBuilder = new NsiCaseValueBuilder();
+        NsiValuesBuilder valuesBuilder = new NsiValuesBuilder();
+
+        matchEntryBuilder.setOxmClass(Nxm1Class.class);
+        matchEntryBuilder.setOxmMatchField(NxmNxNsi.class);
+        matchEntryBuilder.setHasMask(false);
+
+        valuesBuilder.setNsi((short)1);
+
+        caseBuilder.setNsiValues(valuesBuilder.build());
+        matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+        return matchEntryBuilder.build();
+    }
+
+    private void createBuffer(ByteBuf message) {
+        message.writeShort(OxmMatchConstants.NXM_1_CLASS);
+
+        int fieldMask = (NXM_FIELD_CODE << 1);
+        message.writeByte(fieldMask);
+        message.writeByte(VALUE_LENGTH);
+        message.writeByte(2);
+    }
+}
\ No newline at end of file
diff --git a/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NspCodecTest.java b/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NspCodecTest.java
new file mode 100644 (file)
index 0000000..bf9f072
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * 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.opendaylight.openflow.oxm.rev150225.Nxm1Class;
+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.NxmNxNsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsp.grouping.NspValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NspCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NspCaseValueBuilder;
+
+public class NspCodecTest {
+
+    NspCodec nspCodec;
+    ByteBuf buffer;
+    MatchEntry input;
+
+    private static final int VALUE_LENGTH = 4;
+    private static final int NXM_FIELD_CODE = 37;
+
+    @Before
+    public void setUp() {
+        nspCodec = new NspCodec();
+        buffer = ByteBufAllocator.DEFAULT.buffer();
+    }
+
+    @Test
+    public void serializeTest() {
+        input = createMatchEntry();
+        nspCodec.serialize(input, buffer);
+
+        assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
+        short fieldMask = buffer.readUnsignedByte();
+        assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+        assertEquals(0, fieldMask & 1);
+        assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+        assertEquals(1, buffer.readUnsignedInt());
+    }
+
+    @Test
+    public void deserializeTest() {
+        createBuffer(buffer);
+
+        input = nspCodec.deserialize(buffer);
+
+        NspCaseValue result = ((NspCaseValue) input.getMatchEntryValue());
+
+        assertEquals(Nxm1Class.class, input.getOxmClass());
+        assertEquals(NxmNxNsp.class, input.getOxmMatchField());
+        assertEquals(false, input.isHasMask());
+        assertEquals(2, result.getNspValues().getNsp().intValue());
+    }
+
+
+    private MatchEntry createMatchEntry() {
+        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+        NspCaseValueBuilder caseBuilder = new NspCaseValueBuilder();
+        NspValuesBuilder valuesBuilder = new NspValuesBuilder();
+
+        matchEntryBuilder.setOxmClass(Nxm1Class.class);
+        matchEntryBuilder.setOxmMatchField(NxmNxNsp.class);
+        matchEntryBuilder.setHasMask(false);
+
+        valuesBuilder.setNsp((long)1);
+
+        caseBuilder.setNspValues(valuesBuilder.build());
+        matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+        return matchEntryBuilder.build();
+    }
+
+    private void createBuffer(ByteBuf message) {
+        message.writeShort(OxmMatchConstants.NXM_1_CLASS);
+
+        int fieldMask = (NXM_FIELD_CODE << 1);
+        message.writeByte(fieldMask);
+        message.writeByte(VALUE_LENGTH);
+        message.writeInt(2);
+    }
+}
\ No newline at end of file
diff --git a/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NxmHeaderTest.java b/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/NxmHeaderTest.java
new file mode 100644 (file)
index 0000000..e05d0b1
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+
+public class NxmHeaderTest {
+
+    NxmHeader nxmHeader;
+
+    private static long header;
+    private static final int NXM_FIELD_CODE = 4;
+    private static final int VALUE_LENGTH = 14;
+
+    @Test
+    public void NxmHeaderTest() {
+        header = createHeader();
+        nxmHeader = new NxmHeader(header);
+
+        assertEquals(OxmMatchConstants.NXM_1_CLASS, nxmHeader.getOxmClass());
+        assertEquals(NXM_FIELD_CODE, nxmHeader.getNxmField());
+        assertEquals(false, nxmHeader.isHasMask());
+        assertEquals(VALUE_LENGTH, nxmHeader.getLength());
+    }
+
+    @Test
+    public void hashCodeTest() {
+
+    }
+
+    @Test
+    public void equalsTest() {
+        Object notHeader = new Object();
+        header = createHeader();
+        nxmHeader = new NxmHeader(header);
+
+        assertFalse(nxmHeader.equals(notHeader));
+    }
+
+    @Test
+    public void equalsTest1() {
+        header = createHeader();
+        nxmHeader = new NxmHeader(header);
+
+        assertTrue(nxmHeader.equals(nxmHeader));
+    }
+
+    @Test
+    public void toStringTest() {
+        header = createHeader();
+        nxmHeader = new NxmHeader(header);
+
+        String shouldBe = new String("NxmHeader " +
+                                        "[headerAsLong=" + header + ", " +
+                                        "oxmClass=" + OxmMatchConstants.NXM_1_CLASS + "," +
+                                        " nxmField=" + NXM_FIELD_CODE + "," +
+                                        " hasMask=" + false + "," +
+                                        " length=" + VALUE_LENGTH + "]");
+
+        assertEquals(shouldBe, nxmHeader.toString());
+    }
+
+
+    private long createHeader() {
+        long result = 0;
+        int oxmClass = 1 << 16;
+        result = result | oxmClass;
+        int oxmField = NXM_FIELD_CODE << 9;
+        result = result | oxmField;
+        int mask = 0 << 8;
+        result = result | mask;
+        int length = VALUE_LENGTH;
+        result = result | length;
+
+        return result;
+    }
+}
\ No newline at end of file
diff --git a/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/Reg0CodecTest.java b/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/Reg0CodecTest.java
new file mode 100644 (file)
index 0000000..bea66d3
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * 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.opendaylight.openflow.oxm.rev150225.Nxm1Class;
+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.NxmNxReg0;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.reg.grouping.RegValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.RegCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.RegCaseValueBuilder;
+
+public class Reg0CodecTest {
+
+    Reg0Codec reg0Codec;
+    ByteBuf buffer;
+    MatchEntry input;
+
+    private static final int NXM_FIELD_CODE = 0;
+    private static final int VALUE_LENGTH = 4;
+
+    @Before
+    public void setUp() {
+        reg0Codec = new Reg0Codec();
+        buffer = ByteBufAllocator.DEFAULT.buffer();
+    }
+
+    @Test
+    public void serializeTest() {
+        input = createMatchEntry();
+        reg0Codec.serialize(input, buffer);
+
+        assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
+        short fieldMask = buffer.readUnsignedByte();
+        assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+        assertEquals(0, fieldMask & 1);
+        assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+        assertEquals(1, buffer.readUnsignedInt());
+    }
+
+    @Test
+    public void deserializeTest() {
+        createBuffer(buffer);
+
+        input = reg0Codec.deserialize(buffer);
+
+        RegCaseValue result = ((RegCaseValue) input.getMatchEntryValue());
+
+        assertEquals(Nxm1Class.class, input.getOxmClass());
+        assertEquals(NxmNxReg0.class, input.getOxmMatchField());
+        assertEquals(false, input.isHasMask());
+        assertEquals(1, result.getRegValues().getValue().intValue());
+    }
+
+    private MatchEntry createMatchEntry() {
+        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+        RegCaseValueBuilder caseBuilder = new RegCaseValueBuilder();
+        RegValuesBuilder valuesBuilder = new RegValuesBuilder();
+
+        matchEntryBuilder.setOxmClass(Nxm1Class.class);
+        matchEntryBuilder.setOxmMatchField(NxmNxReg0.class);
+        matchEntryBuilder.setHasMask(false);
+
+        valuesBuilder.setValue((long)1);
+
+        caseBuilder.setRegValues(valuesBuilder.build());
+        matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+        return matchEntryBuilder.build();
+    }
+
+    private void createBuffer(ByteBuf message) {
+        message.writeShort(OxmMatchConstants.NXM_1_CLASS);
+
+        int fieldMask = (NXM_FIELD_CODE << 1);
+        message.writeByte(fieldMask);
+        message.writeByte(VALUE_LENGTH);
+        message.writeInt(1);
+    }
+
+}
\ No newline at end of file
diff --git a/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/Reg1CodecTest.java b/extension/openflowjava-extension-nicira/src/test/java/org/opendaylight/openflowjava/nx/codec/match/Reg1CodecTest.java
new file mode 100644 (file)
index 0000000..8650e2c
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * 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.opendaylight.openflow.oxm.rev150225.Nxm1Class;
+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.NxmNxReg1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.reg.grouping.RegValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.RegCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.RegCaseValueBuilder;
+
+public class Reg1CodecTest {
+
+    Reg1Codec reg1Codec;
+    ByteBuf buffer;
+    MatchEntry input;
+
+    private static final int NXM_FIELD_CODE = 1;
+    private static final int VALUE_LENGTH = 4;
+
+    @Before
+    public void setUp() {
+        reg1Codec = new Reg1Codec();
+        buffer = ByteBufAllocator.DEFAULT.buffer();
+    }
+
+    @Test
+    public void serializeTest() {
+        input = createMatchEntry();
+        reg1Codec.serialize(input, buffer);
+
+        assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
+        short fieldMask = buffer.readUnsignedByte();
+        assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+        assertEquals(0, fieldMask & 1);
+        assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+        assertEquals(1, buffer.readUnsignedInt());
+    }
+
+    @Test
+    public void deserializeTest() {
+        createBuffer(buffer);
+
+        input = reg1Codec.deserialize(buffer);
+
+        RegCaseValue result = ((RegCaseValue) input.getMatchEntryValue());
+
+        assertEquals(Nxm1Class.class, input.getOxmClass());
+        assertEquals(NxmNxReg1.class, input.getOxmMatchField());
+        assertEquals(false, input.isHasMask());
+        assertEquals(1, result.getRegValues().getValue().intValue());
+    }
+
+    private MatchEntry createMatchEntry() {
+        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+        RegCaseValueBuilder caseBuilder = new RegCaseValueBuilder();
+        RegValuesBuilder valuesBuilder = new RegValuesBuilder();
+
+        matchEntryBuilder.setOxmClass(Nxm1Class.class);
+        matchEntryBuilder.setOxmMatchField(NxmNxReg1.class);
+        matchEntryBuilder.setHasMask(false);
+
+        valuesBuilder.setValue((long)1);
+
+        caseBuilder.setRegValues(valuesBuilder.build());
+        matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+        return matchEntryBuilder.build();
+    }
+
+    private void createBuffer(ByteBuf message) {
+        message.writeShort(OxmMatchConstants.NXM_1_CLASS);
+
+        int fieldMask = (NXM_FIELD_CODE << 1);
+        message.writeByte(fieldMask);
+        message.writeByte(VALUE_LENGTH);
+        message.writeInt(1);
+    }
+
+}
\ No newline at end of file