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;
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;
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("/rfc7950/openconfig-version/complex-1",
36 StatementParserMode.SEMVER_MODE);
37 verifySchemaContextTest1(context);
40 private static void verifySchemaContextTest1(final SchemaContext context) {
41 assertNotNull(context);
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"))
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, foo,
59 new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:number", true)));
61 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo,
62 new RevisionAwareXPathImpl("/bar:should-present", true)));
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)));
68 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo,
69 new RevisionAwareXPathImpl("/bar:should-not-be-present", true)));
73 public void complexTest2() throws Exception {
74 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-2",
75 StatementParserMode.SEMVER_MODE);
76 verifySchemaContextTest2(context);
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);
86 private static void verifySchemaContextTest2(final SchemaContext context) {
87 assertNotNull(context);
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"))
93 // check module versions
94 assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion().get());
95 assertEquals(SemVer.valueOf("2.32.2"), foo.getSemanticVersion().get());
97 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
98 assertEquals(SemVer.valueOf("4.9.8"), bar.getSemanticVersion().get());
100 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
101 assertEquals(SemVer.valueOf("7.13.99"), foobar.getSemanticVersion().get());
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)));
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)));
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)));
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)));
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)));
123 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, bar,
124 new RevisionAwareXPathImpl("/foobar:root/foobar:included-not-correct-mark", true)));