Bug 5543 - Bo: Update JUnit tests part_12 26/40726/2
authormiroslav.macko <miroslav.macko@pantheon.tech>
Wed, 22 Jun 2016 13:47:55 +0000 (15:47 +0200)
committermiroslav.macko <miroslav.macko@pantheon.tech>
Fri, 1 Jul 2016 08:42:08 +0000 (10:42 +0200)
- Added tests for openflowjava-extension-nicira

Change-Id: I1b400e3f15f0cb5ac5da647844f1abc613a4848a
Signed-off-by: miroslav.macko <miroslav.macko@pantheon.tech>
extension/openflowjava-extension-nicira-api/pom.xml
extension/openflowjava-extension-nicira-api/src/main/java/org/opendaylight/openflowjava/nx/api/impl/NiciraExtensionCodecRegistratorImpl.java
extension/openflowjava-extension-nicira-api/src/test/java/org/opendaylight/openflowjava/nx/api/impl/NiciraExtensionCodecRegistratorImplTest.java [new file with mode: 0644]

index 628180ba45357aa71be38c01c011526d83f31d9c..1d62f93ee69f40531d26ccd227da2d47d2df2129 100644 (file)
             <groupId>org.opendaylight.openflowjava</groupId>
             <artifactId>openflow-protocol-spi</artifactId>
         </dependency>
+
+        <!-- Test dependencies -->
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
index 505c087cc656e1d9a5d5a35a83d7efe5dc62c2f4..3b7f10771c93b200e5f69d44f8a2edd25a964e54 100644 (file)
@@ -11,6 +11,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
 import org.opendaylight.openflowjava.nx.api.NiciraExtensionCodecRegistrator;
@@ -197,7 +198,11 @@ public class NiciraExtensionCodecRegistratorImpl implements NiciraExtensionCodec
     @Override
     public void close() throws Exception {
         // TODO Auto-generated method stub
-        
+    }
+
+    @VisibleForTesting
+    boolean isEmptyActionDeserializers() {
+        return actionDeserializers.isEmpty();
     }
 
 }
