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