Bug 2351 Speed-up Binding-to-Binding routed RPC Invocation.
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / 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.controller.md.sal.binding.impl;
9
10 import static org.junit.Assert.assertNull;
11 import static org.junit.Assert.assertSame;
12
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;
23
24 public final class ContextExtractorTest {
25
26     public interface Transitive extends EncapsulatedRouteInGrouping {
27
28     }
29
30     private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
31     private static final Transitive TEST_GROUPING = new Transitive() {
32
33         @Override
34         public Class<? extends DataContainer> getImplementedInterface() {
35             return Transitive.class;
36         }
37
38         @Override
39         public EncapsulatedRoute getRoute() {
40             return new EncapsulatedRoute(TEST_ROUTE);
41         }
42     };
43
44     @Test
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);
50     }
51
52     @Test
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);
58     }
59
60     @Test
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);
65
66     }
67
68     @Test
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);
73     }
74  }