Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / openconfigver / OpenconfigVersionComplexTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.openconfigver;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13
14 import java.net.URI;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.concepts.SemVer;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
20 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
21 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
23
24 public class OpenconfigVersionComplexTest {
25
26     @Test
27     public void complexTest1() throws Exception {
28         final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-1",
29                 StatementParserMode.SEMVER_MODE);
30         verifySchemaContextTest1(context);
31     }
32
33     @Test
34     public void complexTest1Yang1_1() throws Exception {
35         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/openconfig-version/complex-1",
36                 StatementParserMode.SEMVER_MODE);
37         verifySchemaContextTest1(context);
38     }
39
40     private static void verifySchemaContextTest1(final SchemaContext context) {
41         assertNotNull(context);
42
43         final Module foo = context.findModules(URI.create("foo")).iterator().next();
44         final Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext"))
45                 .iterator().next();
46
47         // check module versions
48         assertEquals(SemVer.valueOf("1.3.95"), semVer.getSemanticVersion().get());
49         assertEquals(SemVer.valueOf("1.50.2"), foo.getSemanticVersion().get());
50
51         final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
52         assertEquals(SemVer.valueOf("1.2.6"), bar.getSemanticVersion().get());
53
54         final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
55         assertEquals(SemVer.valueOf("2.26.465"), foobar.getSemanticVersion().get());
56
57         // check imported components
58         assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo,
59                 new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:number", true)));
60
61         assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo,
62                 new RevisionAwareXPathImpl("/bar:should-present", true)));
63
64         // check not imported components
65         assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo,
66                 new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:oldnumber", true)));
67
68         assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo,
69                 new RevisionAwareXPathImpl("/bar:should-not-be-present", true)));
70     }
71
72     @Test
73     public void complexTest2() throws Exception {
74         final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-2",
75                 StatementParserMode.SEMVER_MODE);
76         verifySchemaContextTest2(context);
77     }
78
79     @Test
80     public void complexTest2Yang1_1() throws Exception {
81         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/openconfig-version/complex-2",
82                 StatementParserMode.SEMVER_MODE);
83         verifySchemaContextTest2(context);
84     }
85
86     private static void verifySchemaContextTest2(final SchemaContext context) {
87         assertNotNull(context);
88
89         final Module foo = context.findModules(URI.create("foo")).iterator().next();
90         final Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext"))
91                 .iterator().next();
92
93         // check module versions
94         assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion().get());
95         assertEquals(SemVer.valueOf("2.32.2"), foo.getSemanticVersion().get());
96
97         final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
98         assertEquals(SemVer.valueOf("4.9.8"), bar.getSemanticVersion().get());
99
100         final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
101         assertEquals(SemVer.valueOf("7.13.99"), foobar.getSemanticVersion().get());
102
103         // check used augmentations
104         assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar,
105                 new RevisionAwareXPathImpl("/foobar:root/foobar:test-container/bar:should-present-leaf-1", true)));
106
107         assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar,
108                 new RevisionAwareXPathImpl("/foobar:root/foobar:test-container/bar:should-present-leaf-2", true)));
109
110         // check not used augmentations
111         assertNull("This component should not be present",
112                 SchemaContextUtil.findDataSchemaNode(context, bar, new RevisionAwareXPathImpl(
113                         "/foobar:root/foobar:test-container/bar:should-not-be-present-leaf-1", true)));
114
115         assertNull("This component should not be present",
116                 SchemaContextUtil.findDataSchemaNode(context, bar, new RevisionAwareXPathImpl(
117                         "/foobar:root/foobar:test-container/bar:should-not-be-present-leaf-2", true)));
118
119         // check if correct foobar module was included
120         assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar,
121                 new RevisionAwareXPathImpl("/foobar:root/foobar:included-correct-mark", true)));
122
123         assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, bar,
124                 new RevisionAwareXPathImpl("/foobar:root/foobar:included-not-correct-mark", true)));
125     }
126 }