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