*/
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.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.openflowplugin.applications.reconciliation.ReconciliationManager;
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);
+ private static final NodeId NODE_ID = new NodeId("testnode:1");
+ private static final NodeKey NODE_KEY = new NodeKey(NODE_ID);
RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
@Mock
ClusterSingletonServiceProvider clusterSingletonService;
@Mock
DeviceMastershipManager deviceMastershipManager;
+ @Mock
+ private NotificationProviderService notificationService;
+ @Mock
+ private ReconciliationManager reconciliationManager;
+
@Before
public void setUp() {
getDataBroker(),
rpcProviderRegistryMock,
getConfig(),
- clusterSingletonService);
+ clusterSingletonService,
+ notificationService,
+ getConfigurationService(),
+ reconciliationManager);
+
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());
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());
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());
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());
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());
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.delete(LogicalDatastoreType.CONFIGURATION, groupII);
assertCommit(writeTx.submit());
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);
public void tearDown() throws Exception {
forwardingRulesManager.close();
}
-
}