Remove ImportResolutionMode.SEMVER_LATEST
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / openconfigver / OpenconfigVersionDefaultsTest.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.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.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.concepts.SemVer;
19 import org.opendaylight.yangtools.yang.common.XMLNamespace;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
22 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
25
26 @Deprecated(since = "8.0.4", forRemoval = true)
27 public class OpenconfigVersionDefaultsTest {
28     private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
29         .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
30         .build();
31
32     @Test
33     public void defaultsTest() throws Exception {
34         final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults", SEMVER);
35         assertNotNull(context);
36
37         Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
38         Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
39
40         assertEquals(Optional.empty(), foo.getSemanticVersion());
41         assertEquals(Optional.empty(), bar.getSemanticVersion());
42     }
43
44     @Test
45     public void defaultMajorValidTest() throws Exception {
46         final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
47             SEMVER);
48         assertNotNull(context);
49
50         Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
51         Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
52
53         assertEquals(Optional.empty(), foo.getSemanticVersion());
54         assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion().get());
55     }
56
57     @Test
58     public void defaultMajorInvalidTest() throws Exception {
59         final var ex = assertThrows(ReactorException.class,
60             () -> StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid", SEMVER));
61         assertThat(ex.getCause().getMessage(),
62             startsWith("Unable to find module compatible with requested import [bar(0.0.1)]."));
63     }
64 }