2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.device;
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;
29 * org.opendaylight.openflowplugin.impl.device
31 * test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
33 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
35 * Created: Mar 29, 2015
37 @RunWith(MockitoJUnitRunner.class)
38 public class DeviceStateImplTest {
40 private NodeId nodeId;
42 private FeaturesReply featuresReply;
43 private DeviceStateImpl deviceState;
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());
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);
60 * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
62 @Test(expected=NullPointerException.class)
63 public void testDeviceStateImplNullNodeId(){
64 new DeviceStateImpl(featuresReply, null);
68 * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
70 @Test(expected=IllegalArgumentException.class)
71 public void testDeviceStateImplNullFeaturesReply(){
72 new DeviceStateImpl(null, nodeId);
76 * Test method for {@link DeviceStateImpl#getNodeId()}.
79 public void testGetNodeId(){
80 final NodeId getNodeId = deviceState.getNodeId();
81 Assert.assertNotNull(getNodeId);
82 Assert.assertEquals(nodeId, getNodeId);
86 * Test method for {@link DeviceStateImpl#getFeatures()}.
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());