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 final 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, 5);
34 final File fooSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_FOO);
35 CompilationTestUtils.assertFilesCount(fooSvcParent, 1);
37 // Test if all sources are generated from 'module bar'
38 final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
39 assertTrue(new File(barParent, "BarData.java").exists());
40 assertTrue(new File(barParent, "NetworkTopology.java").exists());
41 assertTrue(new File(barParent, "NetworkTopologyBuilder.java").exists());
42 assertTrue(new File(barParent, "Link.java").exists());
43 assertTrue(new File(barParent, "LinkAttributes.java").exists());
44 CompilationTestUtils.assertFilesCount(barParent, 7);
45 final File barSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAR);
46 CompilationTestUtils.assertFilesCount(barSvcParent, 1);
48 final File networkParent = new File(barParent, "network");
49 CompilationTestUtils.assertFilesCount(networkParent, 1);
50 final File topologyParent = new File(networkParent, "topology");
51 assertTrue(new File(topologyParent, "Topology.java").exists());
52 assertTrue(new File(topologyParent, "TopologyBuilder.java").exists());
53 assertTrue(new File(topologyParent, "TopologyKey.java").exists());
54 CompilationTestUtils.assertFilesCount(topologyParent, 3);
56 final File linkParent = new File(barParent, "link");
57 assertTrue(new File(linkParent, "Link.java").exists());
58 assertTrue(new File(linkParent, "LinkBuilder.java").exists());
59 assertTrue(new File(linkParent, "LinkKey.java").exists());
60 CompilationTestUtils.assertFilesCount(linkParent, 3);
62 // Test if all sources are generated from 'module baz'
63 final File bazParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
64 assertTrue(new File(bazParent, "BazData.java").exists());
65 assertTrue(new File(bazParent, "IgpLinkAttributes1.java").exists());
66 assertTrue(new File(bazParent, "IgpLinkAttributes1Builder.java").exists());
67 assertTrue(new File(bazParent, "LinkAttributes.java").exists());
68 CompilationTestUtils.assertFilesCount(bazParent, 5);
69 final File bazSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAZ);
70 CompilationTestUtils.assertFilesCount(bazSvcParent, 1);
72 // Test if sources are compilable
73 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
75 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
78 Class<?> link1Class = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Link1",
80 String augmentableNode = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.link.Link";
81 CompilationTestUtils.testAugmentation(link1Class, augmentableNode);
83 Class<?> igpLinkAttributesClass = Class.forName(CompilationTestUtils.BASE_PKG
84 + ".urn.opendaylight.foo.rev131008.IgpLinkAttributes", true, loader);
85 CompilationTestUtils.assertImplementsIfc(link1Class, igpLinkAttributesClass);
86 } catch (ClassNotFoundException e) {
87 throw new AssertionError("Class for augment wasn't generated", e);
91 Class<?> igpLinkAttributes1Class = Class.forName(CompilationTestUtils.BASE_PKG
92 + ".urn.opendaylight.baz.rev131008.IgpLinkAttributes1", true, loader);
93 CompilationTestUtils.testAugmentation(igpLinkAttributes1Class, CompilationTestUtils.BASE_PKG
94 + ".urn.opendaylight.foo.rev131008.igp.link.attributes.IgpLinkAttributes");
96 Class<?> linkAttributesClass = Class.forName(CompilationTestUtils.BASE_PKG
97 + ".urn.opendaylight.baz.rev131008.LinkAttributes", true, loader);
98 CompilationTestUtils.assertImplementsIfc(igpLinkAttributes1Class, linkAttributesClass);
99 } catch (ClassNotFoundException e) {
100 throw new AssertionError("Class for augment wasn't generated", e);
103 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);