2 * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.openconfigver;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.concepts.SemVer;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.XMLNamespace;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
21 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24 public class OpenconfigVersionComplexTest {
27 public void complexTest1() throws Exception {
28 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-1",
29 StatementParserMode.SEMVER_MODE);
30 verifySchemaContextTest1(context);
34 public void complexTest1Yang1_1() throws Exception {
35 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-1-rfc7950",
36 StatementParserMode.SEMVER_MODE);
37 verifySchemaContextTest1(context);
40 private static void verifySchemaContextTest1(final SchemaContext context) {
41 assertNotNull(context);
43 final Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
44 final Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
47 // check module versions
48 assertEquals(SemVer.valueOf("1.3.95"), semVer.getSemanticVersion().get());
49 assertEquals(SemVer.valueOf("1.50.2"), foo.getSemanticVersion().get());
51 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
52 assertEquals(SemVer.valueOf("1.2.6"), bar.getSemanticVersion().get());
54 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
55 assertEquals(SemVer.valueOf("2.26.465"), foobar.getSemanticVersion().get());
57 // check imported components
58 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context,
59 QName.create(bar.getQNameModule(), "root"),
60 QName.create(bar.getQNameModule(), "test-container"),
61 QName.create(bar.getQNameModule(), "number")));
63 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context,
64 QName.create(bar.getQNameModule(), "should-present")));
66 // check not imported components
67 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context,
68 QName.create(bar.getQNameModule(), "root"),
69 QName.create(bar.getQNameModule(), "test-container"),
70 QName.create(bar.getQNameModule(), "oldnumber")));
72 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context,
73 QName.create(bar.getQNameModule(), "should-not-be-present")));
77 public void complexTest2() throws Exception {
78 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-2",
79 StatementParserMode.SEMVER_MODE);
80 verifySchemaContextTest2(context);
84 public void complexTest2Yang1_1() throws Exception {
85 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-2-rfc7950",
86 StatementParserMode.SEMVER_MODE);
87 verifySchemaContextTest2(context);
90 private static void verifySchemaContextTest2(final SchemaContext context) {
91 assertNotNull(context);
93 final Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
94 final Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
97 // check module versions
98 assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion().get());
99 assertEquals(SemVer.valueOf("2.32.2"), foo.getSemanticVersion().get());
101 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
102 assertEquals(SemVer.valueOf("4.9.8"), bar.getSemanticVersion().get());
104 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
105 assertEquals(SemVer.valueOf("7.13.99"), foobar.getSemanticVersion().get());
107 // check used augmentations
108 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context,
109 QName.create(foobar.getQNameModule(), "root"),
110 QName.create(foobar.getQNameModule(), "test-container"),
111 QName.create(bar.getQNameModule(), "should-present-leaf-1")));
113 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context,
114 QName.create(foobar.getQNameModule(), "root"),
115 QName.create(foobar.getQNameModule(), "test-container"),
116 QName.create(bar.getQNameModule(), "should-present-leaf-2")));
118 // check not used augmentations
119 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context,
120 QName.create(foobar.getQNameModule(), "root"),
121 QName.create(foobar.getQNameModule(), "test-container"),
122 QName.create(bar.getQNameModule(), "should-not-be-present-leaf-1")));
123 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context,
124 QName.create(foobar.getQNameModule(), "root"),
125 QName.create(foobar.getQNameModule(), "test-container"),
126 QName.create(bar.getQNameModule(), "should-not-be-present-leaf-2")));
128 // check if correct foobar module was included
129 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context,
130 QName.create(foobar.getQNameModule(), "root"),
131 QName.create(foobar.getQNameModule(), "included-correct-mark")));
133 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context,
134 QName.create(foobar.getQNameModule(), "root"),
135 QName.create(foobar.getQNameModule(), "included-not-correct-mark")));