Added generation of Transfer Objects from Type Definitions.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / maven-yang-plugin / src / test / java / org / opendaylight / controller / yang2sources / plugin / GenerateSourcesTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.yang2sources.plugin;
9
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.*;
14
15 import java.io.File;
16 import java.util.Collection;
17
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;
26
27 import com.google.common.collect.Lists;
28
29 public class GenerateSourcesTest {
30
31     @Mock
32     private YangModelParser parser;
33     private String yang;
34     private YangToSourcesMojo mojo;
35     private File outDir;
36
37     @Before
38     public void setUp() {
39         MockitoAnnotations.initMocks(this);
40
41         yang = new File(getClass().getResource("/mock.yang").getFile())
42                 .getParent();
43         outDir = new File("outputDir");
44         mojo = new YangToSourcesMojo(
45                 new CodeGeneratorArg[] { new CodeGeneratorArg(
46                         GeneratorMock.class.getName(), outDir) }, parser, yang);
47     }
48
49     @Test
50     public void test() throws Exception {
51         mojo.execute();
52         verify(parser, times(1)).parseYangModels(anyListOf(File.class));
53         assertThat(GeneratorMock.called, is(1));
54         assertThat(GeneratorMock.outputDir, is(outDir));
55     }
56
57     public static class GeneratorMock implements CodeGenerator {
58
59         private static int called = 0;
60         private static File outputDir;
61
62         @Override
63         public Collection<File> generateSources(SchemaContext context,
64                 File baseDir) {
65             called++;
66             outputDir = baseDir;
67             return Lists.newArrayList();
68         }
69     }
70 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.