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 static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.doReturn;
13 import com.google.common.collect.ImmutableList;
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;
26 @RunWith(MockitoJUnitRunner.StrictStubs.class)
27 public class YangToSourcesProcessorTest {
29 public File buildContext;
31 public MavenProject project;
33 public YangProvider inspectDependencies;
35 private final boolean dep = false;
36 private List<File> yangFilesRootDir;
39 public void before() {
40 yangFilesRootDir = ImmutableList.of(buildContext);
44 public void yangToSourcesProcessotTest() {
45 YangToSourcesProcessor processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir,
46 ImmutableList.of(), project, dep, inspectDependencies);
47 assertNotNull(processor);
49 processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir, ImmutableList.of(), project, dep,
51 assertNotNull(processor);
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());