OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[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.ArgumentMatchers.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.rev150225.action.container.action.choice.ExperimenterIdCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice.experimenter.id._case.ExperimenterBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.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)))
48             .thenReturn((ConvertorActionFromOFJava<DataContainer, AugmentationPath>) (input, path) -> new MockAction());
49     }
50
51     @Test
52     public void testProcessAlienAction() {
53         ActionBuilder actionBuilder = new ActionBuilder();
54
55
56         ExperimenterIdCaseBuilder experimenterIdCaseBuilder = new ExperimenterIdCaseBuilder();
57         ExperimenterBuilder experimenterBuilder = new ExperimenterBuilder();
58         experimenterBuilder.setExperimenter(new ExperimenterId(42L));
59         experimenterIdCaseBuilder.setExperimenter(experimenterBuilder.build());
60         actionBuilder.setActionChoice(experimenterIdCaseBuilder.build());
61         Action action = ActionExtensionHelper.processAlienAction(actionBuilder.build(), OpenflowVersion.OF13,
62                 ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
63         assertNotNull(action);
64         assertEquals(MockAction.class, action.getImplementedInterface());
65     }
66
67
68     private class MockAction implements Action {
69
70         @Override
71         public Class<? extends DataContainer> getImplementedInterface() {
72             return MockAction.class;
73         }
74     }
75
76 }