--- /dev/null
+/**
+ * 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.api;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class NiciraActionDeserializerKeyTest {
+
+ NiciraActionDeserializerKey niciraActionDeserializerKey;
+
+ private static final short VERSION = 4;
+
+
+ /**
+ * If SUBTYPE is not Uint16 exception should be thrown
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void niciraActionDeserializerKeyTest1() {
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, -10);
+ }
+
+ /**
+ * If SUBTYPE is Uint16 it should be set and version should be set also
+ */
+ @Test
+ public void niciraActionDeserializerKeyTest2() {
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+ assertEquals(VERSION, niciraActionDeserializerKey.getVersion());
+ assertEquals(10, niciraActionDeserializerKey.getSubtype());
+ }
+
+
+ @Test
+ public void hashCodeTest() {
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+ assertEquals(1275, niciraActionDeserializerKey.hashCode());
+ }
+
+ /**
+ * If input param obj is null FALSE should be returned
+ */
+ @Test
+ public void equalsTest1() {
+ Object obj = null;
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+
+ assertFalse(niciraActionDeserializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is NOT null but is different class FALSE should be returned
+ */
+ @Test
+ public void equalsTest2() {
+ Object obj = new Object();
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+
+ assertFalse(niciraActionDeserializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is same class but has different SUBTYPE value FALSE should be returned
+ */
+ @Test
+ public void equalsTest3() {
+ NiciraActionDeserializerKey obj = new NiciraActionDeserializerKey(VERSION, 9);
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+
+ assertFalse(niciraActionDeserializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is same class but has different VERSION value FALSE should be returned
+ */
+ @Test
+ public void equalsTest4() {
+ NiciraActionDeserializerKey obj = new NiciraActionDeserializerKey((short)5, 10);
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+
+ assertFalse(niciraActionDeserializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is absolutely same TRUE should be returned
+ */
+ @Test
+ public void equalsTest5() {
+ NiciraActionDeserializerKey obj = new NiciraActionDeserializerKey(VERSION, 10);
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+
+ assertTrue(niciraActionDeserializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is same instance TRUE should be returned
+ */
+ @Test
+ public void equalsTest6() {
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+
+ assertTrue(niciraActionDeserializerKey.equals(niciraActionDeserializerKey));
+ }
+
+ @Test
+ public void toStringTest() {
+ niciraActionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+ String shouldBe = new String("NiciraActionDeserializerKey [version=4, subtype=10]");
+
+ assertEquals(shouldBe, niciraActionDeserializerKey.toString());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/**
+ * 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.api;
+
+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.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase;
+
+public class NiciraActionSerializerKeyTest {
+
+
+ NiciraActionSerializerKey niciraActionSerializerKey;
+
+ private static final short VERSION = 4;
+
+
+ @Test
+ public void niciraActionSerializerKeyTest() {
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+
+ assertEquals(VERSION, niciraActionSerializerKey.getVersion());
+ assertEquals(SubtypeClass.class, niciraActionSerializerKey.getSubtype());
+ }
+
+ /**
+ * If input param obj is NULL then FALSE should be returned
+ */
+ @Test
+ public void equalsTest1() {
+ Object obj = null;
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+
+ assertFalse(niciraActionSerializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is NOT NULL but is instance of different class then FALSE should be returned
+ */
+ @Test
+ public void equalsTest2() {
+ Object obj = new Object();
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+
+ assertFalse(niciraActionSerializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is instance of the same class but this.subtype is NULL then FALSE should be returned
+ */
+ @Test
+ public void equalsTest3() {
+ NiciraActionSerializerKey obj = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, null);
+
+ assertFalse(niciraActionSerializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is instance of the same class but has different SUBTYPE then FALSE should be returned
+ */
+ @Test
+ public void equalsTest4() {
+ NiciraActionSerializerKey obj = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, PopVlanCase.class);
+
+ assertFalse(niciraActionSerializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is instance of the same class but has different VERSION then FALSE should be returned
+ */
+ @Test
+ public void equalsTest5() {
+ NiciraActionSerializerKey obj = new NiciraActionSerializerKey((short)5, SubtypeClass.class);
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+
+ assertFalse(niciraActionSerializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is instance of the same class and has same VERSION and SUBTYPE then TRUE should be returned
+ */
+ @Test
+ public void equalsTest6() {
+ NiciraActionSerializerKey obj = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+
+ assertTrue(niciraActionSerializerKey.equals(obj));
+ }
+
+ /**
+ * If input param obj is exactly same TRUE should be returned
+ */
+ @Test
+ public void equalsTest7() {
+ niciraActionSerializerKey = new NiciraActionSerializerKey(VERSION, SubtypeClass.class);
+
+ assertTrue(niciraActionSerializerKey.equals(niciraActionSerializerKey));
+ }
+
+
+
+ private interface SubtypeClass extends ActionChoice {}
+
+
+}
\ No newline at end of file
--- /dev/null
+/**
+ * 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.api.impl;
+
+import static org.junit.Assert.assertNull;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
+import org.opendaylight.openflowjava.nx.api.NiciraConstants;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ActionDeserializerTest {
+
+ ActionDeserializer actionDeserializer;
+ ByteBuf buffer;
+ NiciraExtensionCodecRegistratorImpl niciraExtensionCodecRegistrator;
+ List<SwitchConnectionProvider> providers;
+
+
+ @Mock
+ OFDeserializer<Action> deserializer;
+ @Mock
+ SwitchConnectionProvider provider;
+ @Mock
+ OFDeserializer<Action> ofDeserializer;
+
+
+
+
+ private static final short VERSION = 4;
+ private static final long EXPERIMENT_ID = NiciraConstants.NX_VENDOR_ID;
+ private static final byte SUBTYPE = 10;
+
+ @Before
+ public void setUp() {
+ actionDeserializer = new ActionDeserializer(VERSION);
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ providers = new LinkedList<>();
+
+
+ }
+
+
+ /**
+ * If NiciraExtensionCodecRegistratorImpl.getActionDeserializer(actionSerializerKey) returns NULL
+ * then NULL should be returned
+ */
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+ assertNull(actionDeserializer.deserialize(buffer));
+ }
+
+ /**
+ * If experimentId is different from NiciraConstants.NX_VENDOR_ID
+ * then exception should be thrown
+ */
+ @Test(expected = IllegalStateException.class)
+ public void deserializeTest1() {
+ createBufferWithWrongExperimentId(buffer);
+ actionDeserializer.deserialize(buffer);
+ }
+
+ @Test
+ public void deserializeTest2() {
+ createBuffer(buffer);
+ addRecordToMap();
+
+ actionDeserializer.deserialize(buffer);
+
+ Mockito.verify(deserializer).deserialize(buffer);
+ }
+
+ private void createBuffer(ByteBuf message) {
+ //size of experiment type
+ message.writeShort(1);
+ //size of length
+ message.writeShort(13);
+ //experimentId
+ message.writeInt((int)EXPERIMENT_ID);
+ //subtype
+ message.writeShort(SUBTYPE);
+ }
+
+ private void createBufferWithWrongExperimentId(ByteBuf message) {
+ //size of experiment type
+ message.writeShort(1);
+ //size of length
+ message.writeShort(13);
+ //experimentId
+ message.writeInt(1);
+ //subtype
+ message.writeShort(SUBTYPE);
+ }
+
+ private void addRecordToMap() {
+ niciraExtensionCodecRegistrator = new NiciraExtensionCodecRegistratorImpl(providers);
+ NiciraActionDeserializerKey key = new NiciraActionDeserializerKey(VERSION, SUBTYPE);
+
+ niciraExtensionCodecRegistrator.registerActionDeserializer(key, deserializer);
+ }
+
+}
\ No newline at end of file