Revert "Bug 4640: Change semantic-version to openconfig-version"
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / semver / SemanticVersionImportTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt.semver;
9
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;
14
15 import java.net.URI;
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;
23
24 public class SemanticVersionImportTest {
25
26     @Test
27     public void importValidTest() throws Exception {
28         SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/import/import-valid",
29                 StatementParserMode.SEMVER_MODE);
30         assertNotNull(context);
31
32         Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
33                 .iterator().next();
34
35         assertEquals(SemVer.valueOf("1.0.0"), semVer.getSemanticVersion());
36     }
37
38     @Test
39     public void importInvalidDeprecatedTest1() throws Exception {
40         try {
41             StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-deprecated-1",
42                     StatementParserMode.SEMVER_MODE);
43             fail("Test should fail due to invalid import of semantic-version module");
44         } catch (ReactorException e) {
45             assertTrue(e.getCause().getMessage().startsWith(
46                     "Unable to find module compatible with requested import " + "[semantic-version(1.0.0)]."));
47         }
48     }
49
50     @Test
51     public void importInvalidDeprecatedTest2() throws Exception {
52         try {
53             StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-deprecated-2",
54                     StatementParserMode.SEMVER_MODE);
55             fail("Test should fail due to invalid import of semantic-version module");
56         } catch (ReactorException e) {
57             assertTrue(e.getCause().getMessage().startsWith(
58                     "Unable to find module compatible with requested import " + "[semantic-version(0.9.9)]."));
59         }
60     }
61
62     @Test
63     public void importInvalidNotsufficientTest1() throws Exception {
64         try {
65             StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-notsufficient-1",
66                     StatementParserMode.SEMVER_MODE);
67             fail("Test should fail due to invalid import of semantic-version module");
68         } catch (ReactorException e) {
69             assertTrue(e.getCause().getMessage().startsWith(
70                     "Unable to find module compatible with requested import " + "[semantic-version(2.0.0)]."));
71         }
72     }
73
74     @Test
75     public void importInvalidNotsufficientTest2() throws Exception {
76         try {
77             StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-notsufficient-2",
78                     StatementParserMode.SEMVER_MODE);
79             fail("Test should fail due to invalid import of semantic-version module");
80         } catch (ReactorException e) {
81             assertTrue(e.getCause().getMessage().startsWith(
82                     "Unable to find module compatible with requested import " + "[semantic-version(2.0.5)]."));
83         }
84     }
85 }