8fa73e936586375e89de58146aa7e237cf8b3470
[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 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.Matchers;
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 FlowWriterSequentialTest {
35
36     private static final Logger LOG = LoggerFactory.getLogger(FlowWriterSequentialTest.class);
37     private static final int FLOWS_PER_DPN = 100;
38
39     @Mock
40     private DataBroker mockDataBroker;
41     @Mock
42     private ExecutorService mockFlowPusher;
43     @Mock
44     private WriteTransaction writeTransaction;
45
46     private FlowWriterSequential flowWriterSequential;
47
48     @Before
49     public void setUp() throws Exception {
50
51         doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
52         Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
53
54         Mockito.doAnswer(invocation -> {
55             ((Runnable) invocation.getArguments()[0]).run();
56             return null;
57         }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
58
59         flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
60     }
61
62     @Test
63     public void testAddFlows() throws Exception {
64         flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short) 0, (short) 1, true);
65         Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(),
66                 Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
67     }
68
69     @Test
70     public void testDeleteFlows() throws Exception {
71         flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
72         Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(),
73                 Matchers.<InstanceIdentifier<DataObject>>any());
74     }
75 }