Search in sources :

Example 11 with SalMeterService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService in project openflowplugin by opendaylight.

the class SalMetersBatchServiceImplTest method testUpdateMetersBatch_failure.

@Test
public void testUpdateMetersBatch_failure() throws Exception {
    Mockito.when(salMeterService.updateMeter(Mockito.<UpdateMeterInput>any())).thenReturn(RpcResultBuilder.<UpdateMeterOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ur-groupUpdateError").buildFuture());
    final UpdateMetersBatchInput input = new UpdateMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateMeters(Lists.newArrayList(createEmptyBatchUpdateMeter(42L), createEmptyBatchUpdateMeter(44L))).build();
    final Future<RpcResult<UpdateMetersBatchOutput>> resultFuture = salMetersBatchService.updateMetersBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedMetersOutput().size());
    Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(45L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(1).getMeterId().getValue().longValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
    inOrder.verify(salMeterService, Mockito.times(2)).updateMeter(updateMeterInputCpt.capture());
    final List<UpdateMeterInput> allValues = updateMeterInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue());
    Assert.assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue());
    Assert.assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue());
    Assert.assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : UpdateMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder) UpdateMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput) Test(org.junit.Test)

Example 12 with SalMeterService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService in project openflowplugin by opendaylight.

the class SalMetersBatchServiceImplTest method testRemoveMetersBatch_failure.

@Test
public void testRemoveMetersBatch_failure() throws Exception {
    Mockito.when(salMeterService.removeMeter(Mockito.<RemoveMeterInput>any())).thenReturn(RpcResultBuilder.<RemoveMeterOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupRemoveError").buildFuture());
    final RemoveMetersBatchInput input = new RemoveMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchRemoveMeters(Lists.newArrayList(createEmptyBatchRemoveMeter(42L), createEmptyBatchRemoveMeter(43L))).build();
    final Future<RpcResult<RemoveMetersBatchOutput>> resultFuture = salMetersBatchService.removeMetersBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedMetersOutput().size());
    Assert.assertEquals(42L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(1).getMeterId().getValue().longValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
    inOrder.verify(salMeterService, Mockito.times(2)).removeMeter(removeMeterInputCpt.capture());
    final List<RemoveMeterInput> allValues = removeMeterInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemoveMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput) RemoveMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInputBuilder) RemoveMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput) Test(org.junit.Test)

Example 13 with SalMeterService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService in project openflowplugin by opendaylight.

the class SalMetersBatchServiceImplTest method testAddMetersBatch_success.

@Test
public void testAddMetersBatch_success() throws Exception {
    Mockito.when(salMeterService.addMeter(Mockito.<AddMeterInput>any())).thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().build()).buildFuture());
    final AddMetersBatchInput input = new AddMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddMeters(Lists.newArrayList(createEmptyBatchAddMeter(42L), createEmptyBatchAddMeter(43L))).build();
    final Future<RpcResult<AddMetersBatchOutput>> resultFuture = salMetersBatchService.addMetersBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertTrue(resultFuture.get().isSuccessful());
    final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
    inOrder.verify(salMeterService, Mockito.times(2)).addMeter(addMeterInputCpt.capture());
    final List<AddMeterInput> allValues = addMeterInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : InOrder(org.mockito.InOrder) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput) AddMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInputBuilder) AddMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder) Test(org.junit.Test)

Example 14 with SalMeterService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService in project openflowplugin by opendaylight.

the class OpenflowpluginMeterTestServiceProvider method register.

public ObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(final ProviderContext ctx) {
    RoutedRpcRegistration<SalMeterService> addRoutedRpcImplementation = ctx.<SalMeterService>addRoutedRpcImplementation(SalMeterService.class, this);
    setMeterRegistration(addRoutedRpcImplementation);
    InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier.<Nodes>builder(Nodes.class);
    NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
    NodeKey nodeKey = new NodeKey(nodeId);
    InstanceIdentifierBuilder<Node> nodeIndentifier = builder1.<Node, NodeKey>child(Node.class, nodeKey);
    InstanceIdentifier<Node> instance = nodeIndentifier.build();
    meterRegistration.registerPath(NodeContext.class, instance);
    RoutedRpcRegistration<SalMeterService> meterRegistration1 = this.getMeterRegistration();
    return new AbstractObjectRegistration<OpenflowpluginMeterTestServiceProvider>(this) {

        @Override
        protected void removeRegistration() {
            meterRegistration1.close();
        }
    };
}
Also used : AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) SalMeterService(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)

Aggregations

Test (org.junit.Test)12 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 InOrder (org.mockito.InOrder)6 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)6 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)5 MeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder)5 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)4 RemoveMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput)4 UpdateMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)3 MeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey)3 StaleMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter)3 StaleMeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterBuilder)3 StaleMeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterKey)3 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)3 FRMTest (test.mock.util.FRMTest)3 SalMeterServiceMock (test.mock.util.SalMeterServiceMock)3 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)2 AddMeterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder)2