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.DataContainer;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 public final class ContextExtractorTest {
26 public interface Transitive extends EncapsulatedRouteInGrouping {
30 private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
31 private static final Transitive TEST_GROUPING = new Transitive() {
34 public Class<? extends DataContainer> getImplementedInterface() {
35 return Transitive.class;
39 public EncapsulatedRoute getRoute() {
40 return new EncapsulatedRoute(TEST_ROUTE);
45 public void testNonRoutedExtraction() {
46 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
47 final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
48 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
49 assertNull(extractedValue);
53 public void testRoutedSimpleExtraction() {
54 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
55 final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
56 final InstanceIdentifier<?> extractedValue = extractor.extract(input);
57 assertSame(TEST_ROUTE,extractedValue);
61 public void testRoutedEncapsulatedExtraction() {
62 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
63 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
64 assertSame(TEST_ROUTE,extractedValue);
69 public void testRoutedEncapsulatedTransitiveExtraction() {
70 final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
71 final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
72 assertSame(TEST_ROUTE,extractedValue);