/* * Copyright (c) 2017 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.adapter; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map.Entry; import org.junit.Test; import org.opendaylight.mdsal.binding.dom.adapter.test.util.TestingModuleInfoSnapshot; import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext; import org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator; import org.opendaylight.mdsal.binding.runtime.api.DefaultBindingRuntimeContext; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class CurrentAdapterSerializerTest { /** * Positive test. * *
* Test for yang with leaf of type int in container where data are created
* with int value (acceptable data).
*
* @throws Exception
* - throw exception
*/
@Test
public void fromNormalizedNodeTest() throws Exception {
final EffectiveModelContext schemaCtx = YangParserTestUtils.parseYangResource("/test.yang");
final NormalizedNode, ?> data = prepareData(schemaCtx, Uint16.valueOf(42));
final Entry
* Test for yang with leaf of type int in container where data are created
* with String value (non acceptable data - should failed with
* {@link IllegalArgumentException})
*
* @throws Exception
* - throw exception
*/
@Test
public void fromNormalizedNodeWithAnotherInputDataTest() throws Exception {
final EffectiveModelContext schemaCtx = YangParserTestUtils.parseYangResource("/test.yang");
final NormalizedNode, ?> data = prepareData(schemaCtx, "42");
final Entry