de0e17ff4314cc8c7ed1e42e112a9d0f61f6dbe0
[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 import java.io.InputStream;
17 import org.junit.Test;
18
19 public class YangModelDependencyInfoTest {
20
21     @Test
22     public void testModuleWithNoImports() {
23         InputStream stream = getClass().getResourceAsStream("/ietf/ietf-inet-types@2010-09-24.yang");
24         YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
25         assertNotNull(info);
26         assertEquals("ietf-inet-types", info.getName());
27         assertEquals("2010-09-24", info.getFormattedRevision());
28         assertNotNull(info.getDependencies());
29
30         assertTrue(info.equals(info));
31     }
32
33     @Test
34     public void testModuleWithImports() {
35         InputStream stream = getClass().getResourceAsStream("/parse-methods/dependencies/m2@2013-09-30.yang");
36         YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
37         assertNotNull(info);
38         assertEquals("m2", info.getName());
39         assertEquals("2013-09-30", info.getFormattedRevision());
40         assertNotNull(info.getDependencies());
41         assertEquals(2, info.getDependencies().size());
42     }
43
44     @Test
45     public void testModuleWithoutRevision() {
46         InputStream stream = getClass().getResourceAsStream("/no-revision/module-without-revision.yang");
47         YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
48         assertNotNull(info);
49         assertEquals("module-without-revision", info.getName());
50         assertNull(info.getFormattedRevision());
51     }
52
53     @Test
54     public void testEquals() {
55         InputStream stream1 = getClass().getResourceAsStream("/ietf/ietf-inet-types@2010-09-24.yang");
56         YangModelDependencyInfo info1 = YangModelDependencyInfo.fromInputStream(stream1);
57         InputStream stream2 = getClass().getResourceAsStream("/no-revision/module-without-revision.yang");
58         YangModelDependencyInfo info2 = YangModelDependencyInfo.fromInputStream(stream2);
59
60         assertTrue(info1.equals(info1));
61         assertFalse(info1.equals(null));
62         assertFalse(info1.equals(stream1));
63         assertFalse(info1.equals(info2));
64     }
65
66     @Test
67     public void testHashcode() {
68         InputStream stream = getClass().getResourceAsStream("/no-revision/module-without-revision.yang");
69         YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
70
71         assertNotEquals("hashcode", 31, info.hashCode());
72     }
73 }