diff --git a/extension/openflowjava-extension-nicira-api/src/test/java/org/opendaylight/openflowjava/nx/api/impl/NiciraExtensionCodecRegistratorImplTest.java b/extension/openflowjava-extension-nicira-api/src/test/java/org/opendaylight/openflowjava/nx/api/impl/NiciraExtensionCodecRegistratorImplTest.java
new file mode 100644 (file)
index 0000000..128bff0
--- /dev/null
@@ -0,0 +1,144 @@
+/**
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+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.NiciraActionSerializerKey;
+import org.opendaylight.openflowjava.nx.api.NiciraUtil;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class NiciraExtensionCodecRegistratorImplTest {
+
+
+    NiciraExtensionCodecRegistratorImpl niciraExtensionCodecRegistrator;
+    List<SwitchConnectionProvider> providers = new LinkedList<>();
+    NiciraActionSerializerKey actionSerializerKey;
+    NiciraActionDeserializerKey actionDeserializerKey;
+    MatchEntrySerializerKey matchSerializerKey;
+    MatchEntryDeserializerKey matchDeserializerKey;
+
+    @Mock
+    OFSerializer<Action> actionSerializer;
+    @Mock
+    OFDeserializer<Action> actionDeserializer;
+    @Mock
+    OFSerializer<MatchEntry> matchSerializer;
+    @Mock
+    OFDeserializer<MatchEntry> matchDeserializer;
+
+
+    public static final short VERSION = 4;
+    public static final byte VERSION1 = EncodeConstants.OF10_VERSION_ID;
+    public static final byte VERSION2 = EncodeConstants.OF13_VERSION_ID;
+
+
+
+    @Mock
+    SwitchConnectionProvider provider;
+
+    @Before
+    public void setUp() {
+        providers.add(provider);
+        actionSerializerKey = new NiciraActionSerializerKey(VERSION, PopVlanCase.class);
+        //subtype = 10
+        actionDeserializerKey = new NiciraActionDeserializerKey(VERSION, 10);
+        matchSerializerKey = new MatchEntrySerializerKey(VERSION, Nxm0Class.class, MatchField.class);
+        //OxmClass 1, OxmField 2
+        matchDeserializerKey = new MatchEntryDeserializerKey(VERSION, 1, 2);
+
+        niciraExtensionCodecRegistrator = new NiciraExtensionCodecRegistratorImpl(providers);
+    }
+
+    @Test
+    public void niciraExtensionsCodecRegistratorImplTest() {
+        Mockito.verify(provider).registerActionDeserializer(Matchers.eq(ActionDeserializer.OF10_DESERIALIZER_KEY), Matchers.any(ActionDeserializer.class));
+        Mockito.verify(provider).registerActionDeserializer(Matchers.eq(ActionDeserializer.OF13_DESERIALIZER_KEY), Matchers.any(ActionDeserializer.class));
+    }
+
+    @Test
+    public void registerActionSerializerTest() {
+        niciraExtensionCodecRegistrator.registerActionSerializer(actionSerializerKey, actionSerializer);
+        ActionSerializerKey key1 = NiciraUtil.createOfJavaKeyFrom(actionSerializerKey);
+        Mockito.verify(provider).registerActionSerializer(Matchers.eq(key1), Matchers.any(OFGeneralSerializer.class));
+    }
+
+    @Test
+    public void unregisterActionSerializerTest() {
+        niciraExtensionCodecRegistrator.registerActionSerializer(actionSerializerKey, actionSerializer);
+        ActionSerializerKey key1 = NiciraUtil.createOfJavaKeyFrom(actionSerializerKey);
+        niciraExtensionCodecRegistrator.unregisterActionSerializer(actionSerializerKey);
+        Mockito.verify(provider).unregisterSerializer(Matchers.eq(key1));
+    }
+
+    @Test
+    public void registerActionDeserializerTest() {
+        assertTrue(niciraExtensionCodecRegistrator.isEmptyActionDeserializers());
+        niciraExtensionCodecRegistrator.registerActionDeserializer(actionDeserializerKey, actionDeserializer);
+        assertFalse(niciraExtensionCodecRegistrator.isEmptyActionDeserializers());
+    }
+
+    @Test
+    public void unregisterActionDeserializerTest() {
+        niciraExtensionCodecRegistrator.registerActionDeserializer(actionDeserializerKey, actionDeserializer);
+        assertFalse(niciraExtensionCodecRegistrator.isEmptyActionDeserializers());
+        niciraExtensionCodecRegistrator.unregisterActionDeserializer(actionDeserializerKey);
+        assertTrue(niciraExtensionCodecRegistrator.isEmptyActionDeserializers());
+    }
+
+    @Test
+    public void registerMatchEntrySerializerTest() {
+        niciraExtensionCodecRegistrator.registerMatchEntrySerializer(matchSerializerKey, matchSerializer);
+        Mockito.verify(provider).registerMatchEntrySerializer(matchSerializerKey, matchSerializer);
+    }
+
+    @Test
+    public void unregisterMatchEntrySerializerTest() {
+        niciraExtensionCodecRegistrator.unregisterMatchEntrySerializer(matchSerializerKey);
+        Mockito.verify(provider).unregisterSerializer(matchSerializerKey);
+    }
+
+    @Test
+    public void registerMatchEntryDeserializerTest() {
+        niciraExtensionCodecRegistrator.registerMatchEntryDeserializer(matchDeserializerKey, matchDeserializer);
+        Mockito.verify(provider).registerMatchEntryDeserializer(matchDeserializerKey, matchDeserializer);
+    }
+
+    @Test
+    public void unregisterMatchEntryDeserializerTest() {
+        niciraExtensionCodecRegistrator.unregisterMatchEntryDeserializer(matchDeserializerKey);
+        Mockito.verify(provider).unregisterDeserializer(matchDeserializerKey);
+    }
+
+
+}
\ No newline at end of file