Package org.apache.kato.tck.scenario142.javaruntime

Source Code of org.apache.kato.tck.scenario142.javaruntime.TestJavaMethod_getName

/*******************************************************************************
* 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.runtime.java.JavaClass;
import javax.tools.diagnostics.runtime.java.JavaLocation;
import javax.tools.diagnostics.runtime.java.JavaMethod;
import javax.tools.diagnostics.runtime.java.JavaObject;
import javax.tools.diagnostics.runtime.java.JavaStackFrame;
import javax.tools.diagnostics.runtime.java.JavaThread;

import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
import org.apache.kato.tck.scenario142.javaruntime.SetupJavaMethod_getName;


public class TestJavaMethod_getName extends TCKJavaRuntimeTestcase {
 
  static JavaObject thisObject = null
  public JavaObject getScenerioReference() {
    if (thisObject == null) {
      thisObject = super.getScenerioReference();
   
    return thisObject;   
  }
 
  /**
   * Get this class directly, and find the method via getDeclaredMethods().iterator();
   *
   * @throws Exception
   */
  public void testGetDeclaredMethods() throws Exception {
    JavaClass thisClass = getScenerioReference().getJavaClass();
   
    assertNotNull("Unable to find this class", thisClass);
   
    Iterator methods = thisClass.getDeclaredMethods().iterator();
    boolean found=false;
    while(methods.hasNext()) {
      JavaMethod method = (JavaMethod) methods.next();
     
      if (method.getName().equals(SetupJavaMethod_getName.methodName)) {
        found = true;
        break;
      }
    }
   
    assertTrue("Unable to find method get\u0412\u043e\u0434\u043a\u0430()", found);
  }
 
  /**
   * Pick the method off of the JavaThreads stack. The JavaMethod might be
   * instantiated differently.
   *
   * @throws Exception
   */
  public void testGetStackMethods() throws Exception {
    Iterator threads = getJavaRuntime().getThreads().iterator();
   
    JavaThread testThread = null;
    while(threads.hasNext()) {
      Object next = threads.next();
     
      if (next instanceof JavaThread) {
        JavaThread thread = (JavaThread) next;
        if (thread.getName().equals(SetupJavaMethod_getName.threadName)) {
          testThread = thread;
          break;
        }
      } else {
        break;
      }
    }
   
    assertNotNull("Unable to find thread "+SetupJavaMethod_getName.threadName, testThread);
   
    Iterator frames = testThread.getStackFrames().iterator();
    boolean found = false;
   
    while(frames.hasNext()) {
      Object next = frames.next();
     
      if(next instanceof JavaStackFrame) {
        JavaStackFrame frame = (JavaStackFrame) next;
       
        JavaLocation location = frame.getLocation();
       
        if (location != null) {
          JavaMethod method = location.getMethod();
         
          if(method != null) {
            if (SetupJavaMethod_getName.methodName.equals(method.getName())) {
              found = true;
              break;
            }
          }
        }
      }
    }
   
    assertTrue("Unable to find method "+SetupJavaMethod_getName.methodName+" in stack.", found);
  }
}
TOP

Related Classes of org.apache.kato.tck.scenario142.javaruntime.TestJavaMethod_getName

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.