Replace LOGGER/logger/log by LOG
[yangtools.git] / yang / yang-parser-impl / 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 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;
23
24 public class OpenconfigVersionDefaultsTest {
25
26     @Test
27     public void defaultsTest() throws Exception {
28         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults",
29                 StatementParserMode.OPENCONFIG_VER_MODE);
30         assertNotNull(context);
31
32         Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
33         Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
34
35         assertEquals(SemVer.valueOf("0.0.0"), foo.getOpenconfigVersion());
36         assertEquals(SemVer.valueOf("0.0.0"), bar.getOpenconfigVersion());
37     }
38
39     @Test
40     public void defaultMajorValidTest() throws Exception {
41         SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
42                 StatementParserMode.OPENCONFIG_VER_MODE);
43         assertNotNull(context);
44
45         Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
46         Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
47
48         assertEquals(SemVer.valueOf("0.0.0"), foo.getOpenconfigVersion());
49         assertEquals(SemVer.valueOf("0.99.99"), bar.getOpenconfigVersion());
50     }
51
52     @Test
53     public void defaultMajorInvalidTest() throws Exception {
54         try {
55             StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid",
56                 StatementParserMode.OPENCONFIG_VER_MODE);
57             fail("Test should fail due to invalid openconfig version");
58         } catch (ReactorException e) {
59             assertTrue(e.getCause().getMessage()
60                     .startsWith("Unable to find module compatible with requested import [bar(0.0.0)]."));
61         }
62     }
63 }