Enforce checkstyle in yang-data-util
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / openconfigver / OpenconfigVersionBorderCaseTest.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.openconfigver;
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 OpenconfigVersionBorderCaseTest {
25
26     @Test
27     public void borderCaseValidMajorTest() throws Exception {
28         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-valid-major",
29                 StatementParserMode.SEMVER_MODE);
30         assertNotNull(context);
31
32         Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
33         Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
34                 .iterator().next();
35
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());
40     }
41
42     @Test
43     public void borderCaseValidMinorTest() throws Exception {
44         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-valid-minor",
45                 StatementParserMode.SEMVER_MODE);
46         assertNotNull(context);
47
48         Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
49         Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
50                 .iterator().next();
51
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());
56     }
57
58     @Test
59     public void borderCaseValidPatchTest() throws Exception {
60         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-valid-patch",
61                 StatementParserMode.SEMVER_MODE);
62         assertNotNull(context);
63
64         Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
65         Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
66                 .iterator().next();
67
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());
72     }
73
74     @Test
75     public void borderCaseInvalidMajorTest() throws Exception {
76         try {
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().getMessage()
82                     .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
83         }
84     }
85
86     @Test
87     public void borderCaseInvalidMinorTest() throws Exception {
88         try {
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().getMessage()
94                     .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
95         }
96     }
97
98     @Test
99     public void borderCaseInvalidPatchTest() throws Exception {
100         try {
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().getMessage()
106                     .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
107         }
108     }
109 }