[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/marshall/data ...

Manik Surtani msurtani at jboss.com
Tue Aug 29 08:24:41 EDT 2006


  User: msurtani
  Date: 06/08/29 08:24:41

  Added:       tests/functional/org/jboss/cache/marshall/data   
                        Address.java Debug.java Person.java
  Log:
  Test data migrated to subpackage to reduce ambiguity
  
  Revision  Changes    Path
  1.1      date: 2006/08/29 12:24:41;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/marshall/data/Address.java
  
  Index: Address.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.marshall.data;
  
  import java.io.Serializable;
  
  
  /**
   */
  public class Address implements Serializable
  {
     String street = null;
     String city = "San Jose";
     int zip = 0;
  
     public Address()
     {
  
     }
  
     public String getStreet()
     {
        return street;
     }
  
     public void setStreet(String street)
     {
        this.street = street;
     }
  
     public String getCity()
     {
  //      System.out.println("********* getting city of " +city);
        return city;
     }
  
     public void setCity(String city)
     {
  //      System.out.println("********* setting city of " +city);
        this.city = city;
     }
  
     public int getZip()
     {
        return zip;
     }
  
     public void setZip(int zip)
     {
        this.zip = zip;
     }
  
     public String toString()
     {
        return "street=" + getStreet() + ", city=" + getCity() + ", zip=" + getZip();
     }
  
  //    public Object writeReplace() {
  //	return this;
  //    }
  
     public boolean equals(Object o)
     {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
  
        final Address address = (Address) o;
  
        if (zip != address.zip) return false;
        if (city != null ? !city.equals(address.city) : address.city != null) return false;
        if (street != null ? !street.equals(address.street) : address.street != null) return false;
  
        return true;
     }
  
     public int hashCode()
     {
        int result;
        result = (street != null ? street.hashCode() : 0);
        result = 29 * result + (city != null ? city.hashCode() : 0);
        result = 29 * result + zip;
        return result;
     }
  }
  
  
  
  1.1      date: 2006/08/29 12:24:41;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/marshall/data/Debug.java
  
  Index: Debug.java
  ===================================================================
  package org.jboss.cache.marshall.data;
  
  import java.lang.reflect.Method;
  import java.net.URL;
  import java.security.CodeSource;
  import java.security.ProtectionDomain;
  
  /**
   * Various debugging utility methods available for use in unit tests
   *
   * @author Scott.Stark at jboss.org
   */
  public class Debug
  {
     /**
      * Format a string buffer containing the Class, Interfaces, CodeSource,
      * and ClassLoader information for the given object clazz.
      *
      * @param clazz   the Class
      * @param results the buffer to write the info to
      */
     public static void displayClassInfo(Class clazz, StringBuffer results)
     {
        displayClassInfo(clazz, results, true);
     }
  
     public static void displayClassInfo(Class clazz, StringBuffer results,
                                         boolean showParentClassLoaders)
     {
  
        ClassLoader cl = clazz.getClassLoader();
        results.append("\n" + clazz.getName() + "(" + Integer.toHexString(clazz.hashCode()) + ").ClassLoader=" + cl);
        ClassLoader parent = cl;
        while (parent != null)
        {
           results.append("\n.." + parent);
           URL[] urls = getClassLoaderURLs(parent);
           int length = urls != null ? urls.length : 0;
           for (int u = 0; u < length; u ++)
           {
              results.append("\n...." + urls[u]);
           }
           if (showParentClassLoaders == false)
           {
              break;
           }
           if (parent != null)
           {
              parent = parent.getParent();
           }
        }
        CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource();
        if (clazzCS != null)
        {
           results.append("\n++++CodeSource: " + clazzCS);
        }
        else
        {
           results.append("\n++++Null CodeSource");
        }
  
        results.append("\nImplemented Interfaces:");
        Class[] ifaces = clazz.getInterfaces();
        for (int i = 0; i < ifaces.length; i ++)
        {
           Class iface = ifaces[i];
           results.append("\n++" + iface + "(" + Integer.toHexString(iface.hashCode()) + ")");
           ClassLoader loader = ifaces[i].getClassLoader();
           results.append("\n++++ClassLoader: " + loader);
           ProtectionDomain pd = ifaces[i].getProtectionDomain();
           CodeSource cs = pd.getCodeSource();
           if (cs != null)
           {
              results.append("\n++++CodeSource: " + cs);
           }
           else
           {
              results.append("\n++++Null CodeSource");
           }
        }
     }
  
     /**
      * Use reflection to access a URL[] getURLs or ULR[] getAllURLs method so
      * that non-URLClassLoader class loaders, or class loaders that override
      * getURLs to return null or empty, can provide the true classpath info.
      */
     public static URL[] getClassLoaderURLs(ClassLoader cl)
     {
        URL[] urls = {};
        try
        {
           Class returnType = urls.getClass();
           Class[] parameterTypes = {};
           Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
           if (returnType.isAssignableFrom(getURLs.getReturnType()))
           {
              Object[] args = {};
              urls = (URL[]) getURLs.invoke(cl, args);
           }
        }
        catch (Exception ignore)
        {
        }
        return urls;
     }
  
  }
  
  
  
  1.1      date: 2006/08/29 12:24:41;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/marshall/data/Person.java
  
  Index: Person.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.marshall.data;
  
  import java.io.Serializable;
  
  
  /**
   */
  public class Person implements Serializable
  {
     String name = null;
     Address address;
  
     public Person()
     {
     }
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
  
     public void setName(Object obj)
     {
        this.name = (String) obj;
     }
  
     public Address getAddress()
     {
        return address;
     }
  
     public void setAddress(Address address)
     {
        this.address = address;
     }
  
     public String toString()
     {
        StringBuffer sb = new StringBuffer();
        sb.append("name=").append(getName()).append(" Address= ").append(address);
        return sb.toString();
     }
  
     public boolean equals(Object o)
     {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
  
        final Person person = (Person) o;
  
        if (address != null ? !address.equals(person.address) : person.address != null) return false;
        if (name != null ? !name.equals(person.name) : person.name != null) return false;
  
        return true;
     }
  
     public int hashCode()
     {
        int result;
        result = (name != null ? name.hashCode() : 0);
        result = 29 * result + (address != null ? address.hashCode() : 0);
        return result;
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list