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 com.google.common.collect.ImmutableList;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.apache.maven.model.Build;
15 import org.apache.maven.model.Plugin;
16 import org.apache.maven.project.MavenProject;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
24 import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock;
25 import org.sonatype.plexus.build.incremental.DefaultBuildContext;
27 @RunWith(MockitoJUnitRunner.class)
28 public class YangToSourcesMojoTest {
30 private YangToSourcesMojo mojo;
33 private MavenProject project;
36 private Plugin plugin;
38 private YangToSourcesProcessor proc;
41 public void yangToSourceMojoTest() throws Exception {
42 Mockito.when(this.project.getPlugin(YangToSourcesMojo.PLUGIN_NAME)).thenReturn(this.plugin);
44 this.mojo = new YangToSourcesMojo();
45 this.mojo.setProject(this.project);
46 this.mojo.buildContext = new DefaultBuildContext();
48 Assert.assertNotNull(this.mojo);
50 final YangToSourcesProcessor processor = Mockito.mock(YangToSourcesProcessor.class);
51 this.mojo = new YangToSourcesMojo(processor);
52 this.mojo.setProject(this.project);
54 Mockito.verify(processor).conditionalExecute(false);
58 public void test() throws Exception {
60 Assert.assertNotNull(this.proc);
61 this.mojo = new YangToSourcesMojo(this.proc);
62 this.mojo.setProject(this.project);
64 Assert.assertNotNull(this.mojo);
67 private void prepareProcessor() {
68 final File file = new File(getClass().getResource("/yang").getFile());
69 final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
70 final String path = file.getPath();
71 final List<CodeGeneratorArg> codeGenerators = new ArrayList<>();
72 final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(),
73 "target/YangToSourcesMojoTest-outputBaseDir");
74 codeGenerators.add(codeGeneratorArg);
75 final MavenProject mvnProject = Mockito.mock(MavenProject.class);
76 final Build build = new Build();
77 Mockito.when(mvnProject.getBuild()).thenReturn(build);
78 final boolean dependencies = true;
79 this.proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang), codeGenerators,
80 mvnProject, dependencies, YangProvider.getInstance());