23b6f01ee518e84c8ff2a1edd48b7e34aa9fdfc4
[yangtools.git] / plugin / 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 static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.doReturn;
12
13 import com.google.common.collect.ImmutableList;
14 import java.io.File;
15 import java.util.List;
16 import org.apache.maven.model.Build;
17 import org.apache.maven.project.MavenProject;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
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
26 @RunWith(MockitoJUnitRunner.StrictStubs.class)
27 public class YangToSourcesProcessorTest {
28     @Mock
29     public File buildContext;
30     @Mock
31     public MavenProject project;
32     @Mock
33     public YangProvider inspectDependencies;
34
35     private final boolean dep = false;
36     private List<File> yangFilesRootDir;
37
38     @Before
39     public void before() {
40         yangFilesRootDir = ImmutableList.of(buildContext);
41     }
42
43     @Test
44     public void yangToSourcesProcessotTest() {
45         YangToSourcesProcessor processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir,
46             ImmutableList.of(), project, dep, inspectDependencies);
47         assertNotNull(processor);
48
49         processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir, ImmutableList.of(), project, dep,
50             inspectDependencies);
51         assertNotNull(processor);
52     }
53
54     @Test
55     public void test() throws Exception {
56         final File file = new File(getClass().getResource("/yang").getFile());
57         final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
58         final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(),
59                 "target/YangToSourcesProcessorTest-outputBaseDir");
60         final List<CodeGeneratorArg> codeGenerators = ImmutableList.of(codeGeneratorArg);
61         final Build build = new Build();
62         build.setDirectory("foo");
63         doReturn(build).when(project).getBuild();
64         final boolean dependencies = true;
65         final YangToSourcesProcessor proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang),
66             codeGenerators, project, dependencies, YangProvider.getInstance());
67         assertNotNull(proc);
68         proc.execute();
69     }
70 }