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;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
30 * org.opendaylight.openflowplugin.impl.device
32 * test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
34 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
36 * Created: Mar 29, 2015
38 @RunWith(MockitoJUnitRunner.class)
39 public class DeviceStateImplTest {
41 private NodeId nodeId;
43 private FeaturesReply featuresReply;
44 private DeviceStateImpl deviceState;
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());
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);
61 * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
63 @Test(expected=NullPointerException.class)
64 public void testDeviceStateImplNullNodeId(){
65 new DeviceStateImpl(featuresReply, null);
69 * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
71 @Test(expected=IllegalArgumentException.class)
72 public void testDeviceStateImplNullFeaturesReply(){
73 new DeviceStateImpl(null, nodeId);
77 * Test method for {@link DeviceStateImpl#getNodeId()}.
80 public void testGetNodeId(){
81 final NodeId getNodeId = deviceState.getNodeId();
82 Assert.assertNotNull(getNodeId);
83 Assert.assertEquals(nodeId, getNodeId);
87 * Test method for {@link DeviceStateImpl#getFeatures()}.
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());
99 public void testIsValid_initialValue(){
100 Assert.assertFalse(deviceState.isValid());
104 public void testDeviceSynchronized_initialValue(){
105 Assert.assertFalse(deviceState.deviceSynchronized());
109 public void testStatPollEnabled_initialValue(){
110 Assert.assertFalse(deviceState.isStatisticsPollingEnabled());
114 public void testStatistics_initialValue(){
115 Assert.assertFalse(deviceState.isFlowStatisticsAvailable());
116 Assert.assertFalse(deviceState.isPortStatisticsAvailable());
117 Assert.assertFalse(deviceState.isQueueStatisticsAvailable());
118 Assert.assertFalse(deviceState.isTableStatisticsAvailable());
122 public void testMeterAndGroupAvailable_initialValue(){
123 Assert.assertFalse(deviceState.isGroupAvailable());
124 Assert.assertFalse(deviceState.isMetersAvailable());