Switch to MD-SAL APIs
[openflowplugin.git] / applications / bulk-o-matic / src / test / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / FlowWriterSequentialTest.java
1 /*
2  * Copyright (c) 2016, 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 java.util.concurrent.ExecutorService;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.ArgumentMatchers;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.WriteTransaction;
23 import org.opendaylight.mdsal.common.api.CommitInfo;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 /**
29  * Test for {@link FlowWriterSequential}.
30  */
31 @RunWith(MockitoJUnitRunner.class)
32 public class FlowWriterSequentialTest {
33     private static final int FLOWS_PER_DPN = 100;
34
35     @Mock
36     private DataBroker mockDataBroker;
37     @Mock
38     private ExecutorService mockFlowPusher;
39     @Mock
40     private WriteTransaction writeTransaction;
41
42     private FlowWriterSequential flowWriterSequential;
43
44     @Before
45     public void setUp() throws Exception {
46
47         doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
48         doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
49
50         Mockito.doAnswer(invocation -> {
51             ((Runnable) invocation.getArguments()[0]).run();
52             return null;
53         }).when(mockFlowPusher).execute(ArgumentMatchers.<Runnable>any());
54
55         flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
56     }
57
58     @Test
59     public void testAddFlows() throws Exception {
60         flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short) 0, (short) 1, true);
61         Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.<LogicalDatastoreType>any(),
62                 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
63                 ArgumentMatchers.anyBoolean());
64     }
65
66     @Test
67     public void testDeleteFlows() throws Exception {
68         flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
69         Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
70                 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
71                         ArgumentMatchers.<InstanceIdentifier<DataObject>>any());
72     }
73 }