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