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