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.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertThrows;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.concepts.SemVer;
18 import org.opendaylight.yangtools.yang.common.XMLNamespace;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
22 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
26 @Deprecated(since = "8.0.4", forRemoval = true)
27 public class OpenconfigVersionBorderCaseTest {
28 private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
29 .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
33 public void borderCaseValidMajorTest() throws Exception {
34 SchemaContext context = StmtTestUtils.parseYangSources(
35 "/openconfig-version/border-case/border-case-valid-major", SEMVER);
36 assertNotNull(context);
38 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
39 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
42 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
43 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
44 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
45 assertEquals(SemVer.valueOf("5.5.5"), bar.getSemanticVersion().get());
49 public void borderCaseValidMinorTest() throws Exception {
50 SchemaContext context = StmtTestUtils.parseYangSources(
51 "/openconfig-version/border-case/border-case-valid-minor", SEMVER);
52 assertNotNull(context);
54 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
55 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
58 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
59 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
60 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
61 assertEquals(SemVer.valueOf("5.6.5"), bar.getSemanticVersion().get());
65 public void borderCaseValidPatchTest() throws Exception {
66 SchemaContext context = StmtTestUtils.parseYangSources(
67 "/openconfig-version/border-case/border-case-valid-patch", SEMVER);
68 assertNotNull(context);
70 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
71 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
74 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
75 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
76 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
77 assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion().get());
81 public void borderCaseInvalidMajorTest() throws Exception {
82 final ReactorException ex = assertThrows(ReactorException.class,
83 () -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-major", SEMVER));
84 assertThat(ex.getCause().getMessage(),
85 startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
89 public void borderCaseInvalidMinorTest() {
90 final ReactorException ex = assertThrows(ReactorException.class,
91 () -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-minor", SEMVER));
92 assertThat(ex.getCause().getMessage(),
93 startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
97 public void borderCaseInvalidPatchTest() throws Exception {
98 final ReactorException ex = assertThrows(ReactorException.class,
99 () -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-patch", SEMVER));
100 assertThat(ex.getCause().getMessage(),
101 startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));