Merge "Bug 4957 TxChainManager lifecycle startup cleaning"
[openflowplugin.git] / applications / forwardingrules-manager / src / test / java / test / mock / TableFeaturesListenerTest.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package test.mock;
9
10 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
12
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
14 import test.mock.util.EntityOwnershipServiceMock;
15 import test.mock.util.SalTableServiceMock;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
22 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import test.mock.util.FRMTest;
32 import test.mock.util.RpcProviderRegistryMock;
33 import java.util.List;
34 import static org.junit.Assert.assertEquals;
35
36 public class TableFeaturesListenerTest extends FRMTest {
37     RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
38     EntityOwnershipService eos = new EntityOwnershipServiceMock();
39
40
41     @Test
42     public void updateFlowTest() throws Exception {
43         NodeKey s1Key = new NodeKey(new NodeId("S1"));
44         TableKey tableKey = new TableKey((short) 2);
45         TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId());
46         ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(
47                 getDataBroker(),
48                 rpcProviderRegistryMock,
49                 getConfig(),
50                 eos);
51         forwardingRulesManager.start();
52
53         addTable(tableKey, s1Key);
54
55         TableFeatures tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).build();
56         InstanceIdentifier<TableFeatures> tableFeaturesII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
57               .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(TableFeatures.class, tableFeaturesKey);
58         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
59         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
60         assertCommit(writeTx.submit());
61
62         tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).setName("dummy name").build();
63         writeTx = getDataBroker().newWriteOnlyTransaction();
64         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
65         assertCommit(writeTx.submit());
66
67         SalTableServiceMock salTableServiceMock = (SalTableServiceMock) forwardingRulesManager.getSalTableService();
68         List<UpdateTableInput> updateTableInputs = salTableServiceMock.getUpdateTableInput();
69         assertEquals(1, updateTableInputs.size());
70         assertEquals("DOM-0", updateTableInputs.get(0).getTransactionUri().getValue());
71
72         forwardingRulesManager.close();
73     }
74 }