BUG-956 deadlock by rpc invocation - phase2
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / SwitchFeaturesUtilTest.java
1 /**
2  * Copyright (c) 2013 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 package org.opendaylight.openflowplugin.openflow.md.core.sal;
9
10
11 import org.junit.After;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
18
19 /**
20  * Tests for setting switch features for different version of OF plugin
21  * 
22  * @author jsebin
23  *
24  */
25 public class SwitchFeaturesUtilTest {
26
27     private GetFeaturesOutputBuilder featuresOutputBuilder;    
28     private SwitchFeaturesUtil swUtil; 
29     
30     
31     /**
32      * initialization of {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder GetFeaturesOutputBuilder}
33      * and {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil SwitchFeaturesUtil}
34      * @throws Exception
35      */
36     @Before
37     public void setUp() throws Exception {
38         featuresOutputBuilder = new GetFeaturesOutputBuilder();
39         swUtil = SwitchFeaturesUtil.getInstance();
40     }
41
42     /**
43      * @throws Exception
44      */
45     @After
46     public void tearDown() throws Exception {
47         featuresOutputBuilder = null;
48         swUtil = null;
49     }
50
51     /**
52      * Test method for
53      * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for OF 1.0 version 
54      * and switch feature capabilities
55      * .
56      */
57     @Test
58     public void testSwFeaturesCapabilitiesV10() {        
59         CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, false);
60         featuresOutputBuilder.setCapabilitiesV10(capabilities).setVersion((short) 1);
61         
62         Assert.assertNotNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
63     }
64     
65     /**
66      * Test method for
67      * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for OF 1.3 version 
68      * and switch feature capabilities
69      * .
70      */
71     @Test
72     public void testSwFeaturesCapabilitiesV13() {
73         Capabilities capabilities = new Capabilities(true, false, true, false, true, false, true);
74         featuresOutputBuilder.setCapabilities(capabilities).setCapabilitiesV10(null).setVersion((short) 4);
75         
76         Assert.assertNotNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
77     }
78     
79     /**
80      * Test method for
81      * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for malformed switch feature capabilities
82      * - at least one feature is null
83      * .
84      */    
85     //@Test TODO:do we need to check if capability is null?
86     public void testSwFeaturesCapabilitiesMalformed() {
87         CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, null);
88         featuresOutputBuilder.setCapabilitiesV10(capabilities).setCapabilities(null).setVersion((short) 1);
89         
90         Assert.assertNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
91     }
92     
93     /**
94      * Test method for
95      * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for mismatch between
96      * version and switch feature capabilities
97      * .
98      */
99     @Test
100     public void testSwFeaturesCapabilitiesVersionMismatch() {
101         CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, false);
102         featuresOutputBuilder.setCapabilitiesV10(capabilities).setCapabilities(null).setVersion((short) 4);
103         
104         Assert.assertNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
105     }
106     
107     /**
108      * Test method for
109      * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for nonexisting version
110      * .
111      */
112     @Test
113     public void testSwFeaturesCapabilitiesNonexistingVersion() {
114         CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, false);
115         featuresOutputBuilder.setCapabilitiesV10(capabilities).setCapabilities(null).setVersion((short) 0);
116         
117         Assert.assertNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
118     }
119 }