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.openconfigver.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.IOException;
17 import java.net.URISyntaxException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.concepts.SemVer;
20 import org.opendaylight.yangtools.yang.common.XMLNamespace;
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.stmt.StmtTestUtils;
26 import org.xml.sax.SAXException;
28 public class YinOpenconfigVersionTest {
30 public void basicTest() throws URISyntaxException, SAXException, IOException, ReactorException {
31 SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic",
32 StatementParserMode.SEMVER_MODE);
33 assertNotNull(context);
35 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
36 Module bar = context.findModules(XMLNamespace.of("bar")).iterator().next();
37 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
40 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
41 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
42 assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion().get());
46 public void basicImportTest1() throws URISyntaxException, SAXException, IOException, ReactorException {
47 SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import",
48 StatementParserMode.SEMVER_MODE);
49 assertNotNull(context);
51 Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
52 Module semVer = context.findModules(XMLNamespace.of("http://openconfig.net/yang/openconfig-ext"))
55 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
56 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
57 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
58 assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion().get());
62 public void basicImportErrTest1() throws URISyntaxException, SAXException, IOException {
64 StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid",
65 StatementParserMode.SEMVER_MODE);
66 fail("Test should fail due to invalid openconfig version");
67 } catch (ReactorException e) {
68 assertTrue(e.getCause().getCause().getMessage()
69 .startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));