Do not require namespace repairing
[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 com.google.common.base.Optional;
14 import java.util.HashMap;
15 import java.util.Map;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
19
20 public class DependencyResolverTest {
21
22     @Test
23     public void testModulesWithoutRevisionAndImport() throws Exception {
24         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
25
26         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported.yang")));
27         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported@2012-12-12.yang")));
28         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/top@2012-10-10.yang")));
29
30         final DependencyResolver resolved = DependencyResolver.create(map);
31
32         assertEquals(0, resolved.getUnresolvedSources().size());
33         assertEquals(0, resolved.getUnsatisfiedImports().size());
34     }
35
36     @Test
37     public void testSubmoduleNoModule() throws Exception {
38         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
39
40         // Subfoo does not have parent in reactor
41         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang")));
42         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang")));
43         addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang")));
44
45         final DependencyResolver resolved = DependencyResolver.create(map);
46
47         assertEquals(1, resolved.getUnresolvedSources().size());
48         assertEquals(0, resolved.getUnsatisfiedImports().size());
49     }
50
51     private void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final YangModelDependencyInfo yangModelDependencyInfo) {
52         map.put(getSourceId(yangModelDependencyInfo), yangModelDependencyInfo);
53     }
54
55     private static SourceIdentifier getSourceId(final YangModelDependencyInfo depInfo) {
56         final String name = depInfo.getName();
57         return new SourceIdentifier(name, Optional.fromNullable(depInfo.getFormattedRevision()));
58     }
59 }