Merge changes from topic 'BUG-3774'
[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.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
11
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
13 import test.mock.util.SalTableServiceMock;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
20 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import test.mock.util.FRMTest;
30 import test.mock.util.RpcProviderRegistryMock;
31 import java.util.List;
32 import static org.junit.Assert.assertEquals;
33
34 public class TableFeaturesListenerTest extends FRMTest {
35     RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
36
37     @Test
38     public void updateFlowTest() throws Exception {
39         NodeKey s1Key = new NodeKey(new NodeId("S1"));
40         TableKey tableKey = new TableKey((short) 2);
41         TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId());
42         ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(
43                 getDataBroker(),
44                 rpcProviderRegistryMock,
45                 getConfig());
46         forwardingRulesManager.start();
47
48         addTable(tableKey, s1Key);
49
50         TableFeatures tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).build();
51         InstanceIdentifier<TableFeatures> tableFeaturesII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
52               .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(TableFeatures.class, tableFeaturesKey);
53         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
54         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
55         assertCommit(writeTx.submit());
56
57         tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).setName("dummy name").build();
58         writeTx = getDataBroker().newWriteOnlyTransaction();
59         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
60         assertCommit(writeTx.submit());
61
62         SalTableServiceMock salTableServiceMock = (SalTableServiceMock) forwardingRulesManager.getSalTableService();
63         List<UpdateTableInput> updateTableInputs = salTableServiceMock.getUpdateTableInput();
64         assertEquals(1, updateTableInputs.size());
65         assertEquals("DOM-0", updateTableInputs.get(0).getTransactionUri().getValue());
66
67         forwardingRulesManager.close();
68     }
69 }