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.impl.util;
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.assertTrue;
17 import java.io.IOException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
22 public class YangModelDependencyInfoTest {
25 public void testModuleWithNoImports() throws IOException, YangSyntaxErrorException {
26 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
27 "/ietf/ietf-inet-types@2010-09-24.yang");
29 assertEquals("ietf-inet-types", info.getName());
30 assertEquals("2010-09-24", info.getFormattedRevision());
31 assertNotNull(info.getDependencies());
33 assertTrue(info.equals(info));
37 public void testModuleWithImports() throws IOException, YangSyntaxErrorException {
38 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
39 "/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 public void testModuleWithoutRevision() throws IOException, YangSyntaxErrorException {
49 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
50 "/no-revision/module-without-revision.yang");
52 assertEquals("module-without-revision", info.getName());
53 assertNull(info.getFormattedRevision());
57 public void testEquals() throws IOException, YangSyntaxErrorException {
58 YangModelDependencyInfo info1 = YangModelDependencyInfo.forResource(getClass(),
59 "/ietf/ietf-inet-types@2010-09-24.yang");
60 YangModelDependencyInfo info2 = YangModelDependencyInfo.forResource(getClass(),
61 "/no-revision/module-without-revision.yang");
63 assertTrue(info1.equals(info1));
64 assertFalse(info1.equals(null));
65 assertFalse(info1.equals(info2));
69 public void testYangtools827() throws IOException, YangSyntaxErrorException {
70 // Latest revision needs to be picked up irrespective of ordering
71 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
72 "/bugs/YT827/foo.yang");
73 assertEquals("2014-12-24", info.getFormattedRevision());
77 public void testHashcode() throws IOException, YangSyntaxErrorException {
78 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
79 "/no-revision/module-without-revision.yang");
80 assertNotEquals("hashcode", 31, info.hashCode());