Deprecate getSemanticVersion() for removal
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT1297Test.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertThrows;
13
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;
22
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"));
28
29     private static EffectiveModelContext context;
30
31     private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
32
33     @BeforeClass
34     public static void beforeClass() {
35         context = YangParserTestUtils.parseYangResource("/ietf-restconf.yang");
36     }
37
38     @Test
39     public void testEnterYangData() {
40         assertNotNull(stack.enterYangData(RESTCONF, "yang-api"));
41         assertNotNull(stack.enterDataTree(QName.create(RESTCONF, "restconf")));
42     }
43
44     @Test
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());
50
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());
54     }
55 }