250014dad628be186b5e6600cf36ee99ff030627
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / util / 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.impl.util;
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.assertTrue;
16
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;
21
22 public class YangModelDependencyInfoTest {
23
24     @Test
25     public void testModuleWithNoImports() throws IOException, YangSyntaxErrorException {
26         YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
27             "/ietf/ietf-inet-types@2010-09-24.yang");
28         assertNotNull(info);
29         assertEquals("ietf-inet-types", info.getName());
30         assertEquals("2010-09-24", info.getFormattedRevision());
31         assertNotNull(info.getDependencies());
32
33         assertTrue(info.equals(info));
34     }
35
36     @Test
37     public void testModuleWithImports() throws IOException, YangSyntaxErrorException {
38         YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
39                 "/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     public void testModuleWithoutRevision() throws IOException, YangSyntaxErrorException {
49         YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
50                 "/no-revision/module-without-revision.yang");
51         assertNotNull(info);
52         assertEquals("module-without-revision", info.getName());
53         assertNull(info.getFormattedRevision());
54     }
55
56     @Test
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");
62
63         assertTrue(info1.equals(info1));
64         assertFalse(info1.equals(null));
65         assertFalse(info1.equals(info2));
66     }
67
68     @Test
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());
74     }
75
76     @Test
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());
81     }
82 }