2 * Copyright (c) 2016 Intel corporation 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;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
15 import java.lang.reflect.Constructor;
16 import java.lang.reflect.Method;
18 import java.net.URLClassLoader;
19 import org.junit.Test;
22 * union constructor with indentityref
23 * previously identityref was ignored so that there is no constructor
27 public class UnionWithIdentityrefTest extends BaseCompilationTest {
30 public void test() throws Exception {
31 final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-with-identityref");
32 final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-with-identityref");
33 generateTestSources("/compilation/union-with-identityref", sourcesOutputDir);
35 // Test if sources are compilable
36 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
38 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
39 Class<?> identBaseClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.yang.union.test.rev160509.IdentBase", true, loader);
40 Class<?> identOneClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.yang.union.test.rev160509.IdentOne", true, loader);
41 Class<?> unionTypeClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.yang.union.test.rev160509.UnionType", true, loader);
43 // test UnionType with IdentOne argument
44 Constructor<?> unionTypeIdentBaseConstructor = CompilationTestUtils.assertContainsConstructor(unionTypeClass, Class.class);
45 Object unionType = unionTypeIdentBaseConstructor.newInstance(identOneClass);
47 Method getUint8 = unionTypeClass.getDeclaredMethod("getUint8");
48 Object actualUint8 = getUint8.invoke(unionType);
49 assertNull(actualUint8);
51 Method getIdentityref = unionTypeClass.getDeclaredMethod("getIdentityref");
52 Object actualIdentityref = getIdentityref.invoke(unionType);
53 assertEquals(identOneClass, actualIdentityref);
55 Method getValue = unionTypeClass.getDeclaredMethod("getValue");
56 Object actualValue = getValue.invoke(unionType);
57 assertArrayEquals(identOneClass.toString().toCharArray(), (char[])actualValue);
59 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);