2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.yang2sources.plugin;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.Iterables;
14 import com.google.common.io.Resources;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.util.Collection;
19 import java.util.List;
21 import java.util.Optional;
23 import org.apache.maven.plugin.AbstractMojoExecutionException;
24 import org.junit.Test;
25 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
28 import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
29 import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
30 import org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver;
32 public class FilenameResolutionTest extends AbstractCodeGeneratorTest {
34 public void testResolveSubmoduleResource() throws URISyntaxException, AbstractMojoExecutionException, IOException {
35 setupMojo(new YangToSourcesProcessor(
36 new File(Resources.getResource(FilenameResolutionTest.class, "/filename").toURI()), ImmutableList.of(),
37 List.of(new CodeGeneratorArg(Generator.class.getName(), "outputDir")), project, false, yangProvider))
41 public static final class Generator implements BasicCodeGenerator {
43 public Collection<File> generateSources(final EffectiveModelContext context, final File outputBaseDir,
44 final Set<Module> currentModules, final ModuleResourceResolver moduleResourcePathResolver) {
45 final var module = Iterables.getOnlyElement(context.getModules());
46 assertEquals(Optional.of("/META-INF/yang/foo@2020-10-13.yang"),
47 moduleResourcePathResolver.findModuleResourcePath(module, YangTextSchemaSource.class));
49 final var submodule = Iterables.getOnlyElement(module.getSubmodules());
50 assertEquals(Optional.of("/META-INF/yang/foo-submodule@2020-10-12.yang"),
51 moduleResourcePathResolver.findModuleResourcePath(submodule, YangTextSchemaSource.class));
56 public void setAdditionalConfig(final Map<String, String> additionalConfiguration) {
61 public void setResourceBaseDir(final File resourceBaseDir) {