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;
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 OpenconfigVersionImportTest {
27 public void importValidTest() throws Exception {
28 SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/import/import-valid",
29 StatementParserMode.SEMVER_MODE);
30 assertNotNull(context);
32 Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
34 assertEquals(SemVer.valueOf("1.0.0"), semVer.getSemanticVersion().get());
38 public void importInvalidDeprecatedTest1() throws Exception {
40 StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-1",
41 StatementParserMode.SEMVER_MODE);
42 fail("Test should fail due to invalid import of openconfig-version module");
43 } catch (ReactorException e) {
44 assertTrue(e.getCause().getCause().getMessage().startsWith(
45 "Unable to find module compatible with requested import [openconfig-extensions(1.0.0)]."));
50 public void importInvalidDeprecatedTest2() throws Exception {
52 StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-2",
53 StatementParserMode.SEMVER_MODE);
54 fail("Test should fail due to invalid import of openconfig-version module");
55 } catch (ReactorException e) {
56 assertTrue(e.getCause().getCause().getMessage().startsWith(
57 "Unable to find module compatible with requested import [openconfig-extensions(0.9.9)]."));
62 public void importInvalidNotsufficientTest1() throws Exception {
64 StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-1",
65 StatementParserMode.SEMVER_MODE);
66 fail("Test should fail due to invalid import of openconfig-version module");
67 } catch (ReactorException e) {
68 assertTrue(e.getCause().getCause().getMessage().startsWith(
69 "Unable to find module compatible with requested import [openconfig-extensions(2.0.0)]."));
74 public void importInvalidNotsufficientTest2() throws Exception {
76 StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-2",
77 StatementParserMode.SEMVER_MODE);
78 fail("Test should fail due to invalid import of openconfig-version module");
79 } catch (ReactorException e) {
80 assertTrue(e.getCause().getCause().getMessage().startsWith(
81 "Unable to find module compatible with requested import [openconfig-extensions(2.0.5)]."));