Switch to MD-SAL APIs
[openflowplugin.git] / applications / bulk-o-matic / src / test / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / FlowReaderTest.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.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.when;
13
14 import java.util.Optional;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.ReadTransaction;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
25 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
26
27 /**
28  * Test for {@link FlowReader}.
29  */
30 @RunWith(MockitoJUnitRunner.class)
31 public class FlowReaderTest {
32
33     @Mock
34     private DataBroker mockDataBroker;
35     @Mock
36     private ReadTransaction readOnlyTransaction;
37     @Mock
38     private Node node;
39
40     private FlowReader flowReader;
41
42     @Before
43     public void setUp() throws Exception {
44         doReturn(FluentFutures.immediateFluentFuture(Optional.of(node))).when(readOnlyTransaction)
45             .read(any(LogicalDatastoreType.class), any());
46         when(mockDataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
47         flowReader = FlowReader.getNewInstance(mockDataBroker, 2, 5, true, false, (short) 1, (short) 2);
48     }
49
50     @Test
51     public void testRun() throws Exception {
52         flowReader.run();
53         Assert.assertEquals(10, flowReader.getFlowCount());
54         Assert.assertEquals(FlowCounter.OperationStatus.SUCCESS.status(), flowReader.getReadOpStatus());
55     }
56 }