-/**
+/*
* Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package test.mock;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import java.util.List;
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.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
import org.opendaylight.openflowplugin.applications.frm.impl.DeviceMastershipManager;
import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
+import org.opendaylight.openflowplugin.applications.frm.recovery.OpenflowServiceRecoveryHandler;
+import org.opendaylight.openflowplugin.applications.reconciliation.ReconciliationManager;
+import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
@RunWith(MockitoJUnitRunner.class)
public class GroupListenerTest 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();
+ private static final NodeId NODE_ID = new NodeId("testnode:1");
+ private static final NodeKey NODE_KEY = new NodeKey(NODE_ID);
+ RpcProviderRegistryMock rpcProviderRegistryMock = new RpcProviderRegistryMock();
@Mock
ClusterSingletonServiceProvider clusterSingletonService;
@Mock
DeviceMastershipManager deviceMastershipManager;
@Mock
- private NotificationProviderService notificationService;
+ private ReconciliationManager reconciliationManager;
+ @Mock
+ private OpenflowServiceRecoveryHandler openflowServiceRecoveryHandler;
+ @Mock
+ private ServiceRecoveryRegistry serviceRecoveryRegistry;
+ @Mock
+ private MastershipChangeServiceManager mastershipChangeServiceManager;
@Before
public void setUp() {
forwardingRulesManager = new ForwardingRulesManagerImpl(
getDataBroker(),
rpcProviderRegistryMock,
+ rpcProviderRegistryMock,
getConfig(),
+ mastershipChangeServiceManager,
clusterSingletonService,
- notificationService);
+ getConfigurationService(),
+ reconciliationManager,
+ openflowServiceRecoveryHandler,
+ serviceRecoveryRegistry);
+
forwardingRulesManager.start();
// TODO consider tests rewrite (added because of complicated access)
forwardingRulesManager.setDeviceMastershipManager(deviceMastershipManager);
@Test
public void addTwoGroupsTest() throws Exception {
- addFlowCapableNode(s1Key);
+ addFlowCapableNode(NODE_KEY);
GroupKey groupKey = new GroupKey(new GroupId((long) 255));
- InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
+ InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
.augmentation(FlowCapableNode.class).child(Group.class, groupKey);
- Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
+ Group group = new GroupBuilder().withKey(groupKey).setGroupName("Group1").build();
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+ await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(1));
List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
assertEquals(1, addGroupCalls.size());
assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
groupKey = new GroupKey(new GroupId((long) 256));
- groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
+ groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
.augmentation(FlowCapableNode.class).child(Group.class, groupKey);
- group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
+ group = new GroupBuilder().withKey(groupKey).setGroupName("Group1").build();
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+ await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(2));
addGroupCalls = salGroupService.getAddGroupCalls();
assertEquals(2, addGroupCalls.size());
assertEquals("DOM-1", addGroupCalls.get(1).getTransactionUri().getValue());
@Test
public void updateGroupTest() throws Exception {
- addFlowCapableNode(s1Key);
+ addFlowCapableNode(NODE_KEY);
GroupKey groupKey = new GroupKey(new GroupId((long) 255));
- InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
+ InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
.augmentation(FlowCapableNode.class).child(Group.class, groupKey);
- Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
+ Group group = new GroupBuilder().withKey(groupKey).setGroupName("Group1").build();
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+ await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(1));
List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
assertEquals(1, addGroupCalls.size());
assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
- group = new GroupBuilder().setKey(groupKey).setGroupName("Group2").build();
+ group = new GroupBuilder().withKey(groupKey).setGroupName("Group2").build();
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+ await().until(listSize(salGroupService.getUpdateGroupCalls()), equalTo(1));
List<UpdateGroupInput> updateGroupCalls = salGroupService.getUpdateGroupCalls();
assertEquals(1, updateGroupCalls.size());
assertEquals("DOM-1", updateGroupCalls.get(0).getTransactionUri().getValue());
@Test
public void removeGroupTest() throws Exception {
- addFlowCapableNode(s1Key);
+ addFlowCapableNode(NODE_KEY);
GroupKey groupKey = new GroupKey(new GroupId((long) 255));
- InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
+ InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
.augmentation(FlowCapableNode.class).child(Group.class, groupKey);
- Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
+ Group group = new GroupBuilder().withKey(groupKey).setGroupName("Group1").build();
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+ await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(1));
List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
assertEquals(1, addGroupCalls.size());
assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, groupII);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+ await().until(listSize(salGroupService.getRemoveGroupCalls()), equalTo(1));
List<RemoveGroupInput> removeGroupCalls = salGroupService.getRemoveGroupCalls();
assertEquals(1, removeGroupCalls.size());
assertEquals("DOM-1", removeGroupCalls.get(0).getTransactionUri().getValue());
@Test
public void staleGroupCreationTest() throws Exception {
- addFlowCapableNode(s1Key);
+ addFlowCapableNode(NODE_KEY);
StaleGroupKey groupKey = new StaleGroupKey(new GroupId((long) 255));
- InstanceIdentifier<StaleGroup> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
+ InstanceIdentifier<StaleGroup> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)
.augmentation(FlowCapableNode.class).child(StaleGroup.class, groupKey);
- StaleGroup group = new StaleGroupBuilder().setKey(groupKey).setGroupName("Stale_Group1").build();
+ StaleGroup group = new StaleGroupBuilder().withKey(groupKey).setGroupName("Stale_Group1").build();
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
- assertCommit(writeTx.submit());
+ assertCommit(writeTx.commit());
}
@After
public void tearDown() throws Exception {
forwardingRulesManager.close();
}
-
}