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 com.google.common.base.Optional;
14 import java.util.HashMap;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
20 public class DependencyResolverTest {
23 public void testModulesWithoutRevisionAndImport() throws Exception {
24 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
26 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported.yang")));
27 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported@2012-12-12.yang")));
28 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/top@2012-10-10.yang")));
30 final DependencyResolver resolved = DependencyResolver.create(map);
32 assertEquals(0, resolved.getUnresolvedSources().size());
33 assertEquals(0, resolved.getUnsatisfiedImports().size());
37 public void testSubmoduleNoModule() throws Exception {
38 final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
40 // Subfoo does not have parent in reactor
41 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang")));
42 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang")));
43 addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang")));
45 final DependencyResolver resolved = DependencyResolver.create(map);
47 assertEquals(1, resolved.getUnresolvedSources().size());
48 assertEquals(0, resolved.getUnsatisfiedImports().size());
51 private void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final YangModelDependencyInfo yangModelDependencyInfo) {
52 map.put(getSourceId(yangModelDependencyInfo), yangModelDependencyInfo);
55 private static SourceIdentifier getSourceId(final YangModelDependencyInfo depInfo) {
56 final String name = depInfo.getName();
57 return new SourceIdentifier(name, Optional.fromNullable(depInfo.getFormattedRevision()));