2 * Copyright (c) 2014 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.parser.rfc7950.repo;
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;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
19 class YangModelDependencyInfoTest {
21 private static YangModelDependencyInfo forResource(final String resourceName) {
22 final var source = StmtTestUtils.sourceForResource(resourceName);
23 return YangModelDependencyInfo.forIR(source.rootStatement(), source.getIdentifier());
27 void testModuleWithNoImports() {
28 final var info = forResource("/ietf/ietf-inet-types@2010-09-24.yang");
30 assertEquals("ietf-inet-types", info.getName());
31 assertEquals("2010-09-24", info.getFormattedRevision());
32 assertNotNull(info.getDependencies());
34 assertEquals(info, info);
38 void testModuleWithImports() {
39 final var info = forResource("/parse-methods/dependencies/m2@2013-09-30.yang");
41 assertEquals("m2", info.getName());
42 assertEquals("2013-09-30", info.getFormattedRevision());
43 assertNotNull(info.getDependencies());
44 assertEquals(2, info.getDependencies().size());
48 void testModuleWithoutRevision() {
49 final var info = forResource("/no-revision/module-without-revision.yang");
51 assertEquals("module-without-revision", info.getName());
52 assertNull(info.getFormattedRevision());
57 final var info1 = forResource("/ietf/ietf-inet-types@2010-09-24.yang");
58 final var info2 = forResource("/no-revision/module-without-revision.yang");
60 assertEquals(info1, info1);
61 assertNotEquals(null, info1);
62 assertNotEquals(info1, info2);
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());
74 final var info = forResource("/no-revision/module-without-revision.yang");
75 assertNotEquals(31, info.hashCode(), "hashcode");
79 void testMalformedImport() {
80 assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-import.yang"));
84 void testMalformedImportRev() {
85 assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-import-rev.yang"));
89 void testMalformedModule() {
90 assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-module.yang"));
94 void testMalformedRev() {
95 assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-rev.yang"));