Remove deprecated Yin/YangStatementSourceImpl
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / openconfigver / yin / YinOpenconfigVersionTest.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
9 package org.opendaylight.yangtools.yang.stmt.openconfigver.yin;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15
16 import java.io.IOException;
17 import java.net.URI;
18 import java.net.URISyntaxException;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.concepts.SemVer;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
26 import org.xml.sax.SAXException;
27
28 public class YinOpenconfigVersionTest {
29
30     @Test
31     public void basicTest() throws URISyntaxException, SAXException, IOException, ReactorException {
32         SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic",
33                 StatementParserMode.SEMVER_MODE);
34         assertNotNull(context);
35
36         Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
37         Module bar = context.findModuleByNamespace(URI.create("bar")).iterator().next();
38         Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext"))
39                 .iterator().next();
40
41         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
42         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
43         assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion());
44     }
45
46     @Test
47     public void basicImportTest1() throws URISyntaxException, SAXException, IOException, ReactorException {
48         SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import",
49                 StatementParserMode.SEMVER_MODE);
50         assertNotNull(context);
51
52         Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
53         Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext"))
54                 .iterator().next();
55
56         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
57         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
58         Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
59         assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion());
60     }
61
62     @Test
63     public void basicImportErrTest1() throws URISyntaxException, SAXException, IOException {
64         try {
65             StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid", StatementParserMode.SEMVER_MODE);
66             fail("Test should fail due to invalid openconfig version");
67         } catch (ReactorException e) {
68             assertTrue(e.getCause().getMessage()
69                     .startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
70         }
71     }
72 }