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;
15 import java.io.FileNotFoundException;
17 import java.net.URISyntaxException;
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.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27 public class SemanticVersionBorderCaseTest {
30 public void borderCaseValidMajorTest() throws SourceException, FileNotFoundException, ReactorException,
32 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-valid-major",
33 StatementParserMode.SEMVER_MODE);
34 assertNotNull(context);
36 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
37 Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
40 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
41 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
42 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
43 assertEquals(SemVer.valueOf("5.5.5"), bar.getSemanticVersion());
47 public void borderCaseValidMinorTest() throws SourceException, FileNotFoundException, ReactorException,
49 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-valid-minor",
50 StatementParserMode.SEMVER_MODE);
51 assertNotNull(context);
53 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
54 Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
57 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
58 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
59 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
60 assertEquals(SemVer.valueOf("5.6.5"), bar.getSemanticVersion());
64 public void borderCaseValidPatchTest() throws SourceException, FileNotFoundException, ReactorException,
66 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-valid-patch",
67 StatementParserMode.SEMVER_MODE);
68 assertNotNull(context);
70 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
71 Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
74 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
75 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
76 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
77 assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion());
81 public void borderCaseInvalidMajorTest() throws SourceException, FileNotFoundException, ReactorException,
84 StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-invalid-major",
85 StatementParserMode.SEMVER_MODE);
86 fail("Test should fail due to invalid semantic version");
87 } catch (ReactorException e) {
88 assertTrue(e.getCause().getMessage()
89 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
94 public void borderCaseInvalidMinorTest() throws SourceException, FileNotFoundException, ReactorException,
97 StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-invalid-minor",
98 StatementParserMode.SEMVER_MODE);
99 fail("Test should fail due to invalid semantic version");
100 } catch (ReactorException e) {
101 assertTrue(e.getCause().getMessage()
102 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
107 public void borderCaseInvalidPatchTest() throws SourceException, FileNotFoundException, ReactorException,
110 StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-invalid-patch",
111 StatementParserMode.SEMVER_MODE);
112 fail("Test should fail due to invalid semantic version");
113 } catch (ReactorException e) {
114 assertTrue(e.getCause().getMessage()
115 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));