4d7ee9002532edc962e272753759a5033231630b
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / test / 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.test;
9
10 import static junit.framework.TestCase.assertTrue;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.io.File;
15 import java.util.Map;
16 import org.junit.Test;
17
18 /**
19  * Bug5151 involves adding <code>{@literal @}return</code> annotations to accessor methods.
20  */
21 public class Bug5151Test extends BaseCompilationTest {
22
23     private static final String BUG_ID = "bug5151";
24
25     @Test
26     public void test() throws Exception {
27         final File sourcesOutputDir = CompilationTestUtils.generatorOutput(BUG_ID);
28         final File compiledOutputDir = CompilationTestUtils.compilerOutput(BUG_ID);
29         generateTestSources(CompilationTestUtils.FS + "compilation" + CompilationTestUtils.FS + BUG_ID,
30             sourcesOutputDir);
31
32         // Test if sources are compilable
33         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
34
35         final Map<String, File> generatedFiles = FileSearchUtil.getFiles(sourcesOutputDir);
36         assertEquals(13, generatedFiles.size());
37
38         final File fooContainerFile = generatedFiles.get("FooContainer.java");
39         assertNotNull(fooContainerFile);
40         assertTrue(FileSearchUtil.findInFile(fooContainerFile,
41                 "@return <code>java.lang.String</code> <code>fooInContainer</code>, "
42                         + "or <code>null</code> if not present"));
43
44         final File fooDataFile = generatedFiles.get("FooData.java");
45         assertNotNull(fooDataFile);
46         assertTrue(FileSearchUtil.findInFile(fooDataFile,
47             "FooContainer</code> <code>fooContainer</code>, or <code>null</code> if not present"));
48
49         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
50     }
51 }