* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
public class FlowDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest {
- static final Short TABLE_NO = 1;
- private FlowDirectStatisticsService service;
+ static final Uint8 TABLE_NO = Uint8.ONE;
+ private MultiGetFlowStatistics service;
@Override
- public void setUp() throws Exception {
- service = new FlowDirectStatisticsService(requestContextStack,
+ public void setUp() {
+ service = new MultiGetFlowStatistics(requestContextStack,
deviceContext,
convertorManager,
multipartWriterProvider);
}
@Override
- public void testBuildRequestBody() throws Exception {
+ public void testBuildRequestBody() {
final GetFlowStatisticsInput input = mock(GetFlowStatisticsInput.class);
- when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
when(input.getTableId()).thenReturn(TABLE_NO);
final MultipartRequestFlowCase body = (MultipartRequestFlowCase) ((MultipartRequestInput) service
- .buildRequest(new Xid(42L), input))
+ .buildRequest(new Xid(Uint32.valueOf(42L)), input))
.getMultipartRequestBody();
final MultipartRequestFlow flow = body.getMultipartRequestFlow();
}
@Override
- public void testBuildReply() throws Exception {
+ public void testBuildReply() {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyFlowCase flowCase = mock(MultipartReplyFlowCase.class);
final MultipartReplyFlow flow = mock(MultipartReplyFlow.class);
final FlowStats flowStat = new FlowStatsBuilder()
- .setDurationSec(1L)
- .setDurationNsec(1L)
+ .setDurationSec(Uint32.ONE)
+ .setDurationNsec(Uint32.ONE)
.setTableId(TABLE_NO)
- .setByteCount(BigInteger.ONE)
- .setPacketCount(BigInteger.ONE)
+ .setByteCount(Uint64.ONE)
+ .setPacketCount(Uint64.ONE)
.setFlags(mock(FlowModFlags.class))
.setMatch(new org.opendaylight.yang.gen.v1.urn
.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder()
- .setMatchEntry(Collections.emptyList())
+ .setMatchEntry(List.of())
.build())
.build();
- final List<FlowStats> flowStats = Collections.singletonList(flowStat);
- final List<MultipartReply> input = Collections.singletonList(reply);
+ final List<FlowStats> flowStats = List.of(flowStat);
+ final List<MultipartReply> input = List.of(reply);
when(flow.getFlowStats()).thenReturn(flowStats);
when(flowCase.getMultipartReplyFlow()).thenReturn(flow);
when(reply.getMultipartReplyBody()).thenReturn(flowCase);
final GetFlowStatisticsOutput output = service.buildReply(input, true);
- assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
+ assertTrue(output.nonnullFlowAndStatisticsMapList().size() > 0);
- final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
+ final FlowAndStatisticsMap stats = output.nonnullFlowAndStatisticsMapList().iterator().next();
assertEquals(stats.getTableId(), TABLE_NO);
}
@Override
- public void testStoreStatistics() throws Exception {
+ public void testStoreStatistics() {
final FlowAndStatisticsMapList stat = mock(FlowAndStatisticsMapList.class);
when(stat.getTableId()).thenReturn(TABLE_NO);
when(stat.getMatch()).thenReturn(new MatchBuilder().build());
- final List<FlowAndStatisticsMapList> stats = Collections.singletonList(stat);
+ final List<FlowAndStatisticsMapList> stats = List.of(stat);
final GetFlowStatisticsOutput output = mock(GetFlowStatisticsOutput.class);
- when(output.getFlowAndStatisticsMapList()).thenReturn(stats);
+ when(output.nonnullFlowAndStatisticsMapList()).thenReturn(stats);
- multipartWriterProvider.lookup(MultipartType.OFPMPFLOW).get().write(output, true);
+ multipartWriterProvider.lookup(MultipartType.OFPMPFLOW).orElseThrow().write(output, true);
verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
}
}