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.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 public final class ContextExtractorTest {
25 public interface Transitive extends EncapsulatedRouteInGrouping {
29 private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
30 private static final Transitive TEST_GROUPING = new Transitive() {
32 public Class<? extends Transitive> implementedInterface() {
33 return Transitive.class;
37 public EncapsulatedRoute getRoute() {
38 return new EncapsulatedRoute(TEST_ROUTE);
43 public void testNonRoutedExtraction() {
44 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
45 final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
46 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
47 assertNull(extractedValue);
51 public void testRoutedSimpleExtraction() {
52 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
53 final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
54 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
55 assertSame(TEST_ROUTE,extractedValue);
59 public void testRoutedEncapsulatedExtraction() {
60 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
61 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
62 assertSame(TEST_ROUTE,extractedValue);
67 public void testRoutedEncapsulatedTransitiveExtraction() {
68 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
69 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
70 assertSame(TEST_ROUTE,extractedValue);