ClassifierUpdate unit tests 28/55228/7
authorJaime Caamaño Ruiz <jaime.caamano.ruiz@ericsson.com>
Wed, 19 Apr 2017 13:55:02 +0000 (15:55 +0200)
committerSam Hague <shague@redhat.com>
Fri, 28 Apr 2017 12:40:32 +0000 (12:40 +0000)
Change-Id: I4baa75c75c590e35a44da8b61e86eb27e625f79c
Signed-off-by: Jaime Caamaño Ruiz <jaime.caamano.ruiz@ericsson.com>
vpnservice/sfc/classifier/impl/src/test/java/org/opendaylight/netvirt/sfc/classifier/service/domain/impl/ClassifierUpdateTest.java [new file with mode: 0644]

diff --git a/vpnservice/sfc/classifier/impl/src/test/java/org/opendaylight/netvirt/sfc/classifier/service/domain/impl/ClassifierUpdateTest.java b/vpnservice/sfc/classifier/impl/src/test/java/org/opendaylight/netvirt/sfc/classifier/service/domain/impl/ClassifierUpdateTest.java
new file mode 100644 (file)
index 0000000..f00b350
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2017 Ericsson 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.netvirt.sfc.classifier.service.domain.impl;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.internal.util.collections.Sets;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.netvirt.sfc.classifier.service.domain.ClassifierEntry;
+import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierEntryRenderer;
+import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ClassifierUpdateTest {
+
+    @Mock
+    private ClassifierEntryRenderer rendererA;
+
+    @Mock
+    private ClassifierEntryRenderer rendererB;
+
+    @Mock
+    private ClassifierState configurationState;
+
+    @Mock
+    private ClassifierState operationalState;
+
+    private ClassifierUpdate classifierUpdate;
+
+    @Before
+    public void setup() {
+        classifierUpdate = new ClassifierUpdate(
+                configurationState,
+                operationalState,
+                Arrays.asList(rendererA, rendererB));
+    }
+
+    @Test
+    public void update() throws Exception {
+        ClassifierEntry configOnly = ClassifierEntry.buildIngressEntry(new InterfaceKey("configOnly"));
+        ClassifierEntry operOnly = ClassifierEntry.buildIngressEntry(new InterfaceKey("operOnly"));
+        ClassifierEntry configAndOper = ClassifierEntry.buildIngressEntry(new InterfaceKey("configAndOper"));
+        when(configurationState.getAllEntries()).thenReturn(Sets.newSet(configOnly, configAndOper));
+        when(operationalState.getAllEntries()).thenReturn(Sets.newSet(configAndOper, operOnly));
+        classifierUpdate.run();
+        verify(rendererA).renderIngress(new InterfaceKey("configOnly"));
+        verify(rendererB).renderIngress(new InterfaceKey("configOnly"));
+        verify(rendererA).suppressIngress(new InterfaceKey("operOnly"));
+        verify(rendererB).suppressIngress(new InterfaceKey("operOnly"));
+        verifyNoMoreInteractions(rendererA);
+        verifyNoMoreInteractions(rendererB);
+    }
+
+}