Package javax.tools.diagnostics.runtime.java

Examples of javax.tools.diagnostics.runtime.java.JavaObject


public class TestJavaReferences extends TCKJavaRuntimeTestcase {
 
 
  public void testReferences_getDescription() {
    JavaObject thisObj = getScenerioReference();
    Iterator references = thisObj.getReferences().iterator();
   
    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
View Full Code Here


      assertNotNull("Reference description is null", ref.getDescription());
    }
  }

  public void testReferences_getReachability() throws Exception {
    JavaObject thisObj = getScenerioReference();
    Iterator references = thisObj.getReferences().iterator();
   
    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      Object target = ref.getTarget();
      if (!(target instanceof JavaObject)) {
        continue;
      }
      JavaObject targetObject = (JavaObject)target;
      if ("java/lang/ref/WeakReference".equals(targetObject.getJavaClass().getName())) {
        JavaReference referent = getReferent(targetObject);
        assertTrue("Reachability for weak referent different from \"Weak\"", JavaReference.REACHABILITY_WEAK == referent.getReachability());
       
       
      } else if ("java/lang/ref/SoftReference".equals(targetObject.getJavaClass().getName())) {
        JavaReference referent = getReferent(targetObject);
        assertTrue("Reachability for soft referent different from \"Soft\"", JavaReference.REACHABILITY_SOFT == referent.getReachability());
       
      } else if ("java/lang/ref/PhantomReference".equals(targetObject.getJavaClass().getName())) {
        JavaReference referent = getReferent(targetObject);
        assertTrue("Reachability for phantom referent different from \"Phantom\"", JavaReference.REACHABILITY_PHANTOM == referent.getReachability());
       
      } else if (targetObject.getJavaClass().getName().endsWith("StrongReferent")) {
        assertTrue("Reachability for strong field reference different from \"Strong\"", JavaReference.REACHABILITY_STRONG == ref.getReachability());
      }
    }
  }
View Full Code Here

      }
    }
  }
 
  public void testReferences_isClassReference() throws Exception {
    JavaObject thisObj = getScenerioReference();
    Iterator references = thisObj.getReferences().iterator();
   
    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
View Full Code Here

    }
   
  }
 
  public void testReferences_isObjectReference() throws Exception {
    JavaObject thisObj = getScenerioReference();
    Iterator references = thisObj.getReferences().iterator();
   
    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
View Full Code Here

    }
   
  }
 
  public void testReferences_getReferenceType() throws Exception {
    JavaObject thisObj = getScenerioReference();
    Iterator references = thisObj.getReferences().iterator();
   
    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      int type = ref.getReferenceType();
      Object source = ref.getSource();
      Object target = ref.getTarget();
     
      switch (type) {
      case JavaReference.REFERENCE_FIELD:
        if (source instanceof JavaObject) {
          JavaObject sourceObject = (JavaObject)source;
          if (!(sourceObject.equals(thisObj))) {
            fail("Source object for a field reference not equal to this object.");
          }

          if (target instanceof JavaObject) {
            JavaObject targetObject = (JavaObject)target;
            String objectsClassName = targetObject.getJavaClass().getName();
            if (!(objectsClassName.endsWith("Reference") ||
                objectsClassName.endsWith("Referent"||
                objectsClassName.endsWith("ArrayElement;") ||
                objectsClassName.endsWith("ClassLoader"))) {
              fail("Unexpected field reference of type: "+ objectsClassName);
            }
            if (objectsClassName.endsWith("ArrayElement;") && targetObject.isArray()) {
              //found the array field.
              Iterator refs = targetObject.getReferences().iterator();
              boolean arrayElementFound = false;
              while (refs.hasNext()) {
                Object next2 = refs.next();
                if (!(next2 instanceof JavaReference)) {
                  continue;
                }
                JavaReference ref2 = (JavaReference)next2;
                int type2 = ref2.getReferenceType();
                Object target2 = ref2.getTarget();
               
                if (type2 == JavaReference.REFERENCE_ARRAY_ELEMENT) {
                  if (target2 instanceof JavaObject) {
                    JavaObject targetObject2 = (JavaObject)target2;
                    String objectsClassName2 = targetObject2.getJavaClass().getName();
                    if (objectsClassName2.endsWith("ArrayElement") && !targetObject2.isArray()) {
                      arrayElementFound = true;
                    }
                  } else {
                    fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
                  }
                }
              }
              assertTrue("Array element reference not found.", arrayElementFound);
            }
         
          } else {
            fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
          }
         
        } else {
          fail("Source object of a field reference is not a valid JavaObject.");
        }
        break;
      case JavaReference.REFERENCE_CLASS:
        if (source instanceof JavaObject) {
          JavaObject sourceObject = (JavaObject)source;
          if (!(sourceObject.equals(thisObj))) {
            fail("Source object for a CLASS reference not equal to this object.");
          }

          if (!(target instanceof JavaClass)) {
            fail("Target object for a CLASS reference not a JavaClass object.");
          }
          JavaClass targetClass = (JavaClass)target;
          assertTrue("Target class for the CLASS reference of this object different from expected.", targetClass.getName().endsWith("SetupJavaReferences"));
          Iterator refs = targetClass.getReferences().iterator();
          boolean classLoaderFound = false;
          while (refs.hasNext()) {
            Object next2 = refs.next();
            if (!(next2 instanceof JavaReference)) {
              continue;
            }
            JavaReference ref2 = (JavaReference)next2;
            int type2 = ref2.getReferenceType();
            Object target2 = ref2.getTarget();
           
            if (type2 == JavaReference.REFERENCE_CLASS_LOADER) {
              if (!(target2 instanceof JavaObject)) {
                fail("Target object for a CLASSLOADER reference does not represent a JavaObject.");
              }
              JavaObject targetObject2 = (JavaObject)target2;
              if (targetObject2.getClass().getName().endsWith("ClassLoader")) {
                fail("Target object for a CLASSLOADER reference does not represent a ClassLoader.");
              } else {
                classLoaderFound = true;
              }
            }
          }
          assertTrue("ClassLoader reference not found.", classLoaderFound);
         
        } else {
          fail("Source object of a CLASS reference is not a valid JavaObject.");
        }
        break;
      case JavaReference.REFERENCE_CLASS_LOADER:
        if (source instanceof JavaObject) {
          JavaObject sourceObject = (JavaObject)source;
          if (!(sourceObject.equals(thisObj))) {
            fail("Source object for a CLASSLOADER reference not equal to this object.");
          }

          if (!(target instanceof JavaClassLoader)) {
            fail("Target object for a CLASSLOADER reference not a JavaClass object.");
View Full Code Here

      }

      JavaMonitor monitorCandidate = (JavaMonitor) next;
     
      //System.out.println("Monitor candidate->"+monitorCandidate.getName());
      JavaObject monitorObjectCandidate = monitorCandidate.getObject();

      if (monitorObjectCandidate != null) {
        JavaClass monitorClass = monitorObjectCandidate.getJavaClass();
        if (!SetupJavaMonitor_ObjectMonitors.monitorClassName.equals(monitorClass.getName())) {
          continue;
        }

        Iterator fields = monitorClass.getDeclaredFields().iterator();
View Full Code Here

  }
 
  public void testGetObject() throws Exception {
    for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
      JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
      JavaObject object = monitor.getObject();
     
      assertEquals("Monitor object class unexpected name.",setup.monitorClassName, object.getJavaClass().getName());
     
      JavaField idField = getJavaField(object, "id");
      String idString = idField.getString(object);
     
      assertEquals("MonitorClass id strings didn't match.", setup.monitorConfigs[i].id, idString);
View Full Code Here

      }

      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();
View Full Code Here

   
    return thisObject;   
  }
 
  public void testMaxIntegerValue() throws Exception {
    JavaObject thisJavaObject = getScenerioReference();
    JavaField maxIntegerField = getJavaField(thisJavaObject, "maxInteger");
   
    int maxIntegerValue = maxIntegerField.getInt(thisJavaObject);
   
    assertEquals(setup.maxInteger, maxIntegerValue);   
View Full Code Here

   
    assertEquals(setup.maxInteger, maxIntegerValue);   
  }
 
  public void testMinIntegerValue() throws Exception {
    JavaObject thisJavaObject = getScenerioReference();
    JavaField minIntegerField = getJavaField(thisJavaObject, "minInteger");
   
    int minIntegerValue = minIntegerField.getInt(thisJavaObject);
   
    assertEquals(setup.minInteger, minIntegerValue);   
View Full Code Here

TOP

Related Classes of javax.tools.diagnostics.runtime.java.JavaObject

Copyright © 2018 www.massapicom. 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.