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.assertTrue;
13 import static org.junit.Assert.fail;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.concepts.SemVer;
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.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24 public class OpenconfigVersionBorderCaseTest {
27 public void borderCaseValidMajorTest() throws Exception {
28 SchemaContext context = StmtTestUtils.parseYangSources(
29 "/openconfig-version/border-case/border-case-valid-major", StatementParserMode.SEMVER_MODE);
30 assertNotNull(context);
32 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
33 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
36 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
37 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
38 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
39 assertEquals(SemVer.valueOf("5.5.5"), bar.getSemanticVersion().get());
43 public void borderCaseValidMinorTest() throws Exception {
44 SchemaContext context = StmtTestUtils.parseYangSources(
45 "/openconfig-version/border-case/border-case-valid-minor", StatementParserMode.SEMVER_MODE);
46 assertNotNull(context);
48 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
49 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
52 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
53 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
54 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
55 assertEquals(SemVer.valueOf("5.6.5"), bar.getSemanticVersion().get());
59 public void borderCaseValidPatchTest() throws Exception {
60 SchemaContext context = StmtTestUtils.parseYangSources(
61 "/openconfig-version/border-case/border-case-valid-patch", StatementParserMode.SEMVER_MODE);
62 assertNotNull(context);
64 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
65 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
68 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
69 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
70 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
71 assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion().get());
75 public void borderCaseInvalidMajorTest() throws Exception {
77 StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-major",
78 StatementParserMode.SEMVER_MODE);
79 fail("Test should fail due to invalid openconfig version");
80 } catch (ReactorException e) {
81 assertTrue(e.getCause().getCause().getMessage()
82 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
87 public void borderCaseInvalidMinorTest() throws Exception {
89 StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-minor",
90 StatementParserMode.SEMVER_MODE);
91 fail("Test should fail due to invalid openconfig version");
92 } catch (ReactorException e) {
93 assertTrue(e.getCause().getCause().getMessage()
94 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
99 public void borderCaseInvalidPatchTest() throws Exception {
101 StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-patch",
102 StatementParserMode.SEMVER_MODE);
103 fail("Test should fail due to invalid openconfig version");
104 } catch (ReactorException e) {
105 assertTrue(e.getCause().getCause().getMessage()
106 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));