/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.openflowplugin.impl.device;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
/**
* openflowplugin-impl
* org.opendaylight.openflowplugin.impl.device
*
* test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
*
* @author Vaclav Demcak
*
* Created: Mar 29, 2015
*/
@RunWith(MockitoJUnitRunner.class)
public class DeviceStateImplTest {
private NodeId nodeId;
@Mock
private FeaturesReply featuresReply;
private DeviceStateImpl deviceState;
private final short version = 13;
private final long portNr = 10L;
private final Long portBandwidth = 1024L;
private final List pPort = Arrays.asList(new PhyPortBuilder()
.setPortNo(portNr).setMaxSpeed(portBandwidth).build());
@Before
public void initialization() {
nodeId = new NodeId("test-node-id");
Mockito.when(featuresReply.getVersion()).thenReturn(version);
Mockito.when(featuresReply.getPhyPort()).thenReturn(pPort);
deviceState = new DeviceStateImpl(featuresReply, nodeId);
}
/**
* Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
*/
@Test(expected=NullPointerException.class)
public void testDeviceStateImplNullNodeId(){
new DeviceStateImpl(featuresReply, null);
}
/**
* Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
*/
@Test(expected=IllegalArgumentException.class)
public void testDeviceStateImplNullFeaturesReply(){
new DeviceStateImpl(null, nodeId);
}
/**
* Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
*/
@Test(expected=IllegalArgumentException.class)
@Ignore // Available for OF1.0 only
public void testDeviceStateImplNullPhyPort(){
final FeaturesReply emptyFeaturesReply = Mockito.mock(FeaturesReply.class);
Mockito.when(emptyFeaturesReply.getPhyPort()).thenReturn(null);
new DeviceStateImpl(emptyFeaturesReply, nodeId);
}
/**
* Test method for {@link DeviceStateImpl#getNodeId()}.
*/
@Test
public void testGetNodeId(){
final NodeId getNodeId = deviceState.getNodeId();
Assert.assertNotNull(getNodeId);
Assert.assertEquals(nodeId, getNodeId);
}
/**
* Test method for {@link DeviceStateImpl#getFeatures()}.
*/
@Test
public void testGetFeatures(){
final GetFeaturesOutputBuilder expetedResult = new GetFeaturesOutputBuilder(featuresReply);
final GetFeaturesOutput getFeatures = deviceState.getFeatures();
Assert.assertNotNull(getFeatures);
Assert.assertEquals(expetedResult.getVersion(), getFeatures.getVersion());
Assert.assertEquals(expetedResult.getPhyPort(), getFeatures.getPhyPort());
}
}