package org.opendaylight.openflowplugin.impl.services.sal;
import com.google.common.collect.Lists;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Future;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.InOrder;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.add.groups.batch.input.BatchAddGroupsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.OriginalBatchedGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.UpdatedBatchedGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.output.list.grouping.BatchFailedGroupsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.remove.groups.batch.input.BatchRemoveGroups;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.remove.groups.batch.input.BatchRemoveGroupsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.update.groups.batch.input.BatchUpdateGroups;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Test for {@link org.opendaylight.openflowplugin.impl.services.sal.SalGroupsBatchServiceImpl}.
@Before
- public void setUp() throws Exception {
+ public void setUp() {
salGroupsBatchService = new SalGroupsBatchServiceImpl(salGroupService, transactionService);
- Mockito.when(transactionService.sendBarrier(Matchers.<SendBarrierInput>any()))
+ Mockito.when(transactionService.sendBarrier(ArgumentMatchers.any()))
.thenReturn(RpcResultBuilder.<SendBarrierOutput>success().buildFuture());
}
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
Mockito.verifyNoMoreInteractions(salGroupService, transactionService);
}
@Test
public void testUpdateGroupsBatch_success() throws Exception {
- Mockito.when(salGroupService.updateGroup(Mockito.<UpdateGroupInput>any()))
+ Mockito.when(salGroupService.updateGroup(Mockito.any()))
.thenReturn(RpcResultBuilder.success(new UpdateGroupOutputBuilder().build()).buildFuture());
final UpdateGroupsBatchInput input = new UpdateGroupsBatchInputBuilder()
Assert.assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue());
Assert.assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue());
- inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
+ inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any());
}
@Test
public void testUpdateGroupsBatch_failure() throws Exception {
- Mockito.when(salGroupService.updateGroup(Mockito.<UpdateGroupInput>any()))
+ Mockito.when(salGroupService.updateGroup(Mockito.any()))
.thenReturn(RpcResultBuilder.<UpdateGroupOutput>failed()
- .withError(RpcError.ErrorType.APPLICATION, "ur-groupUpdateError")
+ .withError(ErrorType.APPLICATION, "ur-groupUpdateError")
.buildFuture());
final UpdateGroupsBatchInput input = new UpdateGroupsBatchInputBuilder()
.build();
final Future<RpcResult<UpdateGroupsBatchOutput>> resultFuture = salGroupsBatchService.updateGroupsBatch(input);
+ Iterator<BatchFailedGroupsOutput> iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput()
+ .values().iterator();
Assert.assertTrue(resultFuture.isDone());
Assert.assertFalse(resultFuture.get().isSuccessful());
- Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedGroupsOutput().size());
- Assert.assertEquals(43L,
- resultFuture.get().getResult().getBatchFailedGroupsOutput().get(0).getGroupId().getValue().longValue());
- Assert.assertEquals(45L,
- resultFuture.get().getResult().getBatchFailedGroupsOutput().get(1).getGroupId().getValue().longValue());
+ Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size());
+ Assert.assertEquals(43L, iterator.next().getGroupId().getValue().longValue());
+ Assert.assertEquals(45L, iterator.next().getGroupId().getValue().longValue());
Assert.assertEquals(2, resultFuture.get().getErrors().size());
Assert.assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue());
Assert.assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue());
- inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
+ inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any());
}
@Test
public void testAddGroupsBatch_success() throws Exception {
- Mockito.when(salGroupService.addGroup(Mockito.<AddGroupInput>any()))
+ Mockito.when(salGroupService.addGroup(Mockito.any()))
.thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture());
final AddGroupsBatchInput input = new AddGroupsBatchInputBuilder()
.setNode(NODE_REF)
.setBarrierAfter(true)
- .setBatchAddGroups(Lists.newArrayList(
+ .setBatchAddGroups(BindingMap.ordered(
createEmptyBatchAddGroup(42L),
createEmptyBatchAddGroup(43L)))
.build();
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());
+ inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any());
}
@Test
public void testAddGroupsBatch_failure() throws Exception {
- Mockito.when(salGroupService.addGroup(Mockito.<AddGroupInput>any()))
+ Mockito.when(salGroupService.addGroup(Mockito.any()))
.thenReturn(RpcResultBuilder.<AddGroupOutput>failed()
- .withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError")
+ .withError(ErrorType.APPLICATION, "ut-groupAddError")
.buildFuture());
final AddGroupsBatchInput input = new AddGroupsBatchInputBuilder()
.setNode(NODE_REF)
.setBarrierAfter(true)
- .setBatchAddGroups(Lists.newArrayList(
+ .setBatchAddGroups(BindingMap.ordered(
createEmptyBatchAddGroup(42L),
createEmptyBatchAddGroup(43L)))
.build();
final Future<RpcResult<AddGroupsBatchOutput>> resultFuture = salGroupsBatchService.addGroupsBatch(input);
+ Iterator<BatchFailedGroupsOutput> iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput()
+ .values().iterator();
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().getResult().nonnullBatchFailedGroupsOutput().size());
+ Assert.assertEquals(42L, iterator.next().getGroupId().getValue().longValue());
+ Assert.assertEquals(43L, iterator.next().getGroupId().getValue().longValue());
Assert.assertEquals(2, resultFuture.get().getErrors().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());
+ inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any());
}
@Test
public void testRemoveGroupsBatch_success() throws Exception {
- Mockito.when(salGroupService.removeGroup(Mockito.<RemoveGroupInput>any()))
+ Mockito.when(salGroupService.removeGroup(Mockito.any()))
.thenReturn(RpcResultBuilder.success(new RemoveGroupOutputBuilder().build()).buildFuture());
final RemoveGroupsBatchInput input = new RemoveGroupsBatchInputBuilder()
.setNode(NODE_REF)
.setBarrierAfter(true)
- .setBatchRemoveGroups(Lists.newArrayList(
+ .setBatchRemoveGroups(BindingMap.ordered(
createEmptyBatchRemoveGroup(42L),
createEmptyBatchRemoveGroup(43L)))
.build();
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());
+ inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any());
}
@Test
public void testRemoveGroupsBatch_failure() throws Exception {
- Mockito.when(salGroupService.removeGroup(Mockito.<RemoveGroupInput>any()))
+ Mockito.when(salGroupService.removeGroup(Mockito.any()))
.thenReturn(RpcResultBuilder.<RemoveGroupOutput>failed()
- .withError(RpcError.ErrorType.APPLICATION, "ut-groupRemoveError")
+ .withError(ErrorType.APPLICATION, "ut-groupRemoveError")
.buildFuture());
final RemoveGroupsBatchInput input = new RemoveGroupsBatchInputBuilder()
.setNode(NODE_REF)
.setBarrierAfter(true)
- .setBatchRemoveGroups(Lists.newArrayList(
+ .setBatchRemoveGroups(BindingMap.ordered(
createEmptyBatchRemoveGroup(42L),
createEmptyBatchRemoveGroup(43L)))
.build();
final Future<RpcResult<RemoveGroupsBatchOutput>> resultFuture = salGroupsBatchService.removeGroupsBatch(input);
+ Iterator<BatchFailedGroupsOutput> iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput()
+ .values().iterator();
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().getResult().nonnullBatchFailedGroupsOutput().size());
+ Assert.assertEquals(42L, iterator.next().getGroupId().getValue().longValue());
+ Assert.assertEquals(43L, iterator.next().getGroupId().getValue().longValue());
Assert.assertEquals(2, resultFuture.get().getErrors().size());
final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService);
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());
+ inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any());
}
private static BatchAddGroups createEmptyBatchAddGroup(final long groupIdValue) {
return new BatchAddGroupsBuilder()
- .setGroupId(new GroupId(groupIdValue))
+ .setGroupId(new GroupId(Uint32.valueOf(groupIdValue)))
.build();
}
private static BatchRemoveGroups createEmptyBatchRemoveGroup(final long groupIdValue) {
return new BatchRemoveGroupsBuilder()
- .setGroupId(new GroupId(groupIdValue))
+ .setGroupId(new GroupId(Uint32.valueOf(groupIdValue)))
.build();
}