Migrate Optional.get() callers
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / BindingNormalizedCodecTest.java
index 8e223880e2405d3a59badfeef33bb2d20bc36229..7383c4d037e572bcd6f53d45212bf249eede5e59 100644 (file)
@@ -14,14 +14,12 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.SetMultimap;
 import java.lang.reflect.Method;
-import java.net.URI;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.stream.Collectors;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractSchemaAwareTest;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.MockAdapterContext;
+import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext;
+import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyAugment;
@@ -31,13 +29,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.te
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.util.AbstractSchemaContext;
+import org.opendaylight.yangtools.yang.model.spi.AbstractSchemaContext;
 
 public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
 
@@ -53,40 +52,33 @@ public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
     private static final YangInstanceIdentifier BI_TOP_LEVEL_LIST = YangInstanceIdentifier.builder().node(Top.QNAME)
         .node(TopLevelList.QNAME).nodeWithKey(TopLevelList.QNAME, NAME_QNAME, TOP_FOO_KEY.getName()).build();
 
-    private MockAdapterContext codec;
-    private EffectiveModelContext context;
+    private CurrentAdapterSerializer serializer;
 
     @Override
-    protected void setupWithSchema(final EffectiveModelContext schemaContext) {
-        this.context = schemaContext;
-        this.codec = new MockAdapterContext();
+    protected void setupWithRuntimeContext(final BindingRuntimeContext runtimeContext) {
+        serializer = new CurrentAdapterSerializer(new BindingCodecContext(runtimeContext));
     }
 
     @Test
     public void testComplexAugmentationSerialization() {
-        codec.onModelContextUpdated(context);
-        final PathArgument lastArg = codec.currentSerializer().toYangInstanceIdentifier(BA_TREE_COMPLEX_USES)
-                .getLastPathArgument();
+        final PathArgument lastArg = serializer.toYangInstanceIdentifier(BA_TREE_COMPLEX_USES).getLastPathArgument();
         assertTrue(lastArg instanceof AugmentationIdentifier);
     }
 
     @Test
     public void testLeafOnlyAugmentationSerialization() {
-        codec.onModelContextUpdated(context);
-        final PathArgument leafOnlyLastArg = codec.currentSerializer().toYangInstanceIdentifier(BA_TREE_LEAF_ONLY)
+        final PathArgument leafOnlyLastArg = serializer.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY)
             .getLastPathArgument();
         assertTrue(leafOnlyLastArg instanceof AugmentationIdentifier);
         assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
     }
 
     @Test
-    public void testGetRpcMethodToSchemaPath() {
-        codec.onModelContextUpdated(context);
-        final List<String> retMap = codec.currentSerializer()
-                .getRpcMethodToSchemaPath(OpendaylightTestRpcServiceService.class).keySet().stream()
-                .map(Method::getName)
-                .collect(Collectors.toList());
-        assertTrue(retMap.contains("rockTheHouse"));
+    public void testGetRpcMethodToQName() {
+        assertTrue(serializer.createQNameToMethod(OpendaylightTestRpcServiceService.class)
+            .values().stream()
+            .map(Method::getName)
+            .anyMatch("rockTheHouse"::equals));
     }
 
     static class EmptyEffectiveModelContext extends AbstractSchemaContext implements EffectiveModelContext {
@@ -101,7 +93,7 @@ public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
         }
 
         @Override
-        protected SetMultimap<URI, Module> getNamespaceToModules() {
+        protected SetMultimap<XMLNamespace, Module> getNamespaceToModules() {
             return ImmutableSetMultimap.of();
         }