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.controller.md.sal.binding.impl;
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.list.rev140701.Top;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
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() {
33 public Class<? extends Transitive> implementedInterface() {
34 return Transitive.class;
38 public EncapsulatedRoute getRoute() {
39 return new EncapsulatedRoute(TEST_ROUTE);
44 public void testNonRoutedExtraction() {
45 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
46 final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
47 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
48 assertNull(extractedValue);
52 public void testRoutedSimpleExtraction() {
53 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
54 final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
55 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
56 assertSame(TEST_ROUTE,extractedValue);
60 public void testRoutedEncapsulatedExtraction() {
61 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
62 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
63 assertSame(TEST_ROUTE,extractedValue);
68 public void testRoutedEncapsulatedTransitiveExtraction() {
69 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
70 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
71 assertSame(TEST_ROUTE,extractedValue);