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;
13 import java.util.Optional;
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.parser.api.ImportResolutionMode;
21 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24 @Deprecated(since = "8.0.4", forRemoval = true)
25 public class OpenconfigVersionComplexTest {
26 private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
27 .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
31 public void complexTest1() throws Exception {
32 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-1",
34 verifySchemaContextTest1(context);
38 public void complexTest1Yang1_1() throws Exception {
39 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-1-rfc7950",
41 verifySchemaContextTest1(context);
44 private static void verifySchemaContextTest1(final SchemaContext context) {
45 assertNotNull(context);
47 final Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
48 final Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
51 // check module versions
52 assertEquals(SemVer.valueOf("1.3.95"), semVer.getSemanticVersion().get());
53 assertEquals(SemVer.valueOf("1.50.2"), foo.getSemanticVersion().get());
55 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
56 assertEquals(SemVer.valueOf("1.2.6"), bar.getSemanticVersion().get());
58 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
59 assertEquals(SemVer.valueOf("2.26.465"), foobar.getSemanticVersion().get());
61 // check imported components
62 assertNotNull("This component should be present", context.findDataTreeChild(
63 QName.create(bar.getQNameModule(), "root"),
64 QName.create(bar.getQNameModule(), "test-container"),
65 QName.create(bar.getQNameModule(), "number")).orElse(null));
67 assertNotNull("This component should be present", context.findDataTreeChild(
68 QName.create(bar.getQNameModule(), "should-present")).orElse(null));
70 // check not imported components
71 assertEquals("This component should not be present", Optional.empty(), context.findDataTreeChild(
72 QName.create(bar.getQNameModule(), "root"),
73 QName.create(bar.getQNameModule(), "test-container"),
74 QName.create(bar.getQNameModule(), "oldnumber")));
76 assertEquals("This component should not be present", Optional.empty(), context.findDataTreeChild(
77 QName.create(bar.getQNameModule(), "should-not-be-present")));
81 public void complexTest2() throws Exception {
82 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-2", SEMVER);
83 verifySchemaContextTest2(context);
87 public void complexTest2Yang1_1() throws Exception {
88 final SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/complex/complex-2-rfc7950",
90 verifySchemaContextTest2(context);
93 private static void verifySchemaContextTest2(final SchemaContext context) {
94 assertNotNull(context);
96 final Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
97 final Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
100 // check module versions
101 assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion().get());
102 assertEquals(SemVer.valueOf("2.32.2"), foo.getSemanticVersion().get());
104 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
105 assertEquals(SemVer.valueOf("4.9.8"), bar.getSemanticVersion().get());
107 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
108 assertEquals(SemVer.valueOf("7.13.99"), foobar.getSemanticVersion().get());
110 // check used augmentations
111 assertNotNull("This component should be present", context.findDataTreeChild(
112 QName.create(foobar.getQNameModule(), "root"),
113 QName.create(foobar.getQNameModule(), "test-container"),
114 QName.create(bar.getQNameModule(), "should-present-leaf-1")).orElse(null));
116 assertNotNull("This component should be present", context.findDataTreeChild(
117 QName.create(foobar.getQNameModule(), "root"),
118 QName.create(foobar.getQNameModule(), "test-container"),
119 QName.create(bar.getQNameModule(), "should-present-leaf-2")).orElse(null));
121 // check not used augmentations
122 assertEquals("This component should not be present", Optional.empty(), context.findDataTreeChild(
123 QName.create(foobar.getQNameModule(), "root"),
124 QName.create(foobar.getQNameModule(), "test-container"),
125 QName.create(bar.getQNameModule(), "should-not-be-present-leaf-1")));
126 assertEquals("This component should not be present", Optional.empty(), context.findDataTreeChild(
127 QName.create(foobar.getQNameModule(), "root"),
128 QName.create(foobar.getQNameModule(), "test-container"),
129 QName.create(bar.getQNameModule(), "should-not-be-present-leaf-2")));
131 // check if correct foobar module was included
132 assertNotNull("This component should be present", context.findDataTreeChild(
133 QName.create(foobar.getQNameModule(), "root"),
134 QName.create(foobar.getQNameModule(), "included-correct-mark")).orElse(null));
136 assertEquals("This component should not be present", Optional.empty(), context.findDataTreeChild(
137 QName.create(foobar.getQNameModule(), "root"),
138 QName.create(foobar.getQNameModule(), "included-not-correct-mark")));