Enforce checkstyle in maven-plugin
[yangtools.git] / yang / yang-maven-plugin / src / test / java / org / opendaylight / yangtools / yang2sources / plugin / YangToSourcesProcessorTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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 com.google.common.collect.ImmutableList;
11 import java.io.File;
12 import java.util.List;
13 import org.apache.maven.model.Build;
14 import org.apache.maven.project.MavenProject;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
21 import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock;
22
23 @RunWith(MockitoJUnitRunner.class)
24 public class YangToSourcesProcessorTest {
25
26     private final File buildContext = Mockito.mock(File.class);
27     private final List<File> yangFilesRootDir = ImmutableList.of(buildContext);
28     private final MavenProject project = Mockito.mock(MavenProject.class);
29     private final boolean dep = false;
30     private final YangProvider inspectDependencies = Mockito.mock(YangProvider.class);
31
32     @Test
33     public void yangToSourcesProcessotTest() {
34         Mockito.when(this.buildContext.getPath()).thenReturn("path");
35         YangToSourcesProcessor processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir,
36             ImmutableList.of(), project, dep, inspectDependencies);
37         Assert.assertNotNull(processor);
38
39         processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir, ImmutableList.of(), project, dep,
40             inspectDependencies);
41         Assert.assertNotNull(processor);
42     }
43
44     @Test
45     public void test() throws Exception {
46         final File file = new File(getClass().getResource("/yang").getFile());
47         final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
48         final String path = file.getPath();
49         final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(),
50                 "target/YangToSourcesProcessorTest-outputBaseDir");
51         final List<CodeGeneratorArg> codeGenerators = ImmutableList.of(codeGeneratorArg);
52         final MavenProject mvnProject = Mockito.mock(MavenProject.class);
53         final Build build = new Build();
54         Mockito.when(mvnProject.getBuild()).thenReturn(build);
55         final boolean dependencies = true;
56         final YangToSourcesProcessor proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang),
57             codeGenerators, mvnProject, dependencies, new YangProvider());
58         Assert.assertNotNull(proc);
59         proc.execute();
60     }
61
62 }