2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.util.codec;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
16 import java.util.Optional;
17 import org.junit.AfterClass;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.QNameModule;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class DataSchemaContextTreeTest {
27 private static final QNameModule MODULE = QNameModule.create(URI.create("dataschemacontext"));
28 private static final QName FOO = QName.create(MODULE, "foo");
29 private static final QName BAR = QName.create(MODULE, "bar");
30 private static final QName BAZ = QName.create(MODULE, "baz");
31 private static DataSchemaContextTree CONTEXT;
34 public static void init() {
35 CONTEXT = DataSchemaContextTree.from(YangParserTestUtils.parseYangResource("/dataschemacontext.yang"));
39 public static void cleanup() {
44 public void testCorrectInput() {
45 assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO)).isPresent());
46 assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR)).isPresent());
47 assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ)).isPresent());
49 assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO)));
50 assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO).node(BAR)));
51 assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ)));
55 public void testSimpleBad() {
56 assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR)));
57 assertNull(CONTEXT.getChild(YangInstanceIdentifier.of(BAR)));
61 public void testNestedBad() {
62 assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR).node(BAZ)));
63 assertNull(CONTEXT.getChild(YangInstanceIdentifier.of(BAR).node(BAZ)));