/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.apache.kato.tck.scenario142.javaruntime;
import java.util.Iterator;
import javax.tools.diagnostics.image.CorruptData;
import javax.tools.diagnostics.image.CorruptDataException;
import javax.tools.diagnostics.runtime.java.JavaClass;
import javax.tools.diagnostics.runtime.java.JavaClassLoader;
import javax.tools.diagnostics.runtime.java.JavaField;
import javax.tools.diagnostics.runtime.java.JavaObject;
import javax.tools.diagnostics.runtime.java.JavaRuntime;
import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
/**
*
*
*/
public class TestJavaClassLoader_getJavaObject extends TCKJavaRuntimeTestcase {
public void testJavaClassLoader_getJavaObject()
{
boolean foundClassLoader = false;
JavaRuntime runtime=getJavaRuntime();
Iterator classloaders = runtime.getJavaClassLoaders().iterator();
while (classloaders.hasNext()) {
Object nextClassloader = classloaders.next();
if (nextClassloader instanceof CorruptData) {
System.err.println("returned CorruptData `" + nextClassloader + "'");
break;
}
JavaClassLoader aJavaClassloader = (JavaClassLoader) nextClassloader;
JavaClass theJavaClass;
try {
JavaObject classLoaderObject = (aJavaClassloader).getObject();
// The system class loader doesn't have an object.
if (classLoaderObject == null ) {
continue;
}
theJavaClass = classLoaderObject.getJavaClass();
Iterator fields = theJavaClass.getDeclaredFields().iterator();
while (fields.hasNext()) {
Object nextField = fields.next();
if (nextField instanceof CorruptData) {
System.err.println("returned CorruptData `" + nextField + "'");
break;
}
JavaField theField = (JavaField) nextField;
String theFieldName = theField.getName();
if (theFieldName.equals("JavaClassLoader_getJavaObject")){
foundClassLoader = true;
}
}
} catch (CorruptDataException e) {
assertNotNull(e.getCorruptData());
// TODO Auto-generated catch block
e.printStackTrace();
}
}
assertTrue(foundClassLoader);
}
}