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.Matchers;
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(Matchers.<Runnable>any());
60 final BindingTransactionChain mockedTxChain = mock(BindingTransactionChain.class);
61 when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
62 doReturn(mockedTxChain).when(mockDataBroker).createTransactionChain(Matchers.<TransactionChainListener>any());
64 when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
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(Matchers.<LogicalDatastoreType>any(),
73 Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
77 public void testDeleteFlows() throws Exception {
78 flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
79 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(),
80 Matchers.<InstanceIdentifier<DataObject>>any());