Equals/HashCode/StringBuilder removal from Supported/PeerBandwidth
[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.is;
11 import static org.junit.Assert.assertThat;
12 import static org.mockito.Matchers.anyListOf;
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.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;
29
30 import com.google.common.collect.Lists;
31
32 @Ignore
33 public class GenerateSourcesTest {
34
35     @Mock
36     private YangModelParser parser;
37     private String yang;
38     private YangToSourcesMojo mojo;
39     private File outDir;
40
41     @Before
42     public void setUp() {
43         MockitoAnnotations.initMocks(this);
44
45         yang = new File(getClass().getResource("/mock.yang").getFile())
46                 .getParent();
47         outDir = new File("outputDir");
48         mojo = new YangToSourcesMojo(
49                 new ResourceProviderArg[] {
50                         new ResourceProviderArg(ProviderMock.class.getName(),
51                                 outDir),
52                         new ResourceProviderArg(ProviderMock2.class.getName(),
53                                 outDir) },
54                 new CodeGeneratorArg[] { new CodeGeneratorArg(
55                         GeneratorMock.class.getName(), outDir) }, parser, yang);
56     }
57
58     @Test
59     public void test() throws Exception {
60         mojo.execute();
61         verify(parser, times(1)).parseYangModels(anyListOf(File.class));
62         assertThat(GeneratorMock.called, is(1));
63         assertThat(GeneratorMock.outputDir, is(outDir));
64     }
65
66     @Test
67     public void testRes() throws Exception {
68         mojo.execute();
69         assertThat(ProviderMock.called, is(1));
70         assertThat(ProviderMock2.called, is(1));
71         assertThat(ProviderMock2.baseDir, is(outDir));
72         assertThat(ProviderMock.baseDir, is(outDir));
73     }
74
75     public static class GeneratorMock implements CodeGenerator {
76
77         private static int called = 0;
78         private static File outputDir;
79
80         @Override
81         public Collection<File> generateSources(SchemaContext context,
82                 File baseDir) {
83             called++;
84             outputDir = baseDir;
85             return Lists.newArrayList();
86         }
87     }
88
89     public static class ProviderMock implements ResourceGenerator {
90
91         private static int called = 0;
92         private static File baseDir;
93
94         @Override
95         public void generateResourceFiles(Collection<File> resources,
96                 File outputDir) {
97             called++;
98             baseDir = outputDir;
99         }
100     }
101
102     public static class ProviderMock2 implements ResourceGenerator {
103
104         private static int called = 0;
105         private static File baseDir;
106
107         @Override
108         public void generateResourceFiles(Collection<File> resources,
109                 File outputDir) {
110             called++;
111             baseDir = outputDir;
112         }
113     }
114 }