Rework OpenFlowPluginProviderImpl connection provider tracking
[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 package org.opendaylight.openflowplugin.openflow.md.core.extension;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.when;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
21 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
22 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
23 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
24 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.experimenter.id.action.ExperimenterIdCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.experimenter.id.action.experimenter.id._case.ExperimenterBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
30 import org.opendaylight.yangtools.yang.binding.DataContainer;
31 import org.opendaylight.yangtools.yang.common.Uint32;
32
33 /**
34  * Created by Martin Bobak mbobak@cisco.com on 9/17/14.
35  */
36 @RunWith(MockitoJUnitRunner.class)
37 public class ActionExtensionHelperTest {
38
39     @Mock
40     private ExtensionConverterProvider extensionConverterProvider;
41
42     @Before
43     public void setup() {
44         OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterProvider);
45         when(extensionConverterProvider.getActionConverter(any(MessageTypeKey.class)))
46             .thenReturn((input, path) -> new MockAction());
47     }
48
49     @Test
50     public void testProcessAlienAction() {
51         ActionBuilder actionBuilder = new ActionBuilder();
52
53
54         ExperimenterIdCaseBuilder experimenterIdCaseBuilder = new ExperimenterIdCaseBuilder();
55         ExperimenterBuilder experimenterBuilder = new ExperimenterBuilder();
56         experimenterBuilder.setExperimenter(new ExperimenterId(Uint32.valueOf(42)));
57         experimenterIdCaseBuilder.setExperimenter(experimenterBuilder.build());
58         actionBuilder.setActionChoice(experimenterIdCaseBuilder.build());
59         Action action = ActionExtensionHelper.processAlienAction(actionBuilder.build(), OpenflowVersion.OF13,
60                 ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
61         assertNotNull(action);
62         assertEquals(MockAction.class, action.implementedInterface());
63     }
64
65     private static final class MockAction implements Action {
66
67         @Override
68         public Class<? extends DataContainer> implementedInterface() {
69             return MockAction.class;
70         }
71     }
72 }