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.*;
11 import static org.junit.Assert.*;
12 import static org.mockito.Matchers.*;
13 import static org.mockito.Mockito.*;
16 import java.util.Collection;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.yang.model.api.SchemaContext;
23 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
24 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
25 import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
27 import com.google.common.collect.Lists;
29 public class GenerateSourcesTest {
32 private YangModelParser parser;
34 private YangToSourcesMojo mojo;
39 MockitoAnnotations.initMocks(this);
41 yang = new File(getClass().getResource("/mock.yang").getFile())
43 outDir = new File("outputDir");
44 mojo = new YangToSourcesMojo(
45 new CodeGeneratorArg[] { new CodeGeneratorArg(
46 GeneratorMock.class.getName(), outDir) }, parser, yang);
50 public void test() throws Exception {
52 verify(parser, times(1)).parseYangModels((String[]) anyVararg());
53 assertThat(GeneratorMock.called, is(1));
54 assertThat(GeneratorMock.outputDir, is(outDir));
57 public static class GeneratorMock implements CodeGenerator {
59 private static int called = 0;
60 private static File outputDir;
63 public Collection<File> generateSources(SchemaContext context,
67 return Lists.newArrayList();