Merge "BUG 2280 - mac address mask translation."
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / extension / ActionExtensionHelperTest.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
9 package org.opendaylight.openflowplugin.openflow.md.core.extension;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.mockito.Matchers.any;
14 import static org.mockito.Mockito.when;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
22 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
23 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
24 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
25 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
26 import org.opendaylight.openflowplugin.extension.api.path.AugmentationPath;
27 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdActionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
33 import org.opendaylight.yangtools.yang.binding.DataContainer;
34
35 /**
36  * Created by Martin Bobak mbobak@cisco.com on 9/17/14.
37  */
38 @RunWith(MockitoJUnitRunner.class)
39 public class ActionExtensionHelperTest {
40
41     @Mock
42     private ExtensionConverterProvider extensionConverterProvider;
43
44     @Before
45     public void setup(){
46         OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterProvider);
47         when(extensionConverterProvider.getActionConverter(any(MessageTypeKey.class))).thenReturn(new ConvertorActionFromOFJava<DataContainer, AugmentationPath>() {
48             @Override
49             public Action convert(DataContainer input, AugmentationPath path) {
50                 return new MockAction();
51             }
52         });
53     }
54     @Test
55     /**
56      * Trivial test for {@link ActionExtensionHelper#processAlienAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action, org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion, org.opendaylight.openflowplugin.extension.api.path.ActionPath)}
57      */
58     public void testProcessAlienAction() {
59         ActionBuilder actionBuilder = new ActionBuilder();
60         ExperimenterIdActionBuilder experimenterIdActionBuilder = new ExperimenterIdActionBuilder();
61         ExperimenterId experimenterId = new ExperimenterId(new Long(42));
62         experimenterIdActionBuilder.setExperimenter(experimenterId);
63
64         experimenterIdActionBuilder.setSubType(MockExperimenterActionSubtype.class);
65
66         actionBuilder.addAugmentation(ExperimenterIdAction.class, experimenterIdActionBuilder.build());
67         Action action = ActionExtensionHelper.processAlienAction(actionBuilder.build(), OpenflowVersion.OF13, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION);
68         assertNotNull(action);
69         assertEquals(MockAction.class, action.getImplementedInterface());
70     }
71
72
73
74
75     private class MockExperimenterActionSubtype extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.ExperimenterActionSubType {
76
77     }
78
79     private class MockAction implements Action {
80
81         @Override
82         public Class<? extends DataContainer> getImplementedInterface() {
83             return MockAction.class;
84         }
85     }
86
87 }