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;
21 public class YangModelDependencyInfoTest {
24 public void testModuleWithNoImports() throws IOException, YangSyntaxErrorException {
25 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
26 "/ietf/ietf-inet-types@2010-09-24.yang");
28 assertEquals("ietf-inet-types", info.getName());
29 assertEquals("2010-09-24", info.getFormattedRevision());
30 assertNotNull(info.getDependencies());
32 assertTrue(info.equals(info));
36 public void testModuleWithImports() throws IOException, YangSyntaxErrorException {
37 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
38 "/parse-methods/dependencies/m2@2013-09-30.yang");
40 assertEquals("m2", info.getName());
41 assertEquals("2013-09-30", info.getFormattedRevision());
42 assertNotNull(info.getDependencies());
43 assertEquals(2, info.getDependencies().size());
47 public void testModuleWithoutRevision() throws IOException, YangSyntaxErrorException {
48 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
49 "/no-revision/module-without-revision.yang");
51 assertEquals("module-without-revision", info.getName());
52 assertNull(info.getFormattedRevision());
56 public void testEquals() throws IOException, YangSyntaxErrorException {
57 YangModelDependencyInfo info1 = YangModelDependencyInfo.forResource(getClass(),
58 "/ietf/ietf-inet-types@2010-09-24.yang");
59 YangModelDependencyInfo info2 = YangModelDependencyInfo.forResource(getClass(),
60 "/no-revision/module-without-revision.yang");
62 assertTrue(info1.equals(info1));
63 assertFalse(info1.equals(null));
64 assertFalse(info1.equals(info2));
68 public void testYangtools827() throws IOException, YangSyntaxErrorException {
69 // Latest revision needs to be picked up irrespective of ordering
70 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
71 "/bugs/YT827/foo.yang");
72 assertEquals("2014-12-24", info.getFormattedRevision());
76 public void testHashcode() throws IOException, YangSyntaxErrorException {
77 YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
78 "/no-revision/module-without-revision.yang");
79 assertNotEquals("hashcode", 31, info.hashCode());