OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / applications / bulk-o-matic / src / test / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / TableWriterTest.java
1 /**
2  * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
10
11 import static org.mockito.Mockito.doReturn;
12
13 import com.google.common.util.concurrent.Futures;
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.runners.MockitoJUnitRunner;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * Test for {@link FlowWriterSequential}.
32  */
33 @RunWith(MockitoJUnitRunner.class)
34 public class TableWriterTest {
35     private static final Logger LOG = LoggerFactory.getLogger(TableWriterTest.class);
36
37     private static final int TABLES_PER_DPN = 100;
38     private static final int DPN_COUNT = 1;
39     private static final short START_TABLE_ID = 0;
40     private static final short END_TABLE_ID = 99;
41
42     @Mock
43     private DataBroker mockDataBroker;
44     @Mock
45     private ExecutorService mockTablePusher;
46     @Mock
47     private WriteTransaction writeTransaction;
48
49     private TableWriter tableWriter;
50
51     @Before
52     public void setUp() throws Exception {
53
54         doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
55         Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
56
57         Mockito.doAnswer(invocation -> {
58             ((Runnable) invocation.getArguments()[0]).run();
59             return null;
60         }).when(mockTablePusher).execute(ArgumentMatchers.<Runnable>any());
61
62         tableWriter = new TableWriter(mockDataBroker, mockTablePusher);
63     }
64
65     @Test
66     public void testAddTables() throws Exception {
67         tableWriter.addTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
68         Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN))
69                 .put(ArgumentMatchers.<LogicalDatastoreType>any(),
70                         ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
71                         ArgumentMatchers.anyBoolean());
72     }
73
74     @Test
75     public void testDeleteTables() throws Exception {
76         tableWriter.deleteTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
77         Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN))
78                 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
79                         ArgumentMatchers.<InstanceIdentifier<DataObject>>any());
80     }
81 }