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 OpenconfigVersionBorderCaseTest {
27 public void borderCaseValidMajorTest() throws Exception {
28 SchemaContext context = StmtTestUtils.parseYangSources(
29 "/openconfig-version/border-case/border-case-valid-major", StatementParserMode.SEMVER_MODE);
30 assertNotNull(context);
32 Module foo = context.findModules(URI.create("foo")).iterator().next();
33 Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next();
35 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
36 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
37 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
38 assertEquals(SemVer.valueOf("5.5.5"), bar.getSemanticVersion().get());
42 public void borderCaseValidMinorTest() throws Exception {
43 SchemaContext context = StmtTestUtils.parseYangSources(
44 "/openconfig-version/border-case/border-case-valid-minor", StatementParserMode.SEMVER_MODE);
45 assertNotNull(context);
47 Module foo = context.findModules(URI.create("foo")).iterator().next();
48 Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next();
50 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
51 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
52 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
53 assertEquals(SemVer.valueOf("5.6.5"), bar.getSemanticVersion().get());
57 public void borderCaseValidPatchTest() throws Exception {
58 SchemaContext context = StmtTestUtils.parseYangSources(
59 "/openconfig-version/border-case/border-case-valid-patch", StatementParserMode.SEMVER_MODE);
60 assertNotNull(context);
62 Module foo = context.findModules(URI.create("foo")).iterator().next();
63 Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next();
65 assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
66 assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
67 Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
68 assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion().get());
72 public void borderCaseInvalidMajorTest() throws Exception {
74 StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-major",
75 StatementParserMode.SEMVER_MODE);
76 fail("Test should fail due to invalid openconfig version");
77 } catch (ReactorException e) {
78 assertTrue(e.getCause().getCause().getMessage()
79 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
84 public void borderCaseInvalidMinorTest() throws Exception {
86 StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-minor",
87 StatementParserMode.SEMVER_MODE);
88 fail("Test should fail due to invalid openconfig version");
89 } catch (ReactorException e) {
90 assertTrue(e.getCause().getCause().getMessage()
91 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
96 public void borderCaseInvalidPatchTest() throws Exception {
98 StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-patch",
99 StatementParserMode.SEMVER_MODE);
100 fail("Test should fail due to invalid openconfig version");
101 } catch (ReactorException e) {
102 assertTrue(e.getCause().getCause().getMessage()
103 .startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));