Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 1 | package org.projectfloodlight.protocol; |
| 2 | |
| 3 | import java.util.Arrays; |
| 4 | import java.util.HashSet; |
| 5 | |
| 6 | import org.junit.Test; |
| 7 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 8 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 9 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
| 10 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 11 | import org.projectfloodlight.openflow.protocol.OFPortState; |
| 12 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 13 | |
| 14 | import static org.hamcrest.Matchers.is; |
| 15 | |
| 16 | import static org.junit.Assert.assertThat; |
| 17 | |
Sovietaced | d1196ab | 2014-12-02 06:45:42 -0500 | [diff] [blame] | 18 | /** |
| 19 | * Tests auxiliary OFPortDesc methods for all versions of OpenFlow |
| 20 | * |
kjwon15 | 7bc8540 | 2015-02-12 15:07:42 +0900 | [diff] [blame] | 21 | * @author Jason Parraga {@literal <}jason.parraga@bigswitch.com{@literal >} |
Sovietaced | d1196ab | 2014-12-02 06:45:42 -0500 | [diff] [blame] | 22 | */ |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 23 | public class OFPortDescTest { |
| 24 | |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 25 | @Test |
| 26 | public void testIsEnabled() { |
Sovietaced | d1196ab | 2014-12-02 06:45:42 -0500 | [diff] [blame] | 27 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_10)); |
| 28 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_11)); |
| 29 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_12)); |
| 30 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_13)); |
| 31 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_14)); |
| 32 | } |
| 33 | |
| 34 | public void testIsEnabledForFactory(OFFactory factory) { |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 35 | // Default |
| 36 | OFPortDesc desc = factory.buildPortDesc() |
| 37 | .build(); |
| 38 | assertThat(desc.isEnabled(), is(true)); |
| 39 | |
| 40 | // Partially disabled |
| 41 | desc = factory.buildPortDesc() |
| 42 | .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN))) |
| 43 | .build(); |
| 44 | assertThat(desc.isEnabled(), is(false)); |
| 45 | |
| 46 | // Fully disabled |
| 47 | desc = factory.buildPortDesc() |
| 48 | .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN))) |
| 49 | .setState(new HashSet<OFPortState>(Arrays.asList(OFPortState.LINK_DOWN))) |
| 50 | .build(); |
| 51 | assertThat(desc.isEnabled(), is(false)); |
| 52 | } |
| 53 | } |