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 public class OpenconfigVersionImportTest {
27 private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
28 .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
32 public void importValidTest() throws Exception {
33 SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/import/import-valid", SEMVER);
34 assertNotNull(context);
36 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
39 assertEquals(SemVer.valueOf("1.0.0"), semVer.getSemanticVersion().get());
43 public void importInvalidDeprecatedTest1() {
44 ReactorException ex = assertThrows(ReactorException.class,
45 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-1", SEMVER));
46 assertThat(ex.getCause().getMessage(), startsWith(
47 "Unable to find module compatible with requested import [openconfig-extensions(1.0.0)]."));
51 public void importInvalidDeprecatedTest2() {
52 ReactorException ex = assertThrows(ReactorException.class,
53 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-2", SEMVER));
54 assertThat(ex.getCause().getMessage(), startsWith(
55 "Unable to find module compatible with requested import [openconfig-extensions(0.9.9)]."));
59 public void importInvalidNotsufficientTest1() {
60 ReactorException ex = assertThrows(ReactorException.class,
61 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-1", SEMVER));
62 assertThat(ex.getCause().getMessage(), startsWith(
63 "Unable to find module compatible with requested import [openconfig-extensions(2.0.0)]."));
67 public void importInvalidNotsufficientTest2() {
68 ReactorException ex = assertThrows(ReactorException.class,
69 () -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-2", SEMVER));
70 assertThat(ex.getCause().getMessage(), startsWith(
71 "Unable to find module compatible with requested import [openconfig-extensions(2.0.5)]."));