Bump mdsal to 4.0.0
[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.InstanceIdentifier;
22
23 public final class ContextExtractorTest {
24
25     public interface Transitive extends EncapsulatedRouteInGrouping {
26
27     }
28
29     private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
30     private static final Transitive TEST_GROUPING = new Transitive() {
31
32         @Override
33         public Class<? extends Transitive> implementedInterface() {
34             return Transitive.class;
35         }
36
37         @Override
38         public EncapsulatedRoute getRoute() {
39             return new EncapsulatedRoute(TEST_ROUTE);
40         }
41     };
42
43     @Test
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);
49     }
50
51     @Test
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);
57     }
58
59     @Test
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);
64
65     }
66
67     @Test
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);
72     }
73 }