$YangModuleInfoImpl not generated for only extensions model
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / test / Bug1276Test.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 java.io.File;
11 import java.lang.reflect.Constructor;
12 import java.net.URL;
13 import java.net.URLClassLoader;
14 import org.junit.Test;
15
16 /**
17  * Test for BG-1276. Previous construction of union constructor
18  *
19  * <p>
20  * <code>
21  * public IpAddress(Arg1 _arg1) {
22  *     super();
23  *     this._arg1 = _arg1;
24  *     this._arg2 = null;
25  *     this._value = null;
26  * }
27  * </code>
28  *
29  * <p>
30  * was incorrect and setting
31  *
32  * <p>
33  * <code>this._value == null</code>
34  *
35  * <p>
36  * was replaced with setting _value to correct value, for example:
37  *
38  * <p>
39  * <code>this._value = arg1.getValue()</code> or
40  * <code>this._value = _arg1.getValue().toString().toCharArray()</code>
41  */
42 public class Bug1276Test extends BaseCompilationTest {
43
44     @Test
45     public void test() throws Exception {
46         final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1276");
47         final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1276");
48         generateTestSources("/compilation/bug1276", sourcesOutputDir);
49
50         // Test if sources are compilable
51         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
52
53         ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
54         Class<?> ipAddressClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.IpAddress",
55             true, loader);
56         Class<?> ipv4AddressClass = Class.forName(CompilationTestUtils.BASE_PKG
57             + ".test.yang.union.rev140715.Ipv4Address", true, loader);
58         Class<?> hostClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.Host", true,
59             loader);
60
61         Constructor<?> ipAddressConstructor = CompilationTestUtils.assertContainsConstructor(ipAddressClass,
62             ipv4AddressClass);
63         Constructor<?> ipv4addressConstructor = CompilationTestUtils.assertContainsConstructor(ipv4AddressClass,
64             String.class);
65         Constructor<?> hostConstructor = CompilationTestUtils.assertContainsConstructor(hostClass, ipAddressClass);
66
67         // test IpAddress with Ipv4Address argument
68         Object ipv4address = ipv4addressConstructor.newInstance("192.168.0.1");
69         Object ipAddress = ipAddressConstructor.newInstance(ipv4address);
70
71         // test Host with IpAddress argument
72         Object host = hostConstructor.newInstance(ipAddress);
73
74         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
75     }
76 }