2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt.openconfigver;
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;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.concepts.SemVer;
18 import org.opendaylight.yangtools.yang.common.XMLNamespace;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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;
26 @Deprecated(since = "8.0.4", forRemoval = true)
27 public class OpenconfigVersionImportTest {
28 private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
29 .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
33 public void importValidTest() throws Exception {
34 SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/import/import-valid", SEMVER);
35 assertNotNull(context);
37 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
40 assertEquals(SemVer.valueOf("1.0.0"), semVer.getSemanticVersion().get());
44 public void importInvalidDeprecatedTest1() {
45 ReactorException ex = assertThrows(ReactorException.class,
46 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-1", SEMVER));
47 assertThat(ex.getCause().getMessage(), startsWith(
48 "Unable to find module compatible with requested import [openconfig-extensions(1.0.0)]."));
52 public void importInvalidDeprecatedTest2() {
53 ReactorException ex = assertThrows(ReactorException.class,
54 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-2", SEMVER));
55 assertThat(ex.getCause().getMessage(), startsWith(
56 "Unable to find module compatible with requested import [openconfig-extensions(0.9.9)]."));
60 public void importInvalidNotsufficientTest1() {
61 ReactorException ex = assertThrows(ReactorException.class,
62 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-1", SEMVER));
63 assertThat(ex.getCause().getMessage(), startsWith(
64 "Unable to find module compatible with requested import [openconfig-extensions(2.0.0)]."));
68 public void importInvalidNotsufficientTest2() {
69 ReactorException ex = assertThrows(ReactorException.class,
70 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-2", SEMVER));
71 assertThat(ex.getCause().getMessage(), startsWith(
72 "Unable to find module compatible with requested import [openconfig-extensions(2.0.5)]."));