Changed $Yang* generation package and name
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / Bug5151Test.java
1 /*
2  * Copyright (c) 2016 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.mdsal.binding.java.api.generator;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assume.assumeFalse;
13 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.BASE_SVC_PATH;
14 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.FS;
15
16 import java.io.File;
17 import java.util.Map;
18 import org.junit.Test;
19
20 /**
21  * Bug5151 involves adding <code>{@literal @}return</code> annotations to accessor methods.
22  */
23 public class Bug5151Test extends BaseCompilationTest {
24
25     private static final String BUG_ID = "bug5151";
26     private static final String SVC_PATH = BASE_SVC_PATH + FS + "urn" + FS + "test" + FS + "foo" + FS + "rev160706";
27
28     @Test
29     public void test() throws Exception {
30         // Xtend code generation uses the "line.separator" system property to generate proper line endings
31         // in templates, leading to test failures running on Windows-type OS.
32         assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
33         final File sourcesOutputDir = CompilationTestUtils.generatorOutput(BUG_ID);
34         final File compiledOutputDir = CompilationTestUtils.compilerOutput(BUG_ID);
35         generateTestSources(FS + "compilation" + FS + BUG_ID,
36             sourcesOutputDir);
37
38         // Test if sources are compilable
39         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
40
41         final Map<String, File> generatedFiles = FileSearchUtil.getFiles(sourcesOutputDir);
42         assertEquals(14, generatedFiles.size());
43
44         final File fooContainerFile = generatedFiles.get("FooContainer.java");
45         assertNotNull(fooContainerFile);
46         FileSearchUtil.assertFileContains(fooContainerFile,
47             "@return {@code String} fooInContainer, or {@code null} if it is not present");
48
49         final File fooDataFile = generatedFiles.get("FooData.java");
50         assertNotNull(fooDataFile);
51         FileSearchUtil.assertFileContains(fooDataFile,
52             "FooContainer} fooContainer, or {@code null} if it is not present");
53
54         final File svcParent = new File(sourcesOutputDir, SVC_PATH);
55         CompilationTestUtils.assertFilesCount(svcParent, 1);
56
57         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
58     }
59 }