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;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Test for {@link FlowWriterTxChain}.
34 @RunWith(MockitoJUnitRunner.class)
35 public class FlowWriterTxChainTest {
37 private static final Logger LOG = LoggerFactory.getLogger(FlowWriterTxChainTest.class);
38 private static final int FLOWS_PER_DPN = 100;
41 private DataBroker mockDataBroker;
43 private ExecutorService mockFlowPusher;
45 private WriteTransaction writeTransaction;
47 private FlowWriterTxChain flowWriterTxChain;
50 public void setUp() throws Exception {
52 Mockito.doAnswer(invocation -> {
53 ((Runnable) invocation.getArguments()[0]).run();
55 }).when(mockFlowPusher).execute(ArgumentMatchers.any());
57 final TransactionChain mockedTxChain = mock(TransactionChain.class);
58 when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
59 doReturn(mockedTxChain).when(mockDataBroker)
60 .createTransactionChain(ArgumentMatchers.any());
62 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
64 flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
68 public void testAddFlows() throws Exception {
69 flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
70 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.any(),
71 ArgumentMatchers.any(), ArgumentMatchers.any(),
72 ArgumentMatchers.anyBoolean());
76 public void testDeleteFlows() throws Exception {
77 flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
78 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
79 .delete(ArgumentMatchers.any(),
80 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());