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 public class OpenconfigVersionDefaultsTest {
27 private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
28 .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
32 public void defaultsTest() throws Exception {
33 final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults", SEMVER);
34 assertNotNull(context);
36 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
37 Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
39 assertEquals(Optional.empty(), foo.getSemanticVersion());
40 assertEquals(Optional.empty(), bar.getSemanticVersion());
44 public void defaultMajorValidTest() throws Exception {
45 final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
47 assertNotNull(context);
49 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
50 Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
52 assertEquals(Optional.empty(), foo.getSemanticVersion());
53 assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion().get());
57 public void defaultMajorInvalidTest() throws Exception {
58 final var ex = assertThrows(ReactorException.class,
59 () -> StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid", SEMVER));
60 assertThat(ex.getCause().getMessage(),
61 startsWith("Unable to find module compatible with requested import [bar(0.0.1)]."));