Migrate users of deprecated yang.common methods
[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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertSame;
15
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.dom.adapter.ContextReferenceExtractor.Direct;
18 import org.opendaylight.mdsal.binding.dom.adapter.ContextReferenceExtractor.GetValue;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 public final class ContextExtractorTest {
28
29     public interface Transitive extends EncapsulatedRouteInGrouping {
30
31     }
32
33     private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
34     private static final Transitive TEST_GROUPING = new Transitive() {
35         @Override
36         public Class<? extends Transitive> implementedInterface() {
37             return Transitive.class;
38         }
39
40         @Override
41         public EncapsulatedRoute getRoute() {
42             return new EncapsulatedRoute(TEST_ROUTE);
43         }
44     };
45
46     @Test
47     public void testNonRoutedExtraction() {
48         assertNull(ContextReferenceExtractor.of(RockTheHouseInput.class));
49     }
50
51     @Test
52     public void testRoutedSimpleExtraction() {
53         final var extractor = ContextReferenceExtractor.of(RoutedSimpleRouteInput.class);
54         assertNotNull(extractor);
55         assertThat(extractor, instanceOf(Direct.class));
56         assertSame(TEST_ROUTE, extractor.extract(new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build()));
57     }
58
59     @Test
60     public void testRoutedEncapsulatedExtraction() {
61         final var extractor = ContextReferenceExtractor.of(EncapsulatedRouteInGrouping.class);
62         assertNotNull(extractor);
63         assertThat(extractor, instanceOf(GetValue.class));
64         assertSame(TEST_ROUTE, extractor.extract(TEST_GROUPING));
65     }
66
67     @Test
68     public void testRoutedEncapsulatedTransitiveExtraction() {
69         final var extractor = ContextReferenceExtractor.of(Transitive.class);
70         assertNotNull(extractor);
71         assertThat(extractor, instanceOf(GetValue.class));
72         assertSame(TEST_ROUTE, extractor.extract(TEST_GROUPING));
73     }
74 }