4ddc9157807baf2c31ff3267600eb41ef43afbae
[openflowplugin.git] / extension / openflowplugin-extension-api / src / test / java / org / opendaylight / openflowplugin / extension / api / GroupingResolverTest.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.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.flow.types.rev131026.flow.Match;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
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.GeneralAugMatchNodesNodeTableFlow;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchRpcAddFlow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
22 import org.opendaylight.yangtools.yang.binding.Augmentable;
23
24 /**
25  *  Test of {@link GroupingResolver}.
26  */
27 public class GroupingResolverTest {
28
29     /**
30      * test of method {@link GroupingResolver#getExtension(Augmentable)}.
31      */
32     @Test
33     public void testGetExtension() {
34         GroupingResolver<GeneralExtensionListGrouping, Match> eqGroup =
35                 new GroupingResolver<>(GeneralExtensionListGrouping.class);
36         eqGroup.add(GeneralAugMatchNodesNodeTableFlow.class);
37         eqGroup.add(GeneralAugMatchRpcAddFlow.class);
38
39         MatchBuilder mb1 = new MatchBuilder();
40         ExtensionList extension1 = new ExtensionListBuilder().setExtensionKey(JoachimTheBig.class).build();
41         GeneralAugMatchNodesNodeTableFlow odlxxx1 = new GeneralAugMatchNodesNodeTableFlowBuilder()
42                 .setExtensionList(Collections.singletonList(extension1)).build();
43         Match match1 = mb1.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, odlxxx1).build();
44
45         MatchBuilder mb2 = new MatchBuilder();
46         ExtensionList extension2 = new ExtensionListBuilder().setExtensionKey(JoachimTheTiny.class).build();
47         GeneralAugMatchNodesNodeTableFlow odlxxx2 = new GeneralAugMatchNodesNodeTableFlowBuilder()
48                 .setExtensionList(Collections.singletonList(extension2)).build();
49         Match match2 = mb2.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, odlxxx2).build();
50
51         Assert.assertEquals(JoachimTheBig.class,
52                 eqGroup.getExtension(match1).get().getExtensionList().get(0).getExtensionKey());
53         Assert.assertEquals(JoachimTheTiny.class,
54                 eqGroup.getExtension(match2).get().getExtensionList().get(0).getExtensionKey());
55     }
56
57     private interface JoachimTheBig extends ExtensionKey {
58         // nobody
59     }
60
61     private interface JoachimTheTiny extends ExtensionKey {
62         // nobody
63     }
64 }