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.assertTrue;
13 import java.util.Optional;
14 import org.junit.AfterClass;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.common.XMLNamespace;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24 public class DataSchemaContextTreeTest {
25 private static final QNameModule MODULE = QNameModule.create(XMLNamespace.of("dataschemacontext"));
26 private static final QName FOO = QName.create(MODULE, "foo");
27 private static final QName BAR = QName.create(MODULE, "bar");
28 private static final QName BAZ = QName.create(MODULE, "baz");
29 private static DataSchemaContextTree CONTEXT;
32 public static void init() {
33 CONTEXT = DataSchemaContextTree.from(YangParserTestUtils.parseYangResource("/dataschemacontext.yang"));
37 public static void cleanup() {
42 public void testCorrectInput() {
43 assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO)).isPresent());
44 assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR)).isPresent());
45 assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ)).isPresent());
49 public void testSimpleBad() {
50 assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR)));
54 public void testNestedBad() {
55 assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR).node(BAZ)));