Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / repo / DependencyResolverTest.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
9 package org.opendaylight.yangtools.yang.parser.repo;
10
11 import static org.junit.Assert.assertEquals;
12
13 import java.util.HashMap;
14 import java.util.Map;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
19
20 @Deprecated
21 public class DependencyResolverTest {
22
23     @Test
24     public void testModulesWithoutRevisionAndImport() throws Exception {
25         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
26
27         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(),
28             "/no-revision/imported.yang"));
29         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(),
30             "/no-revision/imported@2012-12-12.yang"));
31         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(),
32             "/no-revision/top@2012-10-10.yang"));
33
34         final DependencyResolver resolved = RevisionDependencyResolver.create(map);
35
36         assertEquals(0, resolved.getUnresolvedSources().size());
37         assertEquals(0, resolved.getUnsatisfiedImports().size());
38     }
39
40     @Test
41     public void testSubmoduleNoModule() throws Exception {
42         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
43
44         // Subfoo does not have parent in reactor
45         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang"));
46         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang"));
47         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang"));
48
49         final DependencyResolver resolved = RevisionDependencyResolver.create(map);
50
51         assertEquals(2, resolved.getResolvedSources().size());
52         assertEquals(1, resolved.getUnresolvedSources().size());
53         assertEquals(0, resolved.getUnsatisfiedImports().size());
54     }
55
56     @Test
57     public void testSubmodule() throws Exception {
58         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
59
60         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang"));
61         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/foo.yang"));
62         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang"));
63         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang"));
64
65         final DependencyResolver resolved = RevisionDependencyResolver.create(map);
66         assertEquals(0, resolved.getUnresolvedSources().size());
67         assertEquals(0, resolved.getUnsatisfiedImports().size());
68         assertEquals(4, resolved.getResolvedSources().size());
69     }
70
71     private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map,
72             final YangModelDependencyInfo yangModelDependencyInfo) {
73         map.put(getSourceId(yangModelDependencyInfo), yangModelDependencyInfo);
74     }
75
76     private static SourceIdentifier getSourceId(final YangModelDependencyInfo depInfo) {
77         final String name = depInfo.getName();
78         return RevisionSourceIdentifier.create(name, depInfo.getRevision());
79     }
80 }