2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.statistics.services;
11 import com.google.common.util.concurrent.FutureCallback;
12 import java.util.concurrent.Future;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.mockito.ArgumentCaptor;
16 import org.mockito.Captor;
17 import org.mockito.Matchers;
18 import org.mockito.Mockito;
19 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
21 import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
31 * Test for {@link OpendaylightFlowTableStatisticsServiceImpl}
33 public class OpendaylightFlowTableStatisticsServiceImplTest extends AbstractStatsServiceTest {
36 private ArgumentCaptor<MultipartRequestInput> requestInput;
38 private RequestContext<Object> rqContext;
40 private OpendaylightFlowTableStatisticsServiceImpl flowTableStatisticsService;
43 flowTableStatisticsService = new OpendaylightFlowTableStatisticsServiceImpl(rqContextStack, deviceContext);
45 rqContext = new AbstractRequestContext<Object>(42L) {
51 Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
55 public void testGetFlowTablesStatistics() throws Exception {
56 Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
57 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
59 GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder()
60 .setNode(createNodeRef("unitProt:123"));
62 final Future<RpcResult<GetFlowTablesStatisticsOutput>> resultFuture
63 = flowTableStatisticsService.getFlowTablesStatistics(input.build());
65 Assert.assertTrue(resultFuture.isDone());
66 final RpcResult<GetFlowTablesStatisticsOutput> rpcResult = resultFuture.get();
67 Assert.assertTrue(rpcResult.isSuccessful());
68 Assert.assertEquals(MultipartType.OFPMPTABLE, requestInput.getValue().getType());
72 public void testBuildRequest() throws Exception {
73 Xid xid = new Xid(42L);
74 GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder()
75 .setNode(createNodeRef("unitProt:123"));
76 final OfHeader request = flowTableStatisticsService.buildRequest(xid, input.build());
77 Assert.assertTrue(request instanceof MultipartRequestInput);
78 final MultipartRequestInput mpRequest = (MultipartRequestInput) request;
79 Assert.assertEquals(MultipartType.OFPMPTABLE, mpRequest.getType());
80 Assert.assertTrue(mpRequest.getMultipartRequestBody() instanceof MultipartRequestTableCase);
81 final MultipartRequestTableCase mpRequestBody = (MultipartRequestTableCase) (mpRequest.getMultipartRequestBody());
82 Assert.assertTrue(mpRequestBody.getMultipartRequestTable().isEmpty());