2 * Copyright (c) 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;
12 import java.util.concurrent.ExecutorService;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentMatchers;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.mdsal.binding.api.DataBroker;
21 import org.opendaylight.mdsal.binding.api.WriteTransaction;
22 import org.opendaylight.mdsal.common.api.CommitInfo;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 * Test for {@link FlowWriterSequential}.
29 @RunWith(MockitoJUnitRunner.class)
30 public class TableWriterTest {
31 private static final int TABLES_PER_DPN = 100;
32 private static final int DPN_COUNT = 1;
33 private static final short START_TABLE_ID = 0;
34 private static final short END_TABLE_ID = 99;
37 private DataBroker mockDataBroker;
39 private ExecutorService mockTablePusher;
41 private WriteTransaction writeTransaction;
43 private TableWriter tableWriter;
48 doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
49 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
51 Mockito.doAnswer(invocation -> {
52 ((Runnable) invocation.getArguments()[0]).run();
54 }).when(mockTablePusher).execute(ArgumentMatchers.any());
56 tableWriter = new TableWriter(mockDataBroker, mockTablePusher);
60 public void testAddTables() {
61 tableWriter.addTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
62 Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN))
63 .put(ArgumentMatchers.any(),
64 ArgumentMatchers.any(), ArgumentMatchers.any(),
65 ArgumentMatchers.anyBoolean());
69 public void testDeleteTables() {
70 tableWriter.deleteTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
71 Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN))
72 .delete(ArgumentMatchers.any(),
73 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());