Remove ImportResolutionMode.SEMVER_LATEST
[yangtools.git] / parser / yang-parser-rfc7950 / 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 package org.opendaylight.yangtools.yang.stmt.openconfigver.yin;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertThrows;
15
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.concepts.SemVer;
20 import org.opendaylight.yangtools.yang.common.XMLNamespace;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
24 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27 import org.xml.sax.SAXException;
28
29 @Deprecated(since = "8.0.4", forRemoval = true)
30 public class YinOpenconfigVersionTest {
31     private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
32         .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
33         .build();
34
35     @Test
36     public void basicTest() throws URISyntaxException, SAXException, IOException, ReactorException {
37         SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic", SEMVER);
38         assertNotNull(context);
39
40         Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
41         Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
42         Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
43             .iterator().next();
44
45         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
46         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
47         assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion().get());
48     }
49
50     @Test
51     public void basicImportTest1() throws URISyntaxException, SAXException, IOException, ReactorException {
52         SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import", SEMVER);
53         assertNotNull(context);
54
55         Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
56         Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
57             .iterator().next();
58
59         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
60         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
61         Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
62         assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion().get());
63     }
64
65     @Test
66     public void basicImportErrTest1() {
67         ReactorException ex = assertThrows(ReactorException.class,
68             () -> StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid", SEMVER));
69         assertThat(ex.getCause().getMessage(),
70             startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
71     }
72 }