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;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.apache.maven.model.Build;
14 import org.apache.maven.model.Plugin;
15 import org.apache.maven.project.MavenProject;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
23 import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock;
24 import org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesProcessor.YangProvider;
26 @RunWith(MockitoJUnitRunner.class)
27 public class YangToSourcesMojoTest {
29 private YangToSourcesMojo mojo;
32 private MavenProject project;
35 private Plugin plugin;
37 private YangToSourcesProcessor proc;
40 public void yangToSourceMojoTest() throws Exception{
41 Mockito.when(this.project.getPlugin(YangToSourcesMojo.PLUGIN_NAME)).thenReturn(this.plugin);
43 this.mojo = new YangToSourcesMojo();
44 this.mojo.setProject(this.project);
46 Assert.assertNotNull(this.mojo);
48 final YangToSourcesProcessor processor = Mockito.mock(YangToSourcesProcessor.class);
49 this.mojo = new YangToSourcesMojo(processor);
50 this.mojo.setProject(this.project);
52 Mockito.verify(processor).conditionalExecute(false);
56 public void test() throws Exception {
58 Assert.assertNotNull(this.proc);
59 this.mojo = new YangToSourcesMojo(this.proc);
60 this.mojo.setProject(this.project);
62 Assert.assertNotNull(this.mojo);
65 private void prepareProcessor() {
66 final File file = new File(getClass().getResource("/yang").getFile());
67 final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
68 final String path = file.getPath();
69 final File[] yangFilesRootDir = { excludedYang };
70 final List<CodeGeneratorArg> codeGenerators = new ArrayList<>();
71 final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(), path);
72 codeGenerators.add(codeGeneratorArg);
73 final MavenProject mvnProject = Mockito.mock(MavenProject.class);
74 final Build build = new Build();
75 Mockito.when(mvnProject.getBuild()).thenReturn(build);
76 final boolean dependencies = true;
77 this.proc = new YangToSourcesProcessor(file, yangFilesRootDir, codeGenerators,
78 mvnProject, dependencies, new YangProvider());