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.semver;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import java.io.FileNotFoundException;
16 import java.net.URISyntaxException;
17 import java.text.ParseException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.concepts.SemVer;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
23 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
24 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
27 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
29 public class SemanticVersionComplexTest {
32 public void complexTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException,
34 final SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/complex/complex-1",
35 StatementParserMode.SEMVER_MODE);
36 verifySchemaContextTest1(context);
40 public void complexTest1Yang1_1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException,
42 final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/semantic-version/complex-1",
43 StatementParserMode.SEMVER_MODE);
44 verifySchemaContextTest1(context);
47 private void verifySchemaContextTest1(final SchemaContext context) throws URISyntaxException {
48 assertNotNull(context);
50 final Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
51 final Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
54 // check module versions
55 assertEquals(SemVer.valueOf("1.3.95"), semVer.getSemanticVersion());
56 assertEquals(SemVer.valueOf("1.50.2"), foo.getSemanticVersion());
58 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
59 assertEquals(SemVer.valueOf("1.2.6"), bar.getSemanticVersion());
61 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
62 assertEquals(SemVer.valueOf("2.26.465"), foobar.getSemanticVersion());
64 // check imported components
65 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo,
66 new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:number", true)));
68 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo,
69 new RevisionAwareXPathImpl("/bar:should-present", true)));
71 // check not imported components
72 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo,
73 new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:oldnumber", true)));
75 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo,
76 new RevisionAwareXPathImpl("/bar:should-not-be-present", true)));
80 public void complexTest2() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException,
82 final SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/complex/complex-2",
83 StatementParserMode.SEMVER_MODE);
84 verifySchemaContextTest2(context);
88 public void complexTest2Yang1_1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException,
90 final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/semantic-version/complex-2",
91 StatementParserMode.SEMVER_MODE);
92 verifySchemaContextTest2(context);
95 private void verifySchemaContextTest2(final SchemaContext context) throws URISyntaxException {
96 assertNotNull(context);
98 final Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
99 final Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
102 // check module versions
103 assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion());
104 assertEquals(SemVer.valueOf("2.32.2"), foo.getSemanticVersion());
106 final Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
107 assertEquals(SemVer.valueOf("4.9.8"), bar.getSemanticVersion());
109 final Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar");
110 assertEquals(SemVer.valueOf("7.13.99"), foobar.getSemanticVersion());
112 // check used augmentations
113 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar,
114 new RevisionAwareXPathImpl("/foobar:root/foobar:test-container/bar:should-present-leaf-1", true)));
116 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar,
117 new RevisionAwareXPathImpl("/foobar:root/foobar:test-container/bar:should-present-leaf-2", true)));
119 // check not used augmentations
120 assertNull("This component should not be present",
121 SchemaContextUtil.findDataSchemaNode(context, bar, new RevisionAwareXPathImpl(
122 "/foobar:root/foobar:test-container/bar:should-not-be-present-leaf-1", true)));
124 assertNull("This component should not be present",
125 SchemaContextUtil.findDataSchemaNode(context, bar, new RevisionAwareXPathImpl(
126 "/foobar:root/foobar:test-container/bar:should-not-be-present-leaf-2", true)));
128 // check if correct foobar module was included
129 assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar,
130 new RevisionAwareXPathImpl("/foobar:root/foobar:included-correct-mark", true)));
132 assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, bar,
133 new RevisionAwareXPathImpl("/foobar:root/foobar:included-not-correct-mark", true)));