d6ab9af4205dff3c1e8f62ad4267e9f3ae8db627
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / openconfigver / OpenconfigVersionImportTest.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 OpenconfigVersionImportTest {
25
26     @Test
27     public void importValidTest() throws Exception {
28         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/import/import-valid",
29                 StatementParserMode.OPENCONFIG_VER_MODE);
30         assertNotNull(context);
31
32         Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
33                 .iterator().next();
34
35         assertEquals(SemVer.valueOf("1.0.0"), semVer.getOpenconfigVersion());
36     }
37
38     @Test
39     public void importInvalidDeprecatedTest1() throws Exception {
40         try {
41             StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-1",
42                     StatementParserMode.OPENCONFIG_VER_MODE);
43             fail("Test should fail due to invalid import of openconfig-version module");
44         } catch (ReactorException e) {
45             assertTrue(e.getCause().getMessage().startsWith(
46                     "Unable to find module compatible with requested import " + "[openconfig-extensions(1.0.0)]."));
47         }
48     }
49
50     @Test
51     public void importInvalidDeprecatedTest2() throws Exception {
52         try {
53             StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-2",
54                     StatementParserMode.OPENCONFIG_VER_MODE);
55             fail("Test should fail due to invalid import of openconfig-version module");
56         } catch (ReactorException e) {
57             assertTrue(e.getCause().getMessage().startsWith(
58                     "Unable to find module compatible with requested import " + "[openconfig-extensions(0.9.9)]."));
59         }
60     }
61
62     @Test
63     public void importInvalidNotsufficientTest1() throws Exception {
64         try {
65             StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-1",
66                     StatementParserMode.OPENCONFIG_VER_MODE);
67             fail("Test should fail due to invalid import of openconfig-version module");
68         } catch (ReactorException e) {
69             assertTrue(e.getCause().getMessage().startsWith(
70                     "Unable to find module compatible with requested import " + "[openconfig-extensions(2.0.0)]."));
71         }
72     }
73
74     @Test
75     public void importInvalidNotsufficientTest2() throws Exception {
76         try {
77             StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-2",
78                     StatementParserMode.OPENCONFIG_VER_MODE);
79             fail("Test should fail due to invalid import of openconfig-version module");
80         } catch (ReactorException e) {
81             assertTrue(e.getCause().getMessage().startsWith(
82                     "Unable to find module compatible with requested import " + "[openconfig-extensions(2.0.5)]."));
83         }
84     }
85 }