/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.dom.codec.impl; import static java.util.Objects.requireNonNull; import static org.junit.Assert.assertNotNull; import java.util.HashSet; import java.util.Map.Entry; import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.mdsal.binding.dom.codec.api.MissingClassInLoadingStrategyException; import org.opendaylight.mdsal.binding.generator.api.BindingRuntimeContext; import org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator; import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; 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; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyAugmentBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; /** * This sets of tests are designed in way, that schema context contains models for all augmentations, but backing class * loading strategy is not aware of some of the classes, and becames aware of them after codec was used. * *
* The idea of this suite is to test that codecs will work even if situation like this happens.
*/
public class AugmentationClassDiscoveredAfterCodecTest {
private EffectiveModelContext schemaContext;
private BindingRuntimeContext runtimeContext;
private ClassExcludingClassLoadingStrategy mockedContext;
private BindingNormalizedNodeCodecRegistry registry;
@Before
public void setup() {
final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
ctx.addModuleInfos(BindingReflections.loadModuleInfos());
mockedContext = new ClassExcludingClassLoadingStrategy(ctx);
schemaContext = ctx.tryToCreateModelContext().get();
runtimeContext = BindingRuntimeContext.create(
new DefaultBindingRuntimeGenerator().generateTypeMapping(schemaContext), mockedContext);
registry = new BindingNormalizedNodeCodecRegistry(runtimeContext);
}
private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
private static final InstanceIdentifier