OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / applications / forwardingrules-manager / src / test / java / test / mock / util / FRMTest.java
index a92c33432d189b8858490bcb5f98de458427e171..02bcd1ee5411c7615be7168dafc47307c32e2768 100644 (file)
@@ -1,33 +1,50 @@
+/*
+ * Copyright (c) 2014, 2017 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 test.mock.util;
 
 import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
+import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfigBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public abstract class FRMTest extends AbstractDataBrokerTest {
 
-    public void addFlowCapableNode(NodeKey nodeKey) throws ExecutionException, InterruptedException {
+    public void addFlowCapableNode(NodeKey nodeKey) {
         Nodes nodes = new NodesBuilder().setNode(Collections.<Node>emptyList()).build();
-        InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class)
-                .child(Node.class, nodeKey);
 
         FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder();
         NodeBuilder nodeBuilder = new NodeBuilder();
-        nodeBuilder.setKey(nodeKey);
+        nodeBuilder.withKey(nodeKey);
         nodeBuilder.addAugmentation(FlowCapableNode.class, fcnBuilder.build());
 
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes);
+
+        InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey);
         writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build());
         writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build());
@@ -36,7 +53,57 @@ public abstract class FRMTest extends AbstractDataBrokerTest {
 
     public void removeNode(NodeKey nodeKey) throws ExecutionException, InterruptedException {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
-        writeTx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey));
+        writeTx.delete(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey));
         writeTx.submit().get();
     }
+
+    public void addTable(final TableKey tableKey, final NodeKey nodeKey) {
+        addFlowCapableNode(nodeKey);
+        final Table table = new TableBuilder().withKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
+        WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+        InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey)
+                .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
+        writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
+        assertCommit(writeTx.submit());
+    }
+
+    public ForwardingRulesManagerConfig getConfig() {
+        ForwardingRulesManagerConfigBuilder cfgBuilder = new ForwardingRulesManagerConfigBuilder();
+        cfgBuilder.setDisableReconciliation(false);
+        cfgBuilder.setStaleMarkingEnabled(false);
+        cfgBuilder.setReconciliationRetryCount(0);
+        cfgBuilder.setBundleBasedReconciliationEnabled(false);
+        return cfgBuilder.build();
+    }
+
+    public ConfigurationService getConfigurationService() {
+        final ConfigurationService configurationService = Mockito.mock(ConfigurationService.class);
+        final ForwardingRulesManagerConfig config = getConfig();
+
+        Mockito.when(configurationService.registerListener(Mockito.any())).thenReturn(() -> {
+        });
+
+        Mockito.lenient().when(configurationService.getProperty(Mockito.eq("disable-reconciliation"), Mockito.any()))
+                .thenReturn(config.isDisableReconciliation());
+
+        Mockito.lenient().when(configurationService.getProperty(Mockito.eq("stale-marking-enabled"), Mockito.any()))
+                .thenReturn(config.isStaleMarkingEnabled());
+
+        Mockito.lenient().when(configurationService.getProperty(Mockito.eq("reconciliation-retry-count"),
+                Mockito.any())).thenReturn(config.getReconciliationRetryCount());
+
+        Mockito.lenient().when(configurationService.getProperty(Mockito.eq("bundle-based-reconciliation-enabled"),
+                Mockito.any())).thenReturn(config.isBundleBasedReconciliationEnabled());
+
+        return configurationService;
+    }
+
+    protected Callable<Integer> listSize(List<?> list) {
+        return new Callable<Integer>() {
+            public Integer call() throws Exception {
+                return list.size(); // The condition supplier part
+            }
+        };
+    }
 }