Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / rfc7950 / repo / YangModelDependencyInfoTest.java
1 /*
2  * Copyright (c) 2014 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.parser.rfc7950.repo;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertThrows;
16 import static org.junit.Assert.assertTrue;
17
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
20
21 public class YangModelDependencyInfoTest {
22     // Utility
23     private static YangModelDependencyInfo forResource(final String resourceName) {
24         final YangStatementStreamSource source = StmtTestUtils.sourceForResource(resourceName);
25         return YangModelDependencyInfo.forIR(source.rootStatement(), source.getIdentifier());
26     }
27
28     @Test
29     public void testModuleWithNoImports() {
30         YangModelDependencyInfo info = forResource("/ietf/ietf-inet-types@2010-09-24.yang");
31         assertNotNull(info);
32         assertEquals("ietf-inet-types", info.getName());
33         assertEquals("2010-09-24", info.getFormattedRevision());
34         assertNotNull(info.getDependencies());
35
36         assertTrue(info.equals(info));
37     }
38
39     @Test
40     public void testModuleWithImports() {
41         YangModelDependencyInfo info = forResource("/parse-methods/dependencies/m2@2013-09-30.yang");
42         assertNotNull(info);
43         assertEquals("m2", info.getName());
44         assertEquals("2013-09-30", info.getFormattedRevision());
45         assertNotNull(info.getDependencies());
46         assertEquals(2, info.getDependencies().size());
47     }
48
49     @Test
50     public void testModuleWithoutRevision() {
51         YangModelDependencyInfo info = forResource("/no-revision/module-without-revision.yang");
52         assertNotNull(info);
53         assertEquals("module-without-revision", info.getName());
54         assertNull(info.getFormattedRevision());
55     }
56
57     @Test
58     public void testEquals() {
59         YangModelDependencyInfo info1 = forResource("/ietf/ietf-inet-types@2010-09-24.yang");
60         YangModelDependencyInfo info2 = forResource("/no-revision/module-without-revision.yang");
61
62         assertTrue(info1.equals(info1));
63         assertFalse(info1.equals(null));
64         assertFalse(info1.equals(info2));
65     }
66
67     @Test
68     public void testYangtools827() {
69         // Latest revision needs to be picked up irrespective of ordering
70         YangModelDependencyInfo info = forResource("/bugs/YT827/foo.yang");
71         assertEquals("2014-12-24", info.getFormattedRevision());
72     }
73
74     @Test
75     public void testHashcode() {
76         YangModelDependencyInfo info = forResource("/no-revision/module-without-revision.yang");
77         assertNotEquals("hashcode", 31, info.hashCode());
78     }
79
80     @Test
81     public void testMalformedImport() {
82         assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-import.yang"));
83     }
84
85     @Test
86     public void testMalformedImportRev() {
87         assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-import-rev.yang"));
88     }
89
90     @Test
91     public void testMalformedModule() {
92         assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-module.yang"));
93     }
94
95     @Test
96     public void testMalformedRev() {
97         assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-rev.yang"));
98     }
99 }