Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / openconfigver / OpenconfigVersionDefaultsTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt.openconfigver;
9
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;
14
15 import java.net.URI;
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.concepts.SemVer;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24
25 public class OpenconfigVersionDefaultsTest {
26
27     @Test
28     public void defaultsTest() throws Exception {
29         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults",
30                 StatementParserMode.SEMVER_MODE);
31         assertNotNull(context);
32
33         Module foo = context.findModules(new URI("foo")).iterator().next();
34         Module bar = context.findModules(new URI("bar")).iterator().next();
35
36         assertEquals(Optional.empty(), foo.getSemanticVersion());
37         assertEquals(Optional.empty(), bar.getSemanticVersion());
38     }
39
40     @Test
41     public void defaultMajorValidTest() throws Exception {
42         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
43                 StatementParserMode.SEMVER_MODE);
44         assertNotNull(context);
45
46         Module foo = context.findModules(new URI("foo")).iterator().next();
47         Module bar = context.findModules(new URI("bar")).iterator().next();
48
49         assertEquals(Optional.empty(), foo.getSemanticVersion());
50         assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion().get());
51     }
52
53     @Test
54     public void defaultMajorInvalidTest() throws Exception {
55         try {
56             StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid",
57                 StatementParserMode.SEMVER_MODE);
58             fail("Test should fail due to invalid openconfig version");
59         } catch (ReactorException e) {
60             assertTrue(e.getCause().getCause().getMessage()
61                     .startsWith("Unable to find module compatible with requested import [bar(0.0.1)]."));
62         }
63     }
64 }