/*******************************************************************************
* 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.JavaHeap;
import javax.tools.diagnostics.runtime.java.JavaObject;
import javax.tools.diagnostics.runtime.java.JavaRuntime;
import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
import org.apache.kato.tck.scenario142.javaruntime.SetupJavaClass_getName;
public class TestJavaClass_getName extends TCKJavaRuntimeTestcase {
/**
*
*/
public void testJavaClass_getName()
{
boolean foundClassName = false;
JavaRuntime runtime=getJavaRuntime();
Iterator heaps = runtime.getHeaps().iterator();
while (heaps.hasNext()) {
Object nextHeap = heaps.next();
if (nextHeap instanceof CorruptData) {
System.err.println("returned CorruptData `" + nextHeap + "'");
break;
}
JavaHeap aJavaHeap = (JavaHeap) nextHeap;
Iterator objects = aJavaHeap.getObjects().iterator();
while (objects.hasNext()) {
Object nextObject = objects.next();
if (nextObject instanceof CorruptData) {
System.err.println("returned CorruptData `" + nextObject + "'");
break;
}
JavaObject aJavaObject = (JavaObject) nextObject;
try {
JavaClass theJavaClass = aJavaObject.getJavaClass();
String theClassName = (theJavaClass).getName();
if (SetupJavaClass_getName.TestObjectClassName.equals(theClassName)) {
System.out.println("theClassName "+theClassName);
foundClassName=true;
}
} catch (CorruptDataException e) {
assertNotNull(e.getCorruptData());
e.printStackTrace();
}
}
}
assertTrue(foundClassName);
}
public void testUnicodeClassName() throws Exception {
JavaObject obj = getJavaObjectByClassname(SetupJavaClass_getName.unicodeClassname);
assertNotNull("Couldn't find object of instance " + SetupJavaClass_getName.unicodeClassname, obj);
}
}