X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=applications%2Fforwardingrules-manager%2Fsrc%2Ftest%2Fjava%2Ftest%2Fmock%2FTableFeaturesListenerTest.java;h=1060e795bde9eb1268effc99027183eb3840d5b9;hb=64965a7e88cfb22b180536b56f03bd528bf696bb;hp=c90d3507bde6a7f0c9453325f3848248d54275ef;hpb=0d5980ab7f1b45b5226e8d235fd4672e64dfbbe4;p=openflowplugin.git diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java index c90d3507bd..1060e795bd 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java @@ -7,54 +7,75 @@ */ package test.mock; -import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey; +import static org.junit.Assert.assertEquals; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; -import test.mock.util.EntityOwnershipServiceMock; -import test.mock.util.SalTableServiceMock; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures; +import java.util.List; +import org.junit.After; +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.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.openflowplugin.applications.frm.impl.DeviceMastershipManager; import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; -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.TableKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import test.mock.util.FRMTest; import test.mock.util.RpcProviderRegistryMock; -import java.util.List; -import static org.junit.Assert.assertEquals; +import test.mock.util.SalTableServiceMock; +@RunWith(MockitoJUnitRunner.class) public class TableFeaturesListenerTest extends FRMTest { + private ForwardingRulesManagerImpl forwardingRulesManager; + private final static NodeId NODE_ID = new NodeId("testnode:1"); + private final static NodeKey s1Key = new NodeKey(NODE_ID); RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock(); - EntityOwnershipService eos = new EntityOwnershipServiceMock(); - + @Mock + ClusterSingletonServiceProvider clusterSingletonService; + @Mock + DeviceMastershipManager deviceMastershipManager; + @Mock + private NotificationProviderService notificationService; - @Test - public void updateFlowTest() throws Exception { - NodeKey s1Key = new NodeKey(new NodeId("S1")); - TableKey tableKey = new TableKey((short) 2); - TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId()); - ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl( + @Before + public void setUp() { + forwardingRulesManager = new ForwardingRulesManagerImpl( getDataBroker(), rpcProviderRegistryMock, getConfig(), - eos); + clusterSingletonService, + notificationService); forwardingRulesManager.start(); + // TODO consider tests rewrite (added because of complicated access) + forwardingRulesManager.setDeviceMastershipManager(deviceMastershipManager); + Mockito.when(deviceMastershipManager.isDeviceMastered(NODE_ID)).thenReturn(true); + } + + @Test + public void updateFlowTest() { + TableKey tableKey = new TableKey((short) 2); + TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId()); addTable(tableKey, s1Key); TableFeatures tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).build(); InstanceIdentifier tableFeaturesII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) - .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(TableFeatures.class, tableFeaturesKey); + .augmentation(FlowCapableNode.class).child(TableFeatures.class, tableFeaturesKey); WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData); assertCommit(writeTx.submit()); @@ -68,7 +89,11 @@ public class TableFeaturesListenerTest extends FRMTest { List updateTableInputs = salTableServiceMock.getUpdateTableInput(); assertEquals(1, updateTableInputs.size()); assertEquals("DOM-0", updateTableInputs.get(0).getTransactionUri().getValue()); + } + @After + public void tearDown() throws Exception { forwardingRulesManager.close(); } + }