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.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;
23 @RunWith(MockitoJUnitRunner.class)
24 public class YangToSourcesProcessorTest {
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);
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);
39 processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir, ImmutableList.of(), project, dep,
41 Assert.assertNotNull(processor);
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, YangProvider.getInstance());
58 Assert.assertNotNull(proc);