1a1645ca66a97b8290f2232ea37c676ce02dbd54
[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.binding.DataObject;
26 import org.opendaylight.yangtools.binding.DataObjectIdentifier;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 public final class ContextExtractorTest {
30
31     public interface Transitive extends DataObject, EncapsulatedRouteInGrouping {
32         @Override
33         default Class<Transitive> implementedInterface() {
34             return Transitive.class;
35         }
36     }
37
38     private static final DataObjectIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class).toIdentifier();
39     private static final Transitive TEST_GROUPING = () -> new EncapsulatedRoute(TEST_ROUTE);
40
41     @Test
42     public void testNonRoutedExtraction() {
43         assertNull(ContextReferenceExtractor.of(RockTheHouseInput.class));
44     }
45
46     @Test
47     public void testRoutedSimpleExtraction() {
48         final var extractor = ContextReferenceExtractor.of(RoutedSimpleRouteInput.class);
49         assertNotNull(extractor);
50         assertThat(extractor, instanceOf(Direct.class));
51         assertSame(TEST_ROUTE, extractor.extract(new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build()));
52     }
53
54     @Test
55     public void testRoutedEncapsulatedExtraction() {
56         final var extractor = ContextReferenceExtractor.of(EncapsulatedRouteInGrouping.class);
57         assertNotNull(extractor);
58         assertThat(extractor, instanceOf(GetValue.class));
59         assertSame(TEST_ROUTE, extractor.extract(TEST_GROUPING));
60     }
61
62     @Test
63     public void testRoutedEncapsulatedTransitiveExtraction() {
64         final var extractor = ContextReferenceExtractor.of(Transitive.class);
65         assertNotNull(extractor);
66         assertThat(extractor, instanceOf(GetValue.class));
67         assertSame(TEST_ROUTE, extractor.extract(TEST_GROUPING));
68     }
69 }