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 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;
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)
33 public void defaultsTest() throws Exception {
34 final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults", SEMVER);
35 assertNotNull(context);
37 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
38 Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
40 assertEquals(Optional.empty(), foo.getSemanticVersion());
41 assertEquals(Optional.empty(), bar.getSemanticVersion());
45 public void defaultMajorValidTest() throws Exception {
46 final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
48 assertNotNull(context);
50 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
51 Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
53 assertEquals(Optional.empty(), foo.getSemanticVersion());
54 assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion().get());
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)]."));