Merge "Moving a recently added trim() call in SwitchHandler after Null check."
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-to-sources-plugin / src / test / java / org / opendaylight / controller / yang2sources / plugin / GenerateResourcesTest.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
13 import java.io.File;
14 import java.util.Collection;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
19 import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
20
21 public class GenerateResourcesTest {
22
23     private String yang;
24     private YangToResourcesMojo mojo;
25     private File outDir;
26
27     @Before
28     public void setUp() {
29         yang = new File(getClass().getResource("/mock.yang").getFile())
30                 .getParent();
31         outDir = new File("outputDir");
32         mojo = new YangToResourcesMojo(
33                 new ResourceProviderArg[] {
34                         new ResourceProviderArg(ProviderMock.class.getName(),
35                                 outDir),
36                         new ResourceProviderArg(ProviderMock2.class.getName(),
37                                 outDir) }, yang);
38     }
39
40     @Test
41     public void test() throws Exception {
42         mojo.execute();
43         assertThat(ProviderMock.called, is(1));
44         assertThat(ProviderMock2.called, is(1));
45         assertThat(ProviderMock2.baseDir, is(outDir));
46         assertThat(ProviderMock.baseDir, is(outDir));
47     }
48
49     public static class ProviderMock implements ResourceGenerator {
50
51         private static int called = 0;
52         private static File baseDir;
53
54         @Override
55         public void generateResourceFiles(Collection<File> resources,
56                 File outputDir) {
57             called++;
58             baseDir = outputDir;
59         }
60     }
61
62     public static class ProviderMock2 implements ResourceGenerator {
63
64         private static int called = 0;
65         private static File baseDir;
66
67         @Override
68         public void generateResourceFiles(Collection<File> resources,
69                 File outputDir) {
70             called++;
71             baseDir = outputDir;
72         }
73     }
74
75 }