From: Bryan T. <tho...@us...> - 2007-11-30 21:53:45
|
Update of /cvsroot/cweb/junit-ext/src/java/junit/framework In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29190/src/java/junit/framework Modified Files: TestCase2.java Log Message: Work on the bigdata-GOM integration. Index: TestCase2.java =================================================================== RCS file: /cvsroot/cweb/junit-ext/src/java/junit/framework/TestCase2.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** TestCase2.java 31 Oct 2007 09:51:03 -0000 1.26 --- TestCase2.java 30 Nov 2007 21:53:39 -0000 1.27 *************** *** 1112,1156 **** /** ! * Returns a random but unique string of Unicode characters with a ! * maximum length of len and a minimum length. ! * ! * @param len The maximum length of the string. Each generated ! * literal will have a mean length of <code>len/2</code> and the ! * lengths will be distributed using a normal distribution (bell ! * curve). ! * ! * @param id A unique index used to obtain a unique string. ! * Typically this is a one up identifier. */ ! public String getRandomString( int len, int id ) ! { ! // final String data = "0123456789!@#$%^&*()`~-_=+[{]}\\|;:'\",<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; ! final String data = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; ! int[] order = getRandomOrder( data.length() ); ! ! int n = getNormalInt( len ); ! ! StringBuffer sb = new StringBuffer( n ); ! int index = 0; ! ! for( int i=0; i<n; i++ ) { ! sb.append( data.charAt( order[ index++ ] ) ); ! if( index == order.length ) { ! ! index = 0; ! ! } ! ! } ! ! sb.append( id ); ! return sb.toString(); } --- 1112,1158 ---- /** ! * Returns a random but unique string of Unicode characters with a maximum ! * length of len and a minimum length. Only alphanumeric characters are ! * present in the string so you can form a unique string by appending a ! * delimiter and an one-up counter. ! * ! * @param len ! * The maximum length of the string. Each generated literal will ! * have a mean length of <code>len/2</code> and the lengths ! * will be distributed using a normal distribution (bell curve). ! * ! * @param id ! * A unique index used to obtain a unique string. Typically this ! * is a one up identifier. */ + public String getRandomString(int len, int id) { ! // final String data = ! // "0123456789!@#$%^&*()`~-_=+[{]}\\|;:'\",<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; ! final String data = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; ! int[] order = getRandomOrder(data.length()); ! int n = getNormalInt(len); ! StringBuffer sb = new StringBuffer(n); ! int index = 0; ! for (int i = 0; i < n; i++) { ! sb.append(data.charAt(order[index++])); ! ! if (index == order.length) { ! ! index = 0; ! ! } ! ! } ! ! sb.append(id); ! ! return sb.toString(); } *************** *** 1169,1199 **** * An explicit NULL property value. */ ! ! final public static short NULL = 0; ! ! // /** ! // * A directed link to another generic object in the same store. ! // * ! // * @see LinkValue ! // */ ! // ! // final public static short LINK = 1; ! // ! // /** ! // * A BLOB (metadata that supports access to very large binary ! // * objects using a stream oriented API). ! // */ ! // ! // final public static short BLOB = 2; - /** - * The Java primitive type <em>boolean</em>. - * - * Note: Support for primitives recognizes the corresponding - * objects, e.g., {@link Boolean}, and special cases their - * serialization. This significantly reduces their the storage - * requirements. - */ - final public static short BOOLEAN = 20; final public static short BYTE = 21; --- 1171,1176 ---- * An explicit NULL property value. */ ! // final public static short NULL = 0; final public static short BOOLEAN = 20; final public static short BYTE = 21; *************** *** 1204,1207 **** --- 1181,1185 ---- final public static short FLOAT = 26; final public static short DOUBLE = 27; + final public static short STRING = 28; /** *************** *** 1209,1213 **** * Externalizable}). */ - final public static short OBJECT = 30; --- 1187,1190 ---- *************** *** 1215,1219 **** * Array of Java objects (but not Java primitives). */ - final public static short OBJECT_ARRAY = 31; --- 1192,1195 ---- *************** *** 1221,1225 **** * Array of Java primitives. */ - final public static short BOOLEAN_ARRAY = 40; final public static short BYTE_ARRAY = 41; --- 1197,1200 ---- *************** *** 1235,1238 **** --- 1210,1214 ---- // BLOB, BOOLEAN, BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, + STRING, OBJECT, // OBJECT_ARRAY, *************** *** 1245,1252 **** // FLOAT_ARRAY, // DOUBLE_ARRAY, ! NULL // Note: null at end to make easy to exclude. }; /** * For random characters. */ --- 1221,1262 ---- // FLOAT_ARRAY, // DOUBLE_ARRAY, ! // NULL // Note: null at end to make easy to exclude. }; /** + * Return the type code for the specified class. + * + * @param cls + * A class. + * @return The type code. + * + * @throws UnsupportedOperationException + * if the class is not one of those that is supported by + * {@link RandomType}. + */ + public int getType(Class cls) { + + if(cls==null) { + + throw new IllegalArgumentException(); + + } + + if(cls.equals(Boolean.class)) return BOOLEAN; + if(cls.equals(Byte.class)) return BYTE; + if(cls.equals(Character.class)) return CHAR; + if(cls.equals(Short.class)) return SHORT; + if(cls.equals(Integer.class)) return INT; + if(cls.equals(Long.class)) return LONG; + if(cls.equals(Float.class)) return FLOAT; + if(cls.equals(Double.class)) return DOUBLE; + if(cls.equals(String.class)) return STRING; + if(cls.equals(Object.class)) return OBJECT; + + throw new UnsupportedOperationException("class="+cls); + + } + + /** * For random characters. */ *************** *** 1256,1267 **** * Returns an object with a random type and random value. * ! * @param rnd The random# generator to use. * ! * @param allowNull When true, a null object reference may be ! * returned. * * @return The random object. */ - public Object nextObject( Random rnd, boolean allowNull ) { --- 1266,1277 ---- * Returns an object with a random type and random value. * ! * @param rnd ! * The random# generator to use. * ! * @param allowNull ! * When true, a null object reference may be returned. * * @return The random object. */ public Object nextObject( Random rnd, boolean allowNull ) { *************** *** 1274,1285 **** int type = types[ rnd.nextInt( range ) ]; Object obj = null; switch( type ) { ! case NULL: { ! return null; ! } case BOOLEAN: { obj = ( rnd.nextBoolean() --- 1284,1347 ---- int type = types[ rnd.nextInt( range ) ]; + + return nextObject( rnd, type , allowNull ); + + } + + /** + * Return an instance of the specified type with a random value. + * + * @param rnd + * The random number generator. + * + * @param cls + * The class of the random instance to be returned -or- + * <code>null</code> to return an instance of any of the + * classes that can be generated by this method. + * + * @param allowNull + * When true, a null object reference may be returned. + * + * @return The random object. + */ + public Object nextObject(Random rnd, Class cls, boolean allowNull) { + if(cls==null) { + + // random object type. + return nextObject(rnd, allowNull); + + } else { + + // specific object type. + return nextObject(rnd, getType(cls), allowNull); + + } + + } + + /** + * Return an instance of the specified type with a random value. + * + * @param rnd + * The random number generator. + * + * @param type + * One of the values declared by this class. + * + * @param allowNull + * When true, a null object reference may be returned. + * + * @return The random object. + */ + public Object nextObject( Random rnd, int type, boolean allowNull ) { + Object obj = null; switch( type ) { ! // case NULL: { ! // return null; ! // } case BOOLEAN: { obj = ( rnd.nextBoolean() *************** *** 1317,1320 **** --- 1379,1386 ---- break; } + case STRING: { + obj = getRandomString( 40, rnd.nextInt() ); + break; + } case OBJECT: { obj = getRandomString( 40, rnd.nextInt() ); *************** *** 1342,1346 **** } ! private RandomType _randomType = new RandomType(); /** --- 1408,1412 ---- } ! protected RandomType _randomType = new RandomType(); /** *************** *** 1670,1674 **** className.replace('.','/') + ".properties" ; ! // Try to load properties from the resource into // the new layer. This uses a helper method that --- 1736,1743 ---- className.replace('.','/') + ".properties" ; ! ! // Note: requires Java 1.5. ! // String resourceName = this.getClass().getSimpleName(); ! // Try to load properties from the resource into // the new layer. This uses a helper method that *************** *** 1676,1680 **** // file system, so that it can find the resource // in a JAR if necessary. ! log.info ( "Will try to read properties from resource: "+ --- 1745,1749 ---- // file system, so that it can find the resource // in a JAR if necessary. ! log.info ( "Will try to read properties from resource: "+ |