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
9 package org.opendaylight.yangtools.yang.parser.repo;
11 import static org.junit.Assert.assertEquals;
13 import java.util.HashMap;
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.model.repo.api.YangTextSchemaSource;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo.ModuleDependencyInfo;
23 public class DependencyResolverTest {
25 public void testModulesWithoutRevisionAndImport() throws Exception {
26 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
27 addToMap(map, "/no-revision/imported.yang");
28 addToMap(map, "/no-revision/imported@2012-12-12.yang");
29 addToMap(map, "/no-revision/top@2012-10-10.yang");
31 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
33 assertEquals(0, resolved.getUnresolvedSources().size());
34 assertEquals(0, resolved.getUnsatisfiedImports().size());
38 public void testSubmoduleNoModule() throws Exception {
39 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
40 // Subfoo does not have parent in reactor
41 addToMap(map, "/model/subfoo.yang");
42 addToMap(map, "/model/bar.yang");
43 addToMap(map, "/model/baz.yang");
45 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
47 assertEquals(2, resolved.getResolvedSources().size());
48 assertEquals(1, resolved.getUnresolvedSources().size());
49 assertEquals(0, resolved.getUnsatisfiedImports().size());
53 public void testSubmodule() throws Exception {
54 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
55 addToMap(map, "/model/subfoo.yang");
56 addToMap(map, "/model/foo.yang");
57 addToMap(map, "/model/bar.yang");
58 addToMap(map, "/model/baz.yang");
60 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
61 assertEquals(0, resolved.getUnresolvedSources().size());
62 assertEquals(0, resolved.getUnsatisfiedImports().size());
63 assertEquals(4, resolved.getResolvedSources().size());
66 private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map,
67 final String yangFileName) throws Exception {
68 final var info = ModuleDependencyInfo.forYangText(YangTextSchemaSource.forResource(DependencyResolverTest.class,
70 map.put(RevisionSourceIdentifier.create(info.getName(), info.getRevision()), info);