Promote SchemaSourceRepresentation
[yangtools.git] / parser / 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 package org.opendaylight.yangtools.yang.parser.repo;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11
12 import java.util.HashMap;
13 import java.util.Map;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
16 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo.ModuleDependencyInfo;
19
20 @Deprecated
21 public class DependencyResolverTest {
22     @Test
23     public void testModulesWithoutRevisionAndImport() throws Exception {
24         final var map = new HashMap<SourceIdentifier, YangModelDependencyInfo>();
25         addToMap(map, "/no-revision/imported.yang");
26         addToMap(map, "/no-revision/imported@2012-12-12.yang");
27         addToMap(map, "/no-revision/top@2012-10-10.yang");
28
29         final var resolved = RevisionDependencyResolver.create(map);
30         assertEquals(0, resolved.getUnresolvedSources().size());
31         assertEquals(0, resolved.getUnsatisfiedImports().size());
32     }
33
34     @Test
35     public void testSubmoduleNoModule() throws Exception {
36         final var map = new HashMap<SourceIdentifier, YangModelDependencyInfo>();
37         // Subfoo does not have parent in reactor
38         addToMap(map, "/model/subfoo.yang");
39         addToMap(map, "/model/bar.yang");
40         addToMap(map, "/model/baz.yang");
41
42         final var resolved = RevisionDependencyResolver.create(map);
43         assertEquals(2, resolved.getResolvedSources().size());
44         assertEquals(1, resolved.getUnresolvedSources().size());
45         assertEquals(0, resolved.getUnsatisfiedImports().size());
46     }
47
48     @Test
49     public void testSubmodule() throws Exception {
50         final var map = new HashMap<SourceIdentifier, YangModelDependencyInfo>();
51         addToMap(map, "/model/subfoo.yang");
52         addToMap(map, "/model/foo.yang");
53         addToMap(map, "/model/bar.yang");
54         addToMap(map, "/model/baz.yang");
55
56         final var resolved = RevisionDependencyResolver.create(map);
57         assertEquals(0, resolved.getUnresolvedSources().size());
58         assertEquals(0, resolved.getUnsatisfiedImports().size());
59         assertEquals(4, resolved.getResolvedSources().size());
60     }
61
62     private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final String yangFileName)
63             throws Exception {
64         final var info = ModuleDependencyInfo.forYangText(YangTextSource.forResource(DependencyResolverTest.class,
65             yangFileName));
66         map.put(new SourceIdentifier(info.getName(), info.getFormattedRevision()), info);
67     }
68 }