9d6b66720956a3fb51e2176ba26964470d4e5d9e
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / test / NestedGroupingCompilationTest.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 org.junit.Assert.assertTrue;
11 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.BASE_PKG;
12 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.NS_TEST;
13 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.assertFilesCount;
14 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.assertImplementsIfc;
15 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.cleanUp;
16 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.testCompilation;
17
18 import java.io.File;
19 import java.net.URL;
20 import java.net.URLClassLoader;
21 import org.junit.Test;
22
23 /**
24  * Test correct code generation.
25  *
26  */
27 public class NestedGroupingCompilationTest extends BaseCompilationTest {
28
29     @Test
30     public void testListGeneration() throws Exception {
31         final File sourcesOutputDir = CompilationTestUtils.generatorOutput("nested-grouping");
32         final File compiledOutputDir = CompilationTestUtils.compilerOutput("nested-grouping");
33         generateTestSources("/compilation/nested-grouping", sourcesOutputDir);
34
35         // Test if all sources are generated
36         File parent = new File(sourcesOutputDir, NS_TEST);
37         File foo = new File(parent, "Foo.java");
38         File fooBuilder = new File(parent, "FooBuilder.java");
39         File testData = new File(parent, "TestData.java");
40         File fooDir = new File(parent, "foo");
41         assertTrue(foo.exists());
42         assertTrue(fooBuilder.exists());
43         assertTrue(testData.exists());
44         assertTrue(fooDir.exists());
45         assertFilesCount(parent, 4);
46
47         parent = new File(parent, "foo");
48         File bar = new File(parent, "Bar.java");
49         assertTrue(bar.exists());
50         assertFilesCount(parent, 1);
51
52         // Test if sources are compilable
53         testCompilation(sourcesOutputDir, compiledOutputDir);
54
55         ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
56         Class<?> fooClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Foo", true, loader);
57         Class<?> barClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.foo.Bar", true, loader);
58
59         // Test generated 'foo'
60         assertTrue(fooClass.isInterface());
61         assertImplementsIfc(fooClass, barClass);
62
63         cleanUp(sourcesOutputDir, compiledOutputDir);
64     }
65 }