2 * Copyright (c) 2016, 2017 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
8 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
14 import java.util.concurrent.ExecutorService;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.ArgumentMatchers;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.TransactionChain;
24 import org.opendaylight.mdsal.binding.api.WriteTransaction;
25 import org.opendaylight.mdsal.common.api.CommitInfo;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 * Test for {@link FlowWriterTxChain}.
32 @RunWith(MockitoJUnitRunner.class)
33 public class FlowWriterTxChainTest {
35 private static final int FLOWS_PER_DPN = 100;
38 private DataBroker mockDataBroker;
40 private ExecutorService mockFlowPusher;
42 private WriteTransaction writeTransaction;
44 private FlowWriterTxChain flowWriterTxChain;
49 Mockito.doAnswer(invocation -> {
50 ((Runnable) invocation.getArguments()[0]).run();
52 }).when(mockFlowPusher).execute(ArgumentMatchers.any());
54 final TransactionChain mockedTxChain = mock(TransactionChain.class);
55 when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
56 doReturn(mockedTxChain).when(mockDataBroker)
57 .createMergingTransactionChain(ArgumentMatchers.any());
59 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
61 flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
65 public void testAddFlows() {
66 flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
67 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.any(),
68 ArgumentMatchers.any(), ArgumentMatchers.any(),
69 ArgumentMatchers.anyBoolean());
73 public void testDeleteFlows() {
74 flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
75 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
76 .delete(ArgumentMatchers.any(),
77 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());