Fix Bug 271
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchReactorTest.java
1 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
2
3 import java.math.BigInteger;
4
5 import junit.framework.Assert;
6
7 import org.junit.Before;
8 import org.junit.Test;
9 import org.opendaylight.openflowplugin.openflow.md.OFConstants;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
18
19 /**
20  * match conversion and injection test 
21  */
22 public class MatchReactorTest {
23
24     private MatchBuilder matchBuilder;
25     
26     /**
27      * prepare input match
28      */
29     @Before
30     public void setUp() {
31         matchBuilder = new MatchBuilder();
32         EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
33         EthernetTypeBuilder ethernetTypeBuilder = new EthernetTypeBuilder();
34         ethernetTypeBuilder.setType(new EtherType(42L));
35         ethernetMatchBuilder.setEthernetType(ethernetTypeBuilder.build());
36         matchBuilder.setEthernetMatch(ethernetMatchBuilder.build());
37     }
38
39     /**
40      * convert for OF-1.3, inject into {@link FlowModInputBuilder}
41      */
42     @Test
43     public void testMatchConvertorV13_flow() {
44         FlowModInputBuilder target = new FlowModInputBuilder();
45         MatchReactor.getInstance().convert(matchBuilder.build(), 
46                 OFConstants.OFP_VERSION_1_3, target,BigInteger.valueOf(1));
47         Assert.assertNotNull(target.getMatch());
48     }
49     
50     /**
51      * convert for OF-1.0, inject into {@link FlowModInputBuilder}
52      */
53     @Test
54     public void testMatchConvertorV10_flow() {
55         FlowModInputBuilder target = new FlowModInputBuilder();
56         MatchReactor.getInstance().convert(matchBuilder.build(), 
57                 OFConstants.OFP_VERSION_1_0, target,BigInteger.valueOf(1));
58         Assert.assertNotNull(target.getMatchV10());
59     }
60
61     /**
62      * convert for OF-1.3, inject into {@link OxmFieldsActionBuilder}
63      */
64     @Test
65     public void testMatchConvertorV13_action() {
66         OxmFieldsActionBuilder target = new OxmFieldsActionBuilder();
67         MatchReactor.getInstance().convert(matchBuilder.build(), 
68                 OFConstants.OFP_VERSION_1_3, target,BigInteger.valueOf(1));
69         Assert.assertNotNull(target.getMatchEntries());
70     }
71     
72     /**
73      * convert for OF-1.3, inject into {@link MultipartRequestFlowBuilder}
74      */
75     @Test
76     public void testMatchConvertorV13_mpRequestFlow() {
77         MultipartRequestFlowBuilder target = new MultipartRequestFlowBuilder();
78         MatchReactor.getInstance().convert(matchBuilder.build(), 
79                 OFConstants.OFP_VERSION_1_3, target,BigInteger.valueOf(1));
80         Assert.assertNotNull(target.getMatch());
81     }
82     
83     /**
84      * convert for OF-1.0, inject into {@link MultipartRequestFlowBuilder}
85      */
86     @Test
87     public void testMatchConvertorV10_mpRequestFlow() {
88         MultipartRequestFlowBuilder target = new MultipartRequestFlowBuilder();
89         MatchReactor.getInstance().convert(matchBuilder.build(), 
90                 OFConstants.OFP_VERSION_1_0, target,BigInteger.valueOf(1));
91         Assert.assertNotNull(target.getMatchV10());
92     }
93     
94     /**
95      * convert for OF-1.3, inject into {@link MultipartRequestAggregateBuilder}
96      */
97     @Test
98     public void testMatchConvertorV13_mpRequestAggregate() {
99         MultipartRequestAggregateBuilder target = new MultipartRequestAggregateBuilder();
100         MatchReactor.getInstance().convert(matchBuilder.build(), 
101                 OFConstants.OFP_VERSION_1_3, target,BigInteger.valueOf(1));
102         Assert.assertNotNull(target.getMatch());
103     }
104     
105     /**
106      * convert for OF-1.0, inject into {@link MultipartRequestAggregateBuilder}
107      */
108     @Test
109     public void testMatchConvertorV10_mpRequestAggregate() {
110         MultipartRequestAggregateBuilder target = new MultipartRequestAggregateBuilder();
111         MatchReactor.getInstance().convert(matchBuilder.build(), 
112                 OFConstants.OFP_VERSION_1_0, target,BigInteger.valueOf(1));
113         Assert.assertNotNull(target.getMatchV10());
114     }
115     
116     
117     
118 }