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