2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.java.api.generator;
10 import static org.junit.Assert.assertTrue;
11 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.BASE_PKG;
12 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_TEST;
13 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.assertFilesCount;
14 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.assertImplementsIfc;
15 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.cleanUp;
16 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.testCompilation;
20 import java.net.URLClassLoader;
21 import org.junit.Test;
24 * Test correct code generation.
27 public class NestedGroupingCompilationTest extends BaseCompilationTest {
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);
35 // Test if all sources are generated
36 File parent = new File(sourcesOutputDir, NS_TEST);
37 final File foo = new File(parent, "Foo.java");
38 final File fooBuilder = new File(parent, "FooBuilder.java");
39 final File testData = new File(parent, "TestData.java");
40 final 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, 5);
47 parent = new File(parent, "foo");
48 File bar = new File(parent, "Bar.java");
49 assertTrue(bar.exists());
50 assertFilesCount(parent, 1);
52 // Test if sources are compilable
53 testCompilation(sourcesOutputDir, compiledOutputDir);
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);
59 // Test generated 'foo'
60 assertTrue(fooClass.isInterface());
61 assertImplementsIfc(fooClass, barClass);
63 cleanUp(sourcesOutputDir, compiledOutputDir);