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.Module;
25 import org.opendaylight.controller.yang.model.api.SchemaContext;
26 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
27 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
28 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
29 import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
30 import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
32 import com.google.common.collect.Lists;
35 public class GenerateSourcesTest {
38 private YangModelParser parser;
40 private YangToSourcesMojo mojo;
45 MockitoAnnotations.initMocks(this);
47 yang = new File(getClass().getResource("/mock.yang").getFile())
49 outDir = new File("outputDir");
50 mojo = new YangToSourcesMojo(
51 new ResourceProviderArg[] {
52 new ResourceProviderArg(ProviderMock.class.getName(),
54 new ResourceProviderArg(ProviderMock2.class.getName(),
56 new CodeGeneratorArg[] { new CodeGeneratorArg(
57 GeneratorMock.class.getName(), outDir) }, parser, yang);
61 public void test() throws Exception {
63 verify(parser, times(1)).parseYangModels(anyListOf(File.class));
64 assertThat(GeneratorMock.called, is(1));
65 assertThat(GeneratorMock.outputDir, is(outDir));
69 public void testRes() throws Exception {
71 assertThat(ProviderMock.called, is(1));
72 assertThat(ProviderMock2.called, is(1));
73 assertThat(ProviderMock2.baseDir, is(outDir));
74 assertThat(ProviderMock.baseDir, is(outDir));
77 public static class GeneratorMock implements CodeGenerator {
79 private static int called = 0;
80 private static File outputDir;
83 public Collection<File> generateSources(SchemaContext context,
84 File baseDir, Set<Module> yangModules) {
87 return Lists.newArrayList();
91 public static class ProviderMock implements ResourceGenerator {
93 private static int called = 0;
94 private static File baseDir;
97 public void generateResourceFiles(Collection<File> resources,
104 public static class ProviderMock2 implements ResourceGenerator {
106 private static int called = 0;
107 private static File baseDir;
110 public void generateResourceFiles(Collection<File> resources,