Use YANG binding from YANG Tools
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / ContextExtractorTest.java
index 5dc08a792ce40ea774c5ff2c9414eb4ecb2a64ac..1a1645ca66a97b8290f2232ea37c676ce02dbd54 100644 (file)
@@ -7,74 +7,63 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 
 import org.junit.Test;
+import org.opendaylight.mdsal.binding.dom.adapter.ContextReferenceExtractor.Direct;
+import org.opendaylight.mdsal.binding.dom.adapter.ContextReferenceExtractor.GetValue;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public final class ContextExtractorTest {
 
-    public interface Transitive extends EncapsulatedRouteInGrouping {
-
-    }
-
-    private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
-    private static final Transitive TEST_GROUPING = new Transitive() {
-
-        @Override
-        @Deprecated
-        public Class<? extends DataContainer> getImplementedInterface() {
-            return Transitive.class;
-        }
-
+    public interface Transitive extends DataObject, EncapsulatedRouteInGrouping {
         @Override
-        public Class<? extends Transitive> implementedInterface() {
+        default Class<Transitive> implementedInterface() {
             return Transitive.class;
         }
+    }
 
-        @Override
-        public EncapsulatedRoute getRoute() {
-            return new EncapsulatedRoute(TEST_ROUTE);
-        }
-    };
+    private static final DataObjectIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class).toIdentifier();
+    private static final Transitive TEST_GROUPING = () -> new EncapsulatedRoute(TEST_ROUTE);
 
     @Test
     public void testNonRoutedExtraction() {
-        final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
-        final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
-        final InstanceIdentifier<?> extractedValue = extractor.extract(input);
-        assertNull(extractedValue);
+        assertNull(ContextReferenceExtractor.of(RockTheHouseInput.class));
     }
 
     @Test
     public void testRoutedSimpleExtraction() {
-        final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
-        final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
-        final InstanceIdentifier<?> extractedValue = extractor.extract(input);
-        assertSame(TEST_ROUTE,extractedValue);
+        final var extractor = ContextReferenceExtractor.of(RoutedSimpleRouteInput.class);
+        assertNotNull(extractor);
+        assertThat(extractor, instanceOf(Direct.class));
+        assertSame(TEST_ROUTE, extractor.extract(new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build()));
     }
 
     @Test
     public void testRoutedEncapsulatedExtraction() {
-        final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
-        final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
-        assertSame(TEST_ROUTE,extractedValue);
-
+        final var extractor = ContextReferenceExtractor.of(EncapsulatedRouteInGrouping.class);
+        assertNotNull(extractor);
+        assertThat(extractor, instanceOf(GetValue.class));
+        assertSame(TEST_ROUTE, extractor.extract(TEST_GROUPING));
     }
 
     @Test
     public void testRoutedEncapsulatedTransitiveExtraction() {
-        final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
-        final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
-        assertSame(TEST_ROUTE,extractedValue);
+        final var extractor = ContextReferenceExtractor.of(Transitive.class);
+        assertNotNull(extractor);
+        assertThat(extractor, instanceOf(GetValue.class));
+        assertSame(TEST_ROUTE, extractor.extract(TEST_GROUPING));
     }
 }