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.test;
11 import java.lang.reflect.Constructor;
13 import java.net.URLClassLoader;
14 import org.junit.Test;
17 * Test for BG-1276. Previous construction of union constructor
21 * public IpAddress(Arg1 _arg1) {
30 * was incorrect and setting
33 * <code>this._value == null</code>
36 * was replaced with setting _value to correct value, for example:
39 * <code>this._value = arg1.getValue()</code> or
40 * <code>this._value = _arg1.getValue().toString().toCharArray()</code>
42 public class Bug1276Test extends BaseCompilationTest {
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);
50 // Test if sources are compilable
51 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
53 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
54 Class<?> ipAddressClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.IpAddress",
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,
61 Constructor<?> ipAddressConstructor = CompilationTestUtils.assertContainsConstructor(ipAddressClass,
63 Constructor<?> ipv4addressConstructor = CompilationTestUtils.assertContainsConstructor(ipv4AddressClass,
65 Constructor<?> hostConstructor = CompilationTestUtils.assertContainsConstructor(hostClass, ipAddressClass);
67 // test IpAddress with Ipv4Address argument
68 Object ipv4address = ipv4addressConstructor.newInstance("192.168.0.1");
69 Object ipAddress = ipAddressConstructor.newInstance(ipv4address);
71 // test Host with IpAddress argument
72 Object host = hostConstructor.newInstance(ipAddress);
74 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);