Fixed discard-changes for mdsal netconf, mapping code cleanup.
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / test / java / org / opendaylight / controller / sal / compatibility / test / MDFlowMappingTest.java
1 /*
2  * Copyright (c) 2014 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.controller.sal.compatibility.test;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.action.Action;
13 import org.opendaylight.controller.sal.action.PushVlan;
14 import org.opendaylight.controller.sal.compatibility.MDFlowMapping;
15 import org.opendaylight.controller.sal.core.ConstructionException;
16 import org.opendaylight.controller.sal.core.Node;
17 import org.opendaylight.controller.sal.core.Node.NodeIDType;
18 import org.opendaylight.controller.sal.core.NodeConnector;
19 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
20 import org.opendaylight.controller.sal.utils.EtherTypes;
21
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
24
25 /**
26  * test for {@link MDFlowMapping}
27  */
28 public class MDFlowMappingTest {
29
30     /**
31      * Test method for {@link org.opendaylight.controller.sal.compatibility.MDFlowMapping#toUri(org.opendaylight.controller.sal.core.NodeConnector)}.
32      * @throws ConstructionException
33      */
34     @Test
35     public void testToUri() throws ConstructionException {
36         Node node = new Node(NodeIDType.OPENFLOW, 41L);
37         NodeConnector connector = new NodeConnector(NodeConnectorIDType.OPENFLOW, (short) 42, node);
38         Uri observed = MDFlowMapping.toUri(connector );
39
40         Assert.assertEquals("openflow:41:42", observed.getValue());
41     }
42
43     /**
44      * Test method for {@link MDFlowMapping#toAction(Action, int)}.
45      */
46     @Test
47     public void testToAction() {
48         // PUSH_VLAN test.
49         EtherTypes[] tags = {EtherTypes.VLANTAGGED, EtherTypes.QINQ};
50         int order = 0;
51         for (EtherTypes tag: tags) {
52             Action action = new PushVlan(tag);
53             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
54                 rev131112.action.list.Action mdActionList =
55                 MDFlowMapping.toAction(action, order);
56             Assert.assertEquals(order, mdActionList.getOrder().intValue());
57
58             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
59                 rev131112.action.Action mdAction = mdActionList.getAction();
60             Assert.assertTrue(mdAction instanceof PushVlanActionCase);
61             PushVlanActionCase pushVlan = (PushVlanActionCase)mdAction;
62             Assert.assertEquals(tag.intValue(),
63                                 pushVlan.getPushVlanAction().getEthernetType().
64                                 intValue());
65             order++;
66         }
67     }
68 }