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.binding.DataObject;
26 import org.opendaylight.yangtools.binding.DataObjectIdentifier;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 public final class ContextExtractorTest {
31 public interface Transitive extends DataObject, EncapsulatedRouteInGrouping {
33 default Class<Transitive> implementedInterface() {
34 return Transitive.class;
38 private static final DataObjectIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class).toIdentifier();
39 private static final Transitive TEST_GROUPING = () -> new EncapsulatedRoute(TEST_ROUTE);
42 public void testNonRoutedExtraction() {
43 assertNull(ContextReferenceExtractor.of(RockTheHouseInput.class));
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()));
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));
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));