2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.dom.adapter;
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;
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;
27 public final class ContextExtractorTest {
29 public interface Transitive extends EncapsulatedRouteInGrouping {
33 private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
34 private static final Transitive TEST_GROUPING = new Transitive() {
36 public Class<? extends Transitive> implementedInterface() {
37 return Transitive.class;
41 public EncapsulatedRoute getRoute() {
42 return new EncapsulatedRoute(TEST_ROUTE);
47 public void testNonRoutedExtraction() {
48 assertNull(ContextReferenceExtractor.of(RockTheHouseInput.class));
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()));
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));
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));