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;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doAnswer;
14 import com.google.common.collect.ImmutableTable;
15 import com.google.common.collect.Iterables;
16 import com.google.common.io.Resources;
18 import java.io.IOException;
19 import java.net.URISyntaxException;
20 import java.util.List;
21 import java.util.Optional;
22 import org.apache.maven.plugin.AbstractMojoExecutionException;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
27 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
28 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class FilenameResolutionTest extends AbstractCodeGeneratorTest {
33 public void testResolveSubmoduleResource() throws URISyntaxException, AbstractMojoExecutionException, IOException {
34 assertMojoExecution(new YangToSourcesProcessor(
35 new File(Resources.getResource(FilenameResolutionTest.class, "/filename").toURI()), List.of(),
36 List.of(new FileGeneratorArg("mockGenerator")), project, false, yangProvider), mock -> {
37 doAnswer(invocation -> {
38 final EffectiveModelContext context = invocation.getArgument(0);
39 final ModuleResourceResolver resolver = invocation.getArgument(2);
41 final var module = Iterables.getOnlyElement(context.getModules());
42 assertEquals(Optional.of("/META-INF/yang/foo@2020-10-13.yang"),
43 resolver.findModuleResourcePath(module, YangTextSchemaSource.class));
45 final var submodule = Iterables.getOnlyElement(module.getSubmodules());
46 assertEquals(Optional.of("/META-INF/yang/foo-submodule@2020-10-12.yang"),
47 resolver.findModuleResourcePath(submodule, YangTextSchemaSource.class));
49 return ImmutableTable.of();
50 }).when(mock).generateFiles(any(), any(), any());