2 * Copyright (c) 2021 PANTHEON.tech, 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.model.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertThrows;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.common.XMLNamespace;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class YT1297Test {
24 private static final QNameModule RESTCONF =
25 QNameModule.create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-restconf"), Revision.of("2017-01-26"));
26 private static final QNameModule BAD_MODULE =
27 QNameModule.create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-restconf"), Revision.of("2018-01-26"));
29 private static EffectiveModelContext context;
31 private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
34 public static void beforeClass() {
35 context = YangParserTestUtils.parseYangResource("/ietf-restconf.yang");
39 public void testEnterYangData() {
40 assertNotNull(stack.enterYangData(RESTCONF, "yang-api"));
41 assertNotNull(stack.enterDataTree(QName.create(RESTCONF, "restconf")));
45 public void testEnterYangDataNegative() {
46 Exception ex = assertThrows(IllegalArgumentException.class, () -> stack.enterYangData(RESTCONF, "bad-name"));
47 assertEquals("yang-data bad-name not present in " + RESTCONF, ex.getMessage());
48 ex = assertThrows(IllegalArgumentException.class, () -> stack.enterYangData(BAD_MODULE, "whatever"));
49 assertEquals("Module for " + BAD_MODULE + " not found", ex.getMessage());
51 assertNotNull(stack.enterGrouping(QName.create(RESTCONF, "errors")));
52 ex = assertThrows(IllegalStateException.class, () -> stack.enterYangData(RESTCONF, "yang-api"));
53 assertEquals("Cannot lookup yang-data in a non-empty stack", ex.getMessage());