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