1a854dfc00507660a4a796a151afde437f7d8ee1
[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
27 /**
28  * openflowplugin-impl
29  * org.opendaylight.openflowplugin.impl.device
30  *
31  * test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
32  *
33  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
34  *
35  * Created: Mar 29, 2015
36  */
37 @RunWith(MockitoJUnitRunner.class)
38 public class DeviceStateImplTest {
39
40     private NodeId nodeId;
41     @Mock
42     private FeaturesReply featuresReply;
43     private DeviceStateImpl deviceState;
44
45     private final short version = 13;
46     private final long portNr = 10L;
47     private final Long portBandwidth = 1024L;
48     private final List<PhyPort> pPort = Arrays.asList(new PhyPortBuilder()
49                     .setPortNo(portNr).setMaxSpeed(portBandwidth).build());
50
51     @Before
52     public void initialization() {
53         nodeId = new NodeId("test-node-id");
54         Mockito.when(featuresReply.getVersion()).thenReturn(version);
55         Mockito.when(featuresReply.getPhyPort()).thenReturn(pPort);
56         deviceState = new DeviceStateImpl(featuresReply, nodeId);
57     }
58
59     /**
60      * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
61      */
62     @Test(expected=NullPointerException.class)
63     public void testDeviceStateImplNullNodeId(){
64         new DeviceStateImpl(featuresReply, null);
65     }
66
67     /**
68      * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
69      */
70     @Test(expected=IllegalArgumentException.class)
71     public void testDeviceStateImplNullFeaturesReply(){
72         new DeviceStateImpl(null, nodeId);
73     }
74
75     /**
76      * Test method for {@link DeviceStateImpl#getNodeId()}.
77      */
78     @Test
79     public void testGetNodeId(){
80         final NodeId getNodeId = deviceState.getNodeId();
81         Assert.assertNotNull(getNodeId);
82         Assert.assertEquals(nodeId, getNodeId);
83     }
84
85     /**
86      * Test method for {@link DeviceStateImpl#getFeatures()}.
87      */
88     @Test
89     public void testGetFeatures(){
90         final GetFeaturesOutputBuilder expetedResult = new GetFeaturesOutputBuilder(featuresReply);
91         final GetFeaturesOutput getFeatures = deviceState.getFeatures();
92         Assert.assertNotNull(getFeatures);
93         Assert.assertEquals(expetedResult.getVersion(), getFeatures.getVersion());
94         Assert.assertEquals(expetedResult.getPhyPort(), getFeatures.getPhyPort());
95     }
96
97 }