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.jupiter.api.Assertions.assertEquals;
12 import java.util.HashMap;
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;
21 public class DependencyResolverTest {
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");
29 final var resolved = RevisionDependencyResolver.create(map);
30 assertEquals(0, resolved.unresolvedSources().size());
31 assertEquals(0, resolved.unsatisfiedImports().size());
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");
42 final var resolved = RevisionDependencyResolver.create(map);
43 assertEquals(2, resolved.resolvedSources().size());
44 assertEquals(1, resolved.unresolvedSources().size());
45 assertEquals(0, resolved.unsatisfiedImports().size());
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");
56 final var resolved = RevisionDependencyResolver.create(map);
57 assertEquals(0, resolved.unresolvedSources().size());
58 assertEquals(0, resolved.unsatisfiedImports().size());
59 assertEquals(4, resolved.resolvedSources().size());
62 private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final String yangFileName)
64 final var info = ModuleDependencyInfo.forYangText(YangTextSource.forResource(DependencyResolverTest.class,
66 map.put(new SourceIdentifier(info.getName(), info.getFormattedRevision()), info);