2 * Copyright (c) 2013 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.controller.yang2sources.plugin;
10 import static org.hamcrest.core.Is.is;
11 import static org.junit.Assert.assertThat;
12 import static org.mockito.Matchers.anyListOf;
13 import static org.mockito.Mockito.*;
16 import java.util.Collection;
19 import org.junit.Before;
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.opendaylight.controller.yang.model.api.SchemaContext;
25 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
26 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
27 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
28 import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
29 import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
31 import com.google.common.collect.Lists;
34 public class GenerateSourcesTest {
37 private YangModelParser parser;
39 private YangToSourcesMojo mojo;
44 MockitoAnnotations.initMocks(this);
46 yang = new File(getClass().getResource("/mock.yang").getFile())
48 outDir = new File("outputDir");
49 mojo = new YangToSourcesMojo(
50 new ResourceProviderArg[] {
51 new ResourceProviderArg(ProviderMock.class.getName(),
53 new ResourceProviderArg(ProviderMock2.class.getName(),
55 new CodeGeneratorArg[] { new CodeGeneratorArg(
56 GeneratorMock.class.getName(), outDir) }, parser, yang);
60 public void test() throws Exception {
62 verify(parser, times(1)).parseYangModels(anyListOf(File.class));
63 assertThat(GeneratorMock.called, is(1));
64 assertThat(GeneratorMock.outputDir, is(outDir));
68 public void testRes() throws Exception {
70 assertThat(ProviderMock.called, is(1));
71 assertThat(ProviderMock2.called, is(1));
72 assertThat(ProviderMock2.baseDir, is(outDir));
73 assertThat(ProviderMock.baseDir, is(outDir));
76 public static class GeneratorMock implements CodeGenerator {
78 private static int called = 0;
79 private static File outputDir;
82 public Collection<File> generateSources(SchemaContext context,
83 File baseDir, Set<String> yangModulesNames) {
86 return Lists.newArrayList();
90 public static class ProviderMock implements ResourceGenerator {
92 private static int called = 0;
93 private static File baseDir;
96 public void generateResourceFiles(Collection<File> resources,
103 public static class ProviderMock2 implements ResourceGenerator {
105 private static int called = 0;
106 private static File baseDir;
109 public void generateResourceFiles(Collection<File> resources,