Remove redundant type specifiers
[openflowplugin.git] / applications / bulk-o-matic / src / test / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / FlowWriterTxChainTest.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 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
9
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
13
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.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.TransactionChain;
24 import org.opendaylight.mdsal.binding.api.WriteTransaction;
25 import org.opendaylight.mdsal.common.api.CommitInfo;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * Test for {@link FlowWriterTxChain}.
33  */
34 @RunWith(MockitoJUnitRunner.class)
35 public class FlowWriterTxChainTest {
36
37     private static final Logger LOG = LoggerFactory.getLogger(FlowWriterTxChainTest.class);
38     private static final int FLOWS_PER_DPN = 100;
39
40     @Mock
41     private DataBroker mockDataBroker;
42     @Mock
43     private ExecutorService mockFlowPusher;
44     @Mock
45     private WriteTransaction writeTransaction;
46
47     private FlowWriterTxChain flowWriterTxChain;
48
49     @Before
50     public void setUp() throws Exception {
51
52         Mockito.doAnswer(invocation -> {
53             ((Runnable) invocation.getArguments()[0]).run();
54             return null;
55         }).when(mockFlowPusher).execute(ArgumentMatchers.any());
56
57         final TransactionChain mockedTxChain = mock(TransactionChain.class);
58         when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
59         doReturn(mockedTxChain).when(mockDataBroker)
60                 .createTransactionChain(ArgumentMatchers.any());
61
62         doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
63
64         flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
65     }
66
67     @Test
68     public void testAddFlows() throws Exception {
69         flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
70         Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.any(),
71                 ArgumentMatchers.any(), ArgumentMatchers.any(),
72                 ArgumentMatchers.anyBoolean());
73     }
74
75     @Test
76     public void testDeleteFlows() throws Exception {
77         flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
78         Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
79                 .delete(ArgumentMatchers.any(),
80                         ArgumentMatchers.<InstanceIdentifier<DataObject>>any());
81     }
82 }