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;
13 import java.io.IOException;
14 import java.net.URISyntaxException;
16 import java.net.URLClassLoader;
17 import org.junit.Test;
19 public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest {
22 public void testAugmentToUsesInAugment() throws IOException, URISyntaxException {
23 final File sourcesOutputDir = CompilationTestUtils.generatorOutput("augment-uses-to-augment");
24 final File compiledOutputDir = CompilationTestUtils.compilerOutput("augment-uses-to-augment");
25 generateTestSources("/compilation/augment-uses-to-augment", sourcesOutputDir);
27 // Test if all sources are generated from 'module foo'
28 File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
29 assertTrue(new File(fooParent, "FooData.java").exists());
30 assertTrue(new File(fooParent, "IgpLinkAttributes.java").exists());
31 assertTrue(new File(fooParent, "Link1.java").exists());
32 assertTrue(new File(fooParent, "Link1Builder.java").exists());
33 CompilationTestUtils.assertFilesCount(fooParent, 6);
35 // Test if all sources are generated from 'module bar'
36 File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
37 assertTrue(new File(barParent, "BarData.java").exists());
38 assertTrue(new File(barParent, "NetworkTopology.java").exists());
39 assertTrue(new File(barParent, "NetworkTopologyBuilder.java").exists());
40 assertTrue(new File(barParent, "Link.java").exists());
41 assertTrue(new File(barParent, "LinkAttributes.java").exists());
42 CompilationTestUtils.assertFilesCount(barParent, 8);
44 File networkParent = new File(barParent, "network");
45 CompilationTestUtils.assertFilesCount(networkParent, 1);
46 File topologyParent = new File(networkParent, "topology");
47 assertTrue(new File(topologyParent, "Topology.java").exists());
48 assertTrue(new File(topologyParent, "TopologyBuilder.java").exists());
49 assertTrue(new File(topologyParent, "TopologyKey.java").exists());
50 CompilationTestUtils.assertFilesCount(topologyParent, 3);
52 File linkParent = new File(barParent, "link");
53 assertTrue(new File(linkParent, "Link.java").exists());
54 assertTrue(new File(linkParent, "LinkBuilder.java").exists());
55 assertTrue(new File(linkParent, "LinkKey.java").exists());
56 CompilationTestUtils.assertFilesCount(linkParent, 3);
58 // Test if all sources are generated from 'module baz'
59 File bazParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
60 assertTrue(new File(bazParent, "BazData.java").exists());
61 assertTrue(new File(bazParent, "IgpLinkAttributes1.java").exists());
62 assertTrue(new File(bazParent, "IgpLinkAttributes1Builder.java").exists());
63 assertTrue(new File(bazParent, "LinkAttributes.java").exists());
64 CompilationTestUtils.assertFilesCount(bazParent, 6);
66 // Test if sources are compilable
67 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
69 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
72 Class<?> link1Class = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Link1",
74 String augmentableNode = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.link.Link";
75 CompilationTestUtils.testAugmentation(link1Class, augmentableNode);
77 Class<?> igpLinkAttributesClass = Class.forName(CompilationTestUtils.BASE_PKG
78 + ".urn.opendaylight.foo.rev131008.IgpLinkAttributes", true, loader);
79 CompilationTestUtils.assertImplementsIfc(link1Class, igpLinkAttributesClass);
80 } catch (ClassNotFoundException e) {
81 throw new AssertionError("Class for augment wasn't generated", e);
85 Class<?> igpLinkAttributes1Class = Class.forName(CompilationTestUtils.BASE_PKG
86 + ".urn.opendaylight.baz.rev131008.IgpLinkAttributes1", true, loader);
87 CompilationTestUtils.testAugmentation(igpLinkAttributes1Class, CompilationTestUtils.BASE_PKG
88 + ".urn.opendaylight.foo.rev131008.igp.link.attributes.IgpLinkAttributes");
90 Class<?> linkAttributesClass = Class.forName(CompilationTestUtils.BASE_PKG
91 + ".urn.opendaylight.baz.rev131008.LinkAttributes", true, loader);
92 CompilationTestUtils.assertImplementsIfc(igpLinkAttributes1Class, linkAttributesClass);
93 } catch (ClassNotFoundException e) {
94 throw new AssertionError("Class for augment wasn't generated", e);
97 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);