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;
18 import org.junit.Before;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.yang.model.api.SchemaContext;
24 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
25 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
26 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
27 import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
28 import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
30 import com.google.common.collect.Lists;
33 public class GenerateSourcesTest {
36 private YangModelParser parser;
38 private YangToSourcesMojo mojo;
43 MockitoAnnotations.initMocks(this);
45 yang = new File(getClass().getResource("/mock.yang").getFile())
47 outDir = new File("outputDir");
48 mojo = new YangToSourcesMojo(
49 new ResourceProviderArg[] {
50 new ResourceProviderArg(ProviderMock.class.getName(),
52 new ResourceProviderArg(ProviderMock2.class.getName(),
54 new CodeGeneratorArg[] { new CodeGeneratorArg(
55 GeneratorMock.class.getName(), outDir) }, parser, yang);
59 public void test() throws Exception {
61 verify(parser, times(1)).parseYangModels(anyListOf(File.class));
62 assertThat(GeneratorMock.called, is(1));
63 assertThat(GeneratorMock.outputDir, is(outDir));
67 public void testRes() throws Exception {
69 assertThat(ProviderMock.called, is(1));
70 assertThat(ProviderMock2.called, is(1));
71 assertThat(ProviderMock2.baseDir, is(outDir));
72 assertThat(ProviderMock.baseDir, is(outDir));
75 public static class GeneratorMock implements CodeGenerator {
77 private static int called = 0;
78 private static File outputDir;
81 public Collection<File> generateSources(SchemaContext context,
85 return Lists.newArrayList();
89 public static class ProviderMock implements ResourceGenerator {
91 private static int called = 0;
92 private static File baseDir;
95 public void generateResourceFiles(Collection<File> resources,
102 public static class ProviderMock2 implements ResourceGenerator {
104 private static int called = 0;
105 private static File baseDir;
108 public void generateResourceFiles(Collection<File> resources,