2 * Copyright (c) 2016 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
8 package org.opendaylight.yangtools.yang2sources.plugin;
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.verify;
14 import com.google.common.collect.ImmutableList;
16 import java.util.ArrayList;
17 import java.util.List;
18 import org.apache.maven.model.Build;
19 import org.apache.maven.model.Plugin;
20 import org.apache.maven.project.MavenProject;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mock;
24 import org.mockito.Mockito;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
27 import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock;
28 import org.sonatype.plexus.build.incremental.DefaultBuildContext;
30 @RunWith(MockitoJUnitRunner.class)
31 public class YangToSourcesMojoTest {
33 private YangToSourcesMojo mojo;
36 private MavenProject project;
39 private Plugin plugin;
41 private YangToSourcesProcessor proc;
44 public void yangToSourceMojoTest() throws Exception {
45 doReturn(plugin).when(project).getPlugin(YangToSourcesMojo.PLUGIN_NAME);
47 this.mojo = new YangToSourcesMojo();
48 this.mojo.setProject(project);
49 this.mojo.buildContext = new DefaultBuildContext();
51 assertNotNull(this.mojo);
53 final YangToSourcesProcessor processor = Mockito.mock(YangToSourcesProcessor.class);
54 this.mojo = new YangToSourcesMojo(processor);
55 this.mojo.setProject(project);
57 verify(processor).conditionalExecute(false);
61 public void test() throws Exception {
64 this.mojo = new YangToSourcesMojo(proc);
65 this.mojo.setProject(project);
70 private void prepareProcessor() {
71 final File file = new File(getClass().getResource("/yang").getFile());
72 final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
73 final String path = file.getPath();
74 final List<CodeGeneratorArg> codeGenerators = new ArrayList<>();
75 final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(),
76 "target/YangToSourcesMojoTest-outputBaseDir");
77 codeGenerators.add(codeGeneratorArg);
78 final Build build = new Build();
79 build.setDirectory("testDir");
80 doReturn(build).when(project).getBuild();
81 final boolean dependencies = true;
82 this.proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang), codeGenerators,
83 project, dependencies, YangProvider.getInstance());