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.jupiter.api.Assertions.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.util.List;
19 import java.util.Optional;
20 import org.junit.jupiter.api.Test;
21 import org.junit.jupiter.api.extension.ExtendWith;
22 import org.mockito.junit.jupiter.MockitoExtension;
23 import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
24 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
25 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
27 @ExtendWith(MockitoExtension.class)
28 class FilenameResolutionTest extends AbstractCodeGeneratorTest {
30 void testResolveSubmoduleResource() throws Exception {
31 assertMojoExecution(new YangToSourcesProcessor(
32 new File(Resources.getResource(FilenameResolutionTest.class, "/filename").toURI()),
33 List.of(new FileGeneratorArg("mockGenerator")), project, yangProvider),
35 doAnswer(invocation -> {
36 final EffectiveModelContext context = invocation.getArgument(0);
37 final ModuleResourceResolver resolver = invocation.getArgument(2);
39 final var module = Iterables.getOnlyElement(context.getModules());
40 assertEquals(Optional.of("/META-INF/yang/foo@2020-10-13.yang"),
41 resolver.findModuleResourcePath(module, YangTextSource.class));
43 final var submodule = Iterables.getOnlyElement(module.getSubmodules());
44 assertEquals(Optional.of("/META-INF/yang/foo-submodule@2020-10-12.yang"),
45 resolver.findModuleResourcePath(submodule, YangTextSource.class));
47 return ImmutableTable.of();
48 }).when(mock).generateFiles(any(), any(), any());