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
9 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.when;
15 import com.google.common.util.concurrent.Futures;
16 import java.util.concurrent.ExecutorService;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.ArgumentMatchers;
21 import org.mockito.Mock;
22 import org.mockito.Mockito;
23 import org.mockito.runners.MockitoJUnitRunner;
24 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
27 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
28 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * Test for {@link FlowWriterTxChain}.
37 @RunWith(MockitoJUnitRunner.class)
38 public class FlowWriterTxChainTest {
40 private static final Logger LOG = LoggerFactory.getLogger(FlowWriterTxChainTest.class);
41 private static final int FLOWS_PER_DPN = 100;
44 private DataBroker mockDataBroker;
46 private ExecutorService mockFlowPusher;
48 private WriteTransaction writeTransaction;
50 private FlowWriterTxChain flowWriterTxChain;
53 public void setUp() throws Exception {
55 Mockito.doAnswer(invocation -> {
56 ((Runnable) invocation.getArguments()[0]).run();
58 }).when(mockFlowPusher).execute(ArgumentMatchers.<Runnable>any());
60 final BindingTransactionChain mockedTxChain = mock(BindingTransactionChain.class);
61 when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
62 doReturn(mockedTxChain).when(mockDataBroker)
63 .createTransactionChain(ArgumentMatchers.<TransactionChainListener>any());
65 when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
67 flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
71 public void testAddFlows() throws Exception {
72 flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
73 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.<LogicalDatastoreType>any(),
74 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
75 ArgumentMatchers.anyBoolean());
79 public void testDeleteFlows() throws Exception {
80 flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
81 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
82 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
83 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());