2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.repo;
10 import static org.junit.Assert.assertEquals;
12 import java.util.HashMap;
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;
21 public class DependencyResolverTest {
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");
29 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
31 assertEquals(0, resolved.getUnresolvedSources().size());
32 assertEquals(0, resolved.getUnsatisfiedImports().size());
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");
43 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
45 assertEquals(2, resolved.getResolvedSources().size());
46 assertEquals(1, resolved.getUnresolvedSources().size());
47 assertEquals(0, resolved.getUnsatisfiedImports().size());
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");
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());
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,
68 map.put(new SourceIdentifier(info.getName(), info.getFormattedRevision()), info);