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.TransactionChainListener;
25 import org.opendaylight.mdsal.binding.api.WriteTransaction;
26 import org.opendaylight.mdsal.common.api.CommitInfo;
27 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Test for {@link FlowWriterTxChain}.
36 @RunWith(MockitoJUnitRunner.class)
37 public class FlowWriterTxChainTest {
39 private static final Logger LOG = LoggerFactory.getLogger(FlowWriterTxChainTest.class);
40 private static final int FLOWS_PER_DPN = 100;
43 private DataBroker mockDataBroker;
45 private ExecutorService mockFlowPusher;
47 private WriteTransaction writeTransaction;
49 private FlowWriterTxChain flowWriterTxChain;
52 public void setUp() throws Exception {
54 Mockito.doAnswer(invocation -> {
55 ((Runnable) invocation.getArguments()[0]).run();
57 }).when(mockFlowPusher).execute(ArgumentMatchers.<Runnable>any());
59 final TransactionChain mockedTxChain = mock(TransactionChain.class);
60 when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
61 doReturn(mockedTxChain).when(mockDataBroker)
62 .createTransactionChain(ArgumentMatchers.<TransactionChainListener>any());
64 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
66 flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
70 public void testAddFlows() throws Exception {
71 flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
72 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.<LogicalDatastoreType>any(),
73 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
74 ArgumentMatchers.anyBoolean());
78 public void testDeleteFlows() throws Exception {
79 flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
80 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
81 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
82 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());