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.semver;
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;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.concepts.SemVer;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24 public class SemanticVersionDefaultsTest {
27 public void defaultsTest() throws Exception {
28 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/defaults/defaults",
29 StatementParserMode.SEMVER_MODE);
30 assertNotNull(context);
32 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
33 Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
35 assertEquals(SemVer.valueOf("0.0.0"), foo.getSemanticVersion());
36 assertEquals(SemVer.valueOf("0.0.0"), bar.getSemanticVersion());
40 public void defaultMajorValidTest() throws Exception {
41 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/defaults/default-major-valid",
42 StatementParserMode.SEMVER_MODE);
43 assertNotNull(context);
45 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
46 Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
48 assertEquals(SemVer.valueOf("0.0.0"), foo.getSemanticVersion());
49 assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion());
53 public void defaultMajorInvalidTest() throws Exception {
55 StmtTestUtils.parseYangSources("/semantic-version/defaults/default-major-invalid",
56 StatementParserMode.SEMVER_MODE);
57 fail("Test should fail due to invalid semantic version");
58 } catch (ReactorException e) {
59 assertTrue(e.getCause().getMessage()
60 .startsWith("Unable to find module compatible with requested import [bar(0.0.0)]."));