Search in sources :

Example 6 with SalGroupService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService in project openflowplugin by opendaylight.

the class SalGroupsBatchServiceImplTest method testAddGroupsBatch_success.

@Test
public void testAddGroupsBatch_success() throws Exception {
    Mockito.when(salGroupService.addGroup(Mockito.<AddGroupInput>any())).thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture());
    final AddGroupsBatchInput input = new AddGroupsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddGroups(Lists.newArrayList(createEmptyBatchAddGroup(42L), createEmptyBatchAddGroup(43L))).build();
    final Future<RpcResult<AddGroupsBatchOutput>> resultFuture = salGroupsBatchService.addGroupsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertTrue(resultFuture.get().isSuccessful());
    final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService);
    inOrder.verify(salGroupService, Mockito.times(2)).addGroup(addGroupInputCpt.capture());
    final List<AddGroupInput> allValues = addGroupInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue());
    Assert.assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : InOrder(org.mockito.InOrder) AddGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput) AddGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddGroupOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder) AddGroupsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInputBuilder) Test(org.junit.Test)

Example 7 with SalGroupService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService in project openflowplugin by opendaylight.

the class GroupListenerTest method removeGroupTest.

@Test
public void removeGroupTest() throws Exception {
    addFlowCapableNode(NODE_KEY);
    GroupKey groupKey = new GroupKey(new GroupId((long) 255));
    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();
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
    assertCommit(writeTx.submit());
    SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
    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());
    salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
    List<RemoveGroupInput> removeGroupCalls = salGroupService.getRemoveGroupCalls();
    assertEquals(1, removeGroupCalls.size());
    assertEquals("DOM-1", removeGroupCalls.get(0).getTransactionUri().getValue());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RemoveGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput) StaleGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) AddGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) StaleGroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroupBuilder) GroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder) GroupKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey) StaleGroupKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroupKey) SalGroupServiceMock(test.mock.util.SalGroupServiceMock) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 8 with SalGroupService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService in project openflowplugin by opendaylight.

the class GroupForwarderTest method testRemove.

@Test
public void testRemove() throws Exception {
    Mockito.when(salGroupService.removeGroup(removeGroupInputCpt.capture())).thenReturn(RpcResultBuilder.success(new RemoveGroupOutputBuilder().setTransactionId(txId).build()).buildFuture());
    final Future<RpcResult<RemoveGroupOutput>> addResult = groupForwarder.remove(groupPath, group, flowCapableNodePath);
    Mockito.verify(salGroupService).removeGroup(Matchers.<RemoveGroupInput>any());
    Assert.assertTrue(addResult.isDone());
    final RpcResult<RemoveGroupOutput> result = addResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(result.isSuccessful());
    Assert.assertEquals(1, result.getResult().getTransactionId().getValue().intValue());
    final RemoveGroupInput removeGroupInput = removeGroupInputCpt.getValue();
    Assert.assertEquals(groupPath, removeGroupInput.getGroupRef().getValue());
    Assert.assertNull(removeGroupInput.getBuckets());
    Assert.assertEquals(nodePath, removeGroupInput.getNode().getValue());
    Assert.assertEquals("test-group", removeGroupInput.getGroupName());
}
Also used : RemoveGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput) RemoveGroupOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder) RemoveGroupOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Test(org.junit.Test)

Example 9 with SalGroupService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService in project openflowplugin by opendaylight.

the class GroupForwarderTest method testAdd.

@Test
public void testAdd() throws Exception {
    Mockito.when(salGroupService.addGroup(addGroupInputCpt.capture())).thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().setTransactionId(txId).build()).buildFuture());
    final Future<RpcResult<AddGroupOutput>> addResult = groupForwarder.add(groupPath, group, flowCapableNodePath);
    Mockito.verify(salGroupService).addGroup(Matchers.<AddGroupInput>any());
    Assert.assertTrue(addResult.isDone());
    final RpcResult<AddGroupOutput> result = addResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(result.isSuccessful());
    Assert.assertEquals(1, result.getResult().getTransactionId().getValue().intValue());
    final AddGroupInput addGroupInput = addGroupInputCpt.getValue();
    Assert.assertEquals(groupPath, addGroupInput.getGroupRef().getValue());
    Assert.assertEquals(nodePath, addGroupInput.getNode().getValue());
    Assert.assertNotNull(addGroupInput.getBuckets());
    Assert.assertEquals("test-group", addGroupInput.getGroupName());
}
Also used : AddGroupOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput) AddGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddGroupOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder) Test(org.junit.Test)

Example 10 with SalGroupService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService in project openflowplugin by opendaylight.

the class SalGroupsBatchServiceImplTest method testAddGroupsBatch_failure.

@Test
public void testAddGroupsBatch_failure() throws Exception {
    Mockito.when(salGroupService.addGroup(Mockito.<AddGroupInput>any())).thenReturn(RpcResultBuilder.<AddGroupOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError").buildFuture());
    final AddGroupsBatchInput input = new AddGroupsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddGroups(Lists.newArrayList(createEmptyBatchAddGroup(42L), createEmptyBatchAddGroup(43L))).build();
    final Future<RpcResult<AddGroupsBatchOutput>> resultFuture = salGroupsBatchService.addGroupsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedGroupsOutput().size());
    Assert.assertEquals(42L, resultFuture.get().getResult().getBatchFailedGroupsOutput().get(0).getGroupId().getValue().longValue());
    Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedGroupsOutput().get(1).getGroupId().getValue().longValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService);
    inOrder.verify(salGroupService, Mockito.times(2)).addGroup(addGroupInputCpt.capture());
    final List<AddGroupInput> allValues = addGroupInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue());
    Assert.assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : InOrder(org.mockito.InOrder) AddGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput) AddGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddGroupsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInputBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 InOrder (org.mockito.InOrder)6 AddGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput)6 RemoveGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput)4 UpdateGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput)4 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)4 GroupBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder)4 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)3 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)3 GroupKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey)3 StaleGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup)3 StaleGroupBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroupBuilder)3 StaleGroupKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroupKey)3 FRMTest (test.mock.util.FRMTest)3 SalGroupServiceMock (test.mock.util.SalGroupServiceMock)3 AddGroupOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder)2 RemoveGroupOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder)2