Promote SchemaSourceRepresentation
[yangtools.git] / plugin / yang-maven-plugin / src / test / java / org / opendaylight / yangtools / yang2sources / plugin / FilenameResolutionTest.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang2sources.plugin;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doAnswer;
13
14 import com.google.common.collect.ImmutableTable;
15 import com.google.common.collect.Iterables;
16 import com.google.common.io.Resources;
17 import java.io.File;
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;
26
27 @ExtendWith(MockitoExtension.class)
28 class FilenameResolutionTest extends AbstractCodeGeneratorTest {
29     @Test
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),
34             mock -> {
35                 doAnswer(invocation -> {
36                     final EffectiveModelContext context = invocation.getArgument(0);
37                     final ModuleResourceResolver resolver = invocation.getArgument(2);
38
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));
42
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));
46
47                     return ImmutableTable.of();
48                 }).when(mock).generateFiles(any(), any(), any());
49             }, mock -> {
50                 // No-op
51             });
52     }
53 }