Remove RevisionSourceIdentifier
[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.Assert.assertEquals;
11
12 import java.util.HashMap;
13 import java.util.Map;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
16 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
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 Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
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 DependencyResolver resolved = RevisionDependencyResolver.create(map);
30
31         assertEquals(0, resolved.getUnresolvedSources().size());
32         assertEquals(0, resolved.getUnsatisfiedImports().size());
33     }
34
35     @Test
36     public void testSubmoduleNoModule() throws Exception {
37         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
38         // Subfoo does not have parent in reactor
39         addToMap(map, "/model/subfoo.yang");
40         addToMap(map, "/model/bar.yang");
41         addToMap(map, "/model/baz.yang");
42
43         final DependencyResolver resolved = RevisionDependencyResolver.create(map);
44
45         assertEquals(2, resolved.getResolvedSources().size());
46         assertEquals(1, resolved.getUnresolvedSources().size());
47         assertEquals(0, resolved.getUnsatisfiedImports().size());
48     }
49
50     @Test
51     public void testSubmodule() throws Exception {
52         final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
53         addToMap(map, "/model/subfoo.yang");
54         addToMap(map, "/model/foo.yang");
55         addToMap(map, "/model/bar.yang");
56         addToMap(map, "/model/baz.yang");
57
58         final DependencyResolver resolved = RevisionDependencyResolver.create(map);
59         assertEquals(0, resolved.getUnresolvedSources().size());
60         assertEquals(0, resolved.getUnsatisfiedImports().size());
61         assertEquals(4, resolved.getResolvedSources().size());
62     }
63
64     private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map,
65             final String yangFileName) throws Exception {
66         final var info = ModuleDependencyInfo.forYangText(YangTextSchemaSource.forResource(DependencyResolverTest.class,
67             yangFileName));
68         map.put(new SourceIdentifier(info.getName(), info.getFormattedRevision()), info);
69     }
70 }