Post "Clustering optimization" updates
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / device / DeviceStateImplTest.java
1 /**
2  * Copyright (c) 2015 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.impl.device;
10
11 import java.util.Arrays;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
27
28 /**
29  * openflowplugin-impl
30  * org.opendaylight.openflowplugin.impl.device
31  *
32  * test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
33  *
34  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
35  *
36  * Created: Mar 29, 2015
37  */
38 @RunWith(MockitoJUnitRunner.class)
39 public class DeviceStateImplTest {
40
41     private NodeId nodeId;
42     @Mock
43     private FeaturesReply featuresReply;
44     private DeviceStateImpl deviceState;
45
46     private final short version = 13;
47     private final long portNr = 10L;
48     private final Long portBandwidth = 1024L;
49     private final List<PhyPort> pPort = Arrays.asList(new PhyPortBuilder()
50                     .setPortNo(portNr).setMaxSpeed(portBandwidth).build());
51
52     @Before
53     public void initialization() {
54         nodeId = new NodeId("test-node-id");
55         Mockito.when(featuresReply.getVersion()).thenReturn(version);
56         Mockito.when(featuresReply.getPhyPort()).thenReturn(pPort);
57         deviceState = new DeviceStateImpl(featuresReply, nodeId);
58     }
59
60     /**
61      * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
62      */
63     @Test(expected=NullPointerException.class)
64     public void testDeviceStateImplNullNodeId(){
65         new DeviceStateImpl(featuresReply, null);
66     }
67
68     /**
69      * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
70      */
71     @Test(expected=IllegalArgumentException.class)
72     public void testDeviceStateImplNullFeaturesReply(){
73         new DeviceStateImpl(null, nodeId);
74     }
75
76     /**
77      * Test method for {@link DeviceStateImpl#getNodeId()}.
78      */
79     @Test
80     public void testGetNodeId(){
81         final NodeId getNodeId = deviceState.getNodeId();
82         Assert.assertNotNull(getNodeId);
83         Assert.assertEquals(nodeId, getNodeId);
84     }
85
86     /**
87      * Test method for {@link DeviceStateImpl#getFeatures()}.
88      */
89     @Test
90     public void testGetFeatures(){
91         final GetFeaturesOutputBuilder expetedResult = new GetFeaturesOutputBuilder(featuresReply);
92         final GetFeaturesOutput getFeatures = deviceState.getFeatures();
93         Assert.assertNotNull(getFeatures);
94         Assert.assertEquals(expetedResult.getVersion(), getFeatures.getVersion());
95         Assert.assertEquals(expetedResult.getPhyPort(), getFeatures.getPhyPort());
96     }
97
98     @Test
99     public void testIsValid_initialValue(){
100         Assert.assertFalse(deviceState.isValid());
101     }
102
103     @Test
104     public void testDeviceSynchronized_initialValue(){
105         Assert.assertFalse(deviceState.deviceSynchronized());
106     }
107
108     @Test
109     public void testStatPollEnabled_initialValue(){
110         Assert.assertFalse(deviceState.isStatisticsPollingEnabled());
111     }
112
113     @Test
114     public void testRole_initialValue(){
115         Assert.assertFalse(deviceState.getRole().equals(OfpRole.BECOMEMASTER));
116         Assert.assertFalse(deviceState.getRole().equals(OfpRole.NOCHANGE));
117     }
118
119     @Test
120     public void testStatistics_initialValue(){
121         Assert.assertFalse(deviceState.isFlowStatisticsAvailable());
122         Assert.assertFalse(deviceState.isPortStatisticsAvailable());
123         Assert.assertFalse(deviceState.isQueueStatisticsAvailable());
124         Assert.assertFalse(deviceState.isTableStatisticsAvailable());
125     }
126
127     @Test
128     public void testMeterAndGroupAvailable_initialValue(){
129         Assert.assertFalse(deviceState.isGroupAvailable());
130         Assert.assertFalse(deviceState.isMetersAvailable());
131     }
132
133 }