58fb21ad25aa71ce7e780472ec8e21397b31410c
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / DeviceStateUtilTest.java
1 /*
2  *
3  *  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
4  *  *
5  *  * This program and the accompanying materials are made available under the
6  *  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  *
10  */
11
12 package org.opendaylight.openflowplugin.impl.util;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.mockito.Mockito.verify;
16
17 import org.junit.After;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
32
33
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class DeviceStateUtilTest {
37
38     @Mock
39     private DeviceState mockedDeviceState;
40
41     @After
42     public void tearDown() {
43         Mockito.verifyNoMoreInteractions(mockedDeviceState);
44     }
45
46     @Test
47     public void setDeviceStateBasedOnV13CapabilitiesTest() {
48         final Capabilities dummyCapabilities =  new Capabilities(false,false,false,false,false,false,false);
49
50         DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(mockedDeviceState, dummyCapabilities);
51
52         verify(mockedDeviceState).setFlowStatisticsAvailable(false);
53         verify(mockedDeviceState).setTableStatisticsAvailable(false);
54         verify(mockedDeviceState).setPortStatisticsAvailable(false);
55         verify(mockedDeviceState).setQueueStatisticsAvailable(false);
56         verify(mockedDeviceState).setGroupAvailable(false);
57     }
58
59     @Test
60     public void setDeviceStateBasedOnV10CapabilitiesTest() {
61         CapabilitiesV10 dummyCapabilitiesV10 = new CapabilitiesV10(false, false, false, false, false, false, false, false);
62
63         DeviceStateUtil.setDeviceStateBasedOnV10Capabilities(mockedDeviceState, dummyCapabilitiesV10);
64         verify(mockedDeviceState).setFlowStatisticsAvailable(false);
65         verify(mockedDeviceState).setTableStatisticsAvailable(false);
66         verify(mockedDeviceState).setPortStatisticsAvailable(false);
67         verify(mockedDeviceState).setQueueStatisticsAvailable(false);
68     }
69
70     @Test
71     public void createNodeInstanceIdentifierTest() {
72         final NodeId nodeId = new NodeId("dummyId");
73         final KeyedInstanceIdentifier<Node, NodeKey> expectedII = InstanceIdentifier.create(Nodes.class).child(Node
74                 .class, new NodeKey(nodeId));
75
76         final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil
77                 .createNodeInstanceIdentifier(nodeId);
78         assertEquals(expectedII, nodeInstanceIdentifier);
79     }
80 }