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.junit.Assert.assertNull;
11 import static org.junit.Assert.assertSame;
13 import org.opendaylight.mdsal.binding.dom.adapter.ContextReferenceExtractor;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
23 import org.opendaylight.yangtools.yang.binding.DataContainer;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 public final class ContextExtractorTest {
28 public interface Transitive extends EncapsulatedRouteInGrouping {
32 private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
33 private static final Transitive TEST_GROUPING = new Transitive() {
36 public Class<? extends DataContainer> getImplementedInterface() {
37 return Transitive.class;
41 public EncapsulatedRoute getRoute() {
42 return new EncapsulatedRoute(TEST_ROUTE);
47 public void testNonRoutedExtraction() {
48 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
49 final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
50 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
51 assertNull(extractedValue);
55 public void testRoutedSimpleExtraction() {
56 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
57 final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
58 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
59 assertSame(TEST_ROUTE,extractedValue);
63 public void testRoutedEncapsulatedExtraction() {
64 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
65 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
66 assertSame(TEST_ROUTE,extractedValue);
71 public void testRoutedEncapsulatedTransitiveExtraction() {
72 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
73 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
74 assertSame(TEST_ROUTE,extractedValue);