9eb5b6a7e649ebae29db88ff05e8b19cc931dffd
[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         ExtensionList extension1 = new ExtensionListBuilder().setExtensionKey(ZVendorExt1.VALUE).build();
33         SetField setField1 = new SetFieldBuilder()
34                 .addAugmentation(new GeneralAugMatchRpcAddFlowWriteActionsSetFieldBuilder()
35                     .setExtensionList(Collections.singletonMap(extension1.key(), extension1))
36                     .build())
37                 .build();
38
39         ExtensionList extension2 = new ExtensionListBuilder().setExtensionKey(ZVendorExt2.VALUE).build();
40         SetField setField2 = new SetFieldBuilder()
41                 .addAugmentation(new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
42                     .setExtensionList(Collections.singletonMap(extension2.key(), extension2))
43                     .build())
44                 .build();
45
46         Assert.assertEquals(ZVendorExt1.VALUE,
47                 eqGroup.getExtension(setField1).get().nonnullExtensionList().values().iterator().next()
48                         .getExtensionKey());
49         Assert.assertEquals(ZVendorExt2.VALUE,
50                 eqGroup.getExtension(setField2).get().nonnullExtensionList().values().iterator().next()
51                         .getExtensionKey());
52     }
53
54     private interface ZVendorExt1 extends ExtensionKey {
55         ZVendorExt1 VALUE = () -> ZVendorExt1.class;
56     }
57
58     private interface ZVendorExt2 extends ExtensionKey {
59         ZVendorExt2 VALUE = () -> ZVendorExt2.class;
60     }
61 }