2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.openflow.md.core.extension;
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;
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;
36 * Created by Martin Bobak mbobak@cisco.com on 9/17/14.
38 @RunWith(MockitoJUnitRunner.class)
39 public class ActionExtensionHelperTest {
42 private ExtensionConverterProvider extensionConverterProvider;
46 OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterProvider);
47 when(extensionConverterProvider.getActionConverter(any(MessageTypeKey.class))).thenReturn(new ConvertorActionFromOFJava<DataContainer, AugmentationPath>() {
49 public Action convert(DataContainer input, AugmentationPath path) {
50 return new MockAction();
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)}
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);
64 experimenterIdActionBuilder.setSubType(MockExperimenterActionSubtype.class);
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());
75 private class MockExperimenterActionSubtype extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.ExperimenterActionSubType {
79 private class MockAction implements Action {
82 public Class<? extends DataContainer> getImplementedInterface() {
83 return MockAction.class;