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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
15 import java.util.Optional;
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 OpenconfigVersionDefaultsTest {
27 private static final YangParserConfiguration SEMVER = YangParserConfiguration.builder()
28 .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
32 public void defaultsTest() throws Exception {
33 SchemaContext 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 SchemaContext 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 {
59 StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid", SEMVER);
60 fail("Test should fail due to invalid openconfig version");
61 } catch (ReactorException e) {
62 assertTrue(e.getCause().getCause().getMessage()
63 .startsWith("Unable to find module compatible with requested import [bar(0.0.1)]."));