f47fd103e0363bddf1e5d36b17a484635fcad10b
[openflowplugin.git] / extension / openflowplugin-extension-api / src / test / java / org / opendaylight / openflowplugin / extension / api / SetFieldExtensionTest.java
1 /*
2  * Copyright (c) 2017 ZTE Corporation.  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.extension.api;
9
10 import java.util.Collections;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetField;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchRpcAddFlowWriteActionsSetField;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchRpcAddFlowWriteActionsSetFieldBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
23
24 public class SetFieldExtensionTest {
25     @Test
26     public void testGetExtension() {
27         GroupingLooseResolver<GeneralExtensionListGrouping> eqGroup =
28                 new GroupingLooseResolver<>(GeneralExtensionListGrouping.class);
29         eqGroup.add(GeneralAugMatchRpcAddFlowWriteActionsSetField.class);
30         eqGroup.add(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class);
31
32         SetFieldBuilder sb1 = new SetFieldBuilder();
33         ExtensionList extension1 = new ExtensionListBuilder().setExtensionKey(ZVendorExt1.class).build();
34         GeneralAugMatchRpcAddFlowWriteActionsSetField odlxxx1 =
35                 new GeneralAugMatchRpcAddFlowWriteActionsSetFieldBuilder()
36                     .setExtensionList(Collections.singletonList(extension1)).build();
37         SetField setField1 = sb1.addAugmentation(GeneralAugMatchRpcAddFlowWriteActionsSetField.class, odlxxx1).build();
38
39         SetFieldBuilder sb2 = new SetFieldBuilder();
40         ExtensionList extension2 = new ExtensionListBuilder().setExtensionKey(ZVendorExt2.class).build();
41         GeneralAugMatchNodesNodeTableFlowWriteActionsSetField odlxxx2 =
42                 new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
43                     .setExtensionList(Collections.singletonList(extension2)).build();
44         SetField setField2 = sb2.addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
45                 odlxxx2).build();
46
47         Assert.assertEquals(ZVendorExt1.class,
48                 eqGroup.getExtension(setField1).get().getExtensionList().get(0).getExtensionKey());
49         Assert.assertEquals(ZVendorExt2.class,
50                 eqGroup.getExtension(setField2).get().getExtensionList().get(0).getExtensionKey());
51     }
52
53     private interface ZVendorExt1 extends ExtensionKey {
54         // nobody
55     }
56
57     private interface ZVendorExt2 extends ExtensionKey {
58         // nobody
59     }
60 }