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;
15 import java.io.FileNotFoundException;
17 import java.net.URISyntaxException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.concepts.SemVer;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27 public class SemanticVersionDefaultsTest {
30 public void defaultsTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
31 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/defaults/defaults",
32 StatementParserMode.SEMVER_MODE);
33 assertNotNull(context);
35 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
36 Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
38 assertEquals(SemVer.valueOf("0.0.0"), foo.getSemanticVersion());
39 assertEquals(SemVer.valueOf("0.0.0"), bar.getSemanticVersion());
43 public void defaultMajorValidTest() throws SourceException, FileNotFoundException, ReactorException,
45 SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/defaults/default-major-valid",
46 StatementParserMode.SEMVER_MODE);
47 assertNotNull(context);
49 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
50 Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
52 assertEquals(SemVer.valueOf("0.0.0"), foo.getSemanticVersion());
53 assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion());
57 public void defaultMajorInvalidTest() throws SourceException, FileNotFoundException, ReactorException,
60 StmtTestUtils.parseYangSources("/semantic-version/defaults/default-major-invalid", StatementParserMode.SEMVER_MODE);
61 fail("Test should fail due to invalid semantic version");
62 } catch (ReactorException e) {
63 assertTrue(e.getCause().getMessage()
64 .startsWith("Unable to find module compatible with requested import [bar(0.0.0)]."));