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 * Previous construction of union constructor
20 * public IpAddress(Arg1 _arg1) {
28 * was incorrect and setting
30 * <code>this._value == null</code>
32 * was replaced with setting _value to correct value, for example:
34 * <code>this._value = arg1.getValue()</code> or
35 * <code>this._value = _arg1.getValue().toString().toCharArray()</code>
38 public class Bug1276Test extends BaseCompilationTest {
41 public void test() throws Exception {
42 final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1276");
43 final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1276");
44 generateTestSources("/compilation/bug1276", sourcesOutputDir);
46 // Test if sources are compilable
47 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
49 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
50 Class<?> ipAddressClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.IpAddress", true, loader);
51 Class<?> ipv4AddressClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.Ipv4Address", true, loader);
52 Class<?> hostClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.Host", true, loader);
54 Constructor<?> ipAddressConstructor = CompilationTestUtils.assertContainsConstructor(ipAddressClass, ipv4AddressClass);
55 Constructor<?> ipv4addressConstructor = CompilationTestUtils.assertContainsConstructor(ipv4AddressClass, String.class);
56 Constructor<?> hostConstructor = CompilationTestUtils.assertContainsConstructor(hostClass, ipAddressClass);
58 // test IpAddress with Ipv4Address argument
59 Object ipv4address = ipv4addressConstructor.newInstance("192.168.0.1");
60 Object ipAddress = ipAddressConstructor.newInstance(ipv4address);
62 // test Host with IpAddress argument
63 Object host = hostConstructor.newInstance(ipAddress);
65 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);