Correct ActionProviderService method definition
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / ContextExtractorTest.java
1 /*
2  * Copyright (c) 2015 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.mdsal.binding.dom.adapter;
9
10 import static org.junit.Assert.assertNull;
11 import static org.junit.Assert.assertSame;
12
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 public final class ContextExtractorTest {
24
25     public interface Transitive extends EncapsulatedRouteInGrouping {
26
27     }
28
29     private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
30     private static final Transitive TEST_GROUPING = new Transitive() {
31         @Override
32         public Class<? extends Transitive> implementedInterface() {
33             return Transitive.class;
34         }
35
36         @Override
37         public EncapsulatedRoute getRoute() {
38             return new EncapsulatedRoute(TEST_ROUTE);
39         }
40     };
41
42     @Test
43     public void testNonRoutedExtraction() {
44         final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
45         final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
46         final InstanceIdentifier<?> extractedValue = extractor.extract(input);
47         assertNull(extractedValue);
48     }
49
50     @Test
51     public void testRoutedSimpleExtraction() {
52         final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
53         final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
54         final InstanceIdentifier<?> extractedValue = extractor.extract(input);
55         assertSame(TEST_ROUTE,extractedValue);
56     }
57
58     @Test
59     public void testRoutedEncapsulatedExtraction() {
60         final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
61         final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
62         assertSame(TEST_ROUTE,extractedValue);
63
64     }
65
66     @Test
67     public void testRoutedEncapsulatedTransitiveExtraction() {
68         final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
69         final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
70         assertSame(TEST_ROUTE,extractedValue);
71     }
72 }