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.parser.rfc6020.repo.YangModelDependencyInfo;
21 public class DependencyResolverTest {
24 public void testModulesWithoutRevisionAndImport() throws Exception {
25 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
27 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(),
28 "/no-revision/imported.yang"));
29 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(),
30 "/no-revision/imported@2012-12-12.yang"));
31 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(),
32 "/no-revision/top@2012-10-10.yang"));
34 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
36 assertEquals(0, resolved.getUnresolvedSources().size());
37 assertEquals(0, resolved.getUnsatisfiedImports().size());
41 public void testSubmoduleNoModule() throws Exception {
42 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
44 // Subfoo does not have parent in reactor
45 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang"));
46 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang"));
47 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang"));
49 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
51 assertEquals(2, resolved.getResolvedSources().size());
52 assertEquals(1, resolved.getUnresolvedSources().size());
53 assertEquals(0, resolved.getUnsatisfiedImports().size());
57 public void testSubmodule() throws Exception {
58 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
60 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang"));
61 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/foo.yang"));
62 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang"));
63 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang"));
65 final DependencyResolver resolved = RevisionDependencyResolver.create(map);
66 assertEquals(0, resolved.getUnresolvedSources().size());
67 assertEquals(0, resolved.getUnsatisfiedImports().size());
68 assertEquals(4, resolved.getResolvedSources().size());
71 private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map,
72 final YangModelDependencyInfo yangModelDependencyInfo) {
73 map.put(getSourceId(yangModelDependencyInfo), yangModelDependencyInfo);
76 private static SourceIdentifier getSourceId(final YangModelDependencyInfo depInfo) {
77 final String name = depInfo.getName();
78 return RevisionSourceIdentifier.create(name, depInfo.getRevision());