Moved binding MD-SAL APIs to binding folder
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / ContextExtractorTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.adapter;
9
10 import static org.junit.Assert.assertNull;
11 import static org.junit.Assert.assertSame;
12
13 import org.opendaylight.mdsal.binding.dom.adapter.ContextReferenceExtractor;
14
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;
25
26 public final class ContextExtractorTest {
27
28     public interface Transitive extends EncapsulatedRouteInGrouping {
29
30     }
31
32     private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
33     private static final Transitive TEST_GROUPING = new Transitive() {
34
35         @Override
36         public Class<? extends DataContainer> getImplementedInterface() {
37             return Transitive.class;
38         }
39
40         @Override
41         public EncapsulatedRoute getRoute() {
42             return new EncapsulatedRoute(TEST_ROUTE);
43         }
44     };
45
46     @Test
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);
52     }
53
54     @Test
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);
60     }
61
62     @Test
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);
67
68     }
69
70     @Test
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);
75     }
76  }