From: Robert Varga Date: Fri, 27 Apr 2018 14:59:41 +0000 (+0200) Subject: Add DataSchemaContextTreeTest X-Git-Tag: v2.0.4~6 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=92711383f5272f23183c6d90c4247a9e5590671a;p=yangtools.git Add DataSchemaContextTreeTest DataSchemaContextTree is completely untested, this patch adds some unit tests. Change-Id: I68b3c77080fa1b155ec28ca6ced4d15039437ec8 Signed-off-by: Robert Varga --- diff --git a/yang/yang-data-util/src/test/java/org/opendaylight/yangtools/yang/data/util/codec/DataSchemaContextTreeTest.java b/yang/yang-data-util/src/test/java/org/opendaylight/yangtools/yang/data/util/codec/DataSchemaContextTreeTest.java new file mode 100644 index 0000000000..cca8dcd336 --- /dev/null +++ b/yang/yang-data-util/src/test/java/org/opendaylight/yangtools/yang/data/util/codec/DataSchemaContextTreeTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.yangtools.yang.data.util.codec; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.net.URI; +import java.util.Optional; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; + +public class DataSchemaContextTreeTest { + private static final QNameModule MODULE = QNameModule.create(URI.create("dataschemacontext")); + private static final QName FOO = QName.create(MODULE, "foo"); + private static final QName BAR = QName.create(MODULE, "bar"); + private static final QName BAZ = QName.create(MODULE, "baz"); + private static DataSchemaContextTree CONTEXT; + + @BeforeClass + public static void init() { + CONTEXT = DataSchemaContextTree.from(YangParserTestUtils.parseYangResource("/dataschemacontext.yang")); + } + + @AfterClass + public static void cleanup() { + CONTEXT = null; + } + + @Test + public void testCorrectInput() { + assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO)).isPresent()); + assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR)).isPresent()); + assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ)).isPresent()); + + assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO))); + assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO).node(BAR))); + assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ))); + } + + @Test + public void testSimpleBad() { + assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR))); + assertNull(CONTEXT.getChild(YangInstanceIdentifier.of(BAR))); + } + + @Test + public void testNestedBad() { + assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR).node(BAZ))); + assertNull(CONTEXT.getChild(YangInstanceIdentifier.of(BAR).node(BAZ))); + } +} diff --git a/yang/yang-data-util/src/test/resources/dataschemacontext.yang b/yang/yang-data-util/src/test/resources/dataschemacontext.yang new file mode 100644 index 0000000000..a8ec4cfb3c --- /dev/null +++ b/yang/yang-data-util/src/test/resources/dataschemacontext.yang @@ -0,0 +1,12 @@ +module dataschemacontext { + namespace "dataschemacontext"; + prefix dsc; + + container foo { + choice bar { + leaf baz { + type string; + } + } + } +}