Merge "Bug 8535: Fix IPv6 OXMHeader Mask issue"
[openflowplugin.git] / applications / bulk-o-matic / src / test / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / FlowWriterSequentialTest.java
1 /**
2  * Copyright (c) 2016 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.invocation.InvocationOnMock;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.mockito.stubbing.Answer;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * Test for {@link FlowWriterSequential}.
34  */
35 @RunWith(MockitoJUnitRunner.class)
36 public class FlowWriterSequentialTest {
37
38     private static final Logger LOG = LoggerFactory.getLogger(FlowWriterSequentialTest.class);
39     private static final int FLOWS_PER_DPN = 100;
40
41     @Mock
42     private DataBroker mockDataBroker;
43     @Mock
44     private ExecutorService mockFlowPusher;
45     @Mock
46     private WriteTransaction wTx;
47
48     private FlowWriterSequential flowWriterSequential;
49
50     @Before
51     public void setUp() throws Exception {
52
53         doReturn(wTx).when(mockDataBroker).newWriteOnlyTransaction();
54         Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
55
56         Mockito.doAnswer(new Answer<Void>() {
57             @Override
58             public Void answer(InvocationOnMock invocation) throws Throwable {
59                 ((Runnable)invocation.getArguments()[0]).run();
60                 return null;
61             }
62         }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
63
64         flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
65     }
66     @Test
67     public void testAddFlows() throws Exception {
68         flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short)0, (short)1, true);
69         Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
70     }
71
72     @Test
73     public void testDeleteFlows() throws Exception {
74         flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short)0, (short)1);
75         Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any());
76     }
77
78 }