Merge "Bug 2895: Fix for FRM ClassNotFoundException"
[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.Ignore;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
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#DeviceStateImpl(FeaturesReply, NodeId)}.
78      */
79     @Test(expected=IllegalArgumentException.class)
80     @Ignore // Available for OF1.0 only
81     public void testDeviceStateImplNullPhyPort(){
82         final FeaturesReply emptyFeaturesReply = Mockito.mock(FeaturesReply.class);
83         Mockito.when(emptyFeaturesReply.getPhyPort()).thenReturn(null);
84         new DeviceStateImpl(emptyFeaturesReply, nodeId);
85     }
86
87     /**
88      * Test method for {@link DeviceStateImpl#getNodeId()}.
89      */
90     @Test
91     public void testGetNodeId(){
92         final NodeId getNodeId = deviceState.getNodeId();
93         Assert.assertNotNull(getNodeId);
94         Assert.assertEquals(nodeId, getNodeId);
95     }
96
97     /**
98      * Test method for {@link DeviceStateImpl#getFeatures()}.
99      */
100     @Test
101     public void testGetFeatures(){
102         final GetFeaturesOutputBuilder expetedResult = new GetFeaturesOutputBuilder(featuresReply);
103         final GetFeaturesOutput getFeatures = deviceState.getFeatures();
104         Assert.assertNotNull(getFeatures);
105         Assert.assertEquals(expetedResult.getVersion(), getFeatures.getVersion());
106         Assert.assertEquals(expetedResult.getPhyPort(), getFeatures.getPhyPort());
107     }
108
109 }