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
9 package org.opendaylight.yangtools.yang.stmt.semver.yin;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import java.io.FileNotFoundException;
18 import java.net.URISyntaxException;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.concepts.SemVer;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
28 public class YinSemanticVersionTest {
31 public void basicTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
32 SchemaContext context = StmtTestUtils.parseYinSources("/semantic-version/yin-input/basic",
33 StatementParserMode.SEMVER_MODE);
34 assertNotNull(context);
36 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
37 Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
38 Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
41 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
42 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
43 assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion());
47 public void basicImportTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
48 SchemaContext context = StmtTestUtils.parseYinSources("/semantic-version/yin-input/basic-import",
49 StatementParserMode.SEMVER_MODE);
50 assertNotNull(context);
52 Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
53 Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version"))
56 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
57 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion());
58 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
59 assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion());
63 public void basicImportErrTest1() throws SourceException, FileNotFoundException, ReactorException,
66 StmtTestUtils.parseYinSources("/semantic-version/yin-input/basic-import-invalid", StatementParserMode.SEMVER_MODE);
67 fail("Test should fail due to invalid semantic version");
68 } catch (ReactorException e) {
69 assertTrue(e.getCause().getMessage()
70 .startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));