Write a URL protocol-handler that receives web-service calls.
Se older entries:
Latest debugging techniques for Swing applications: From JavaZone 2008
Viser innlegg med etiketten testing. Vis alle innlegg
Viser innlegg med etiketten testing. Vis alle innlegg
mandag 16. november 2009
mandag 15. desember 2008
Regexp for logging of method calls
BeanShell macros (May be run in jEdit)
Copy and paste auto-generated method signature, and run this macro
Logging methods
Copy and paste auto-generated method signature, and run this macro
// rid of tabs, newlines and double spaces
strippSpace( String text ) {
text = text.replaceAll( "\\t" , " " );
text = text.replaceAll( "\\n?" , "" );
do {
text = text.replaceAll( " " , " " );
} while ( text.indexOf( " " ) > -1 );
return text;
}
// tidy up method call
cleanCall( String text ) {
text = text.replaceAll( "\\(\\s*" , "(\n\t" );
text = text.replaceAll( ",\\s*" , ",\n\t" );
text = text.replaceAll( "\\s*\\)\\s*" , "\n)" );
return text;
}
convertMethodSignature2SuperCall( String text ){
// 2 strings before )
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*\\)\\W*" , "$1 );" );
// 2 strings before comma
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*,\\W*" , "$1, " );
// 3 strings before (
text = text.replaceAll( "\\A\\s*\\w*\\s?void\\s?(\\w*)\\s*\\(" , "super.$1(" );
text = text.replaceAll( "\\A\\s*\\w*\\s?\\w*\\s?(\\w*)\\s*\\(" , "return super.$1(" );
return text;
}
convertMethodSignature2SillyReturn( String text ){
// 2 strings before )
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*\\)\\W*" , "$1 );" );
// 2 strings before comma
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*,\\W*" , "$1, " );
// 3 strings before (
text = text.replaceAll( "\\A\\s*\\w*\\s?void\\s?(\\w*)\\s*\\(" , "" );
text = text.replaceAll( "\\A\\s*\\w*\\s?(\\w*)\\s?(\\w*)\\s*\\(" , "return new $1();" );
return text;
}
convertMethodSignature2LogStatement( String text ){
// 2 strings before )
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*\\)\\W*" , "\n\t\tSEMAFOR_CALL \"$1\" SEMAFOR_COMMA $1 )\n\t);" );
// 2 strings before comma
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*,\\W*" , "\n\t\tSEMAFOR_CALL \"$1\" SEMAFOR_COMMA $1 )," );
// 3 strings before parenthesis
text = text.replaceAll( "\\A\\s*\\w*\\s?\\w*\\s?(\\w*)\\(" , "\tSEMAFOR_CALL \"$1\" ," );
// semafors
text = text.replaceAll( "SEMAFOR_COMMA" , "," );
text = text.replaceAll( "SEMAFOR_CALL" , "toXml(" );
return text;
}
String text = Macros.input(view,"Method call:");
if(text == null || "".equals(text))
return;
String text = strippSpace( text );
String superCall = convertMethodSignature2SuperCall( text );
String logCall = convertMethodSignature2LogStatement( text );
String call = cleanCall( text );
String res = call + "{\n" + logCall + "\n\t" + superCall + "\n}";
Registers.setRegister('HistoryModel.getModel("clipboard").addItem(res);
view.getStatus().setMessageAndClear("OK - result on clipboard");
Logging methods
public static String toXml( String name, Object value ) {
// FixMe: escape xml special characters
if ( value == null )
value = "";
return "\t<" + name + ">" + value.toString() + "";
}
/** */
public static String toXml( String method, String... items ) {
String msg = "";
if ( items != null && 0 < msg = "<">" + msg + "";
System.out.println( msg );
return msg;
},res);
HistoryModel.getModel("clipboard").addItem(res);
view.getStatus().setMessageAndClear("OK - result on clipboard");
Logging methods
public static String toXml( String name, Object value ) {
// FixMe: escape xml special characters
if ( value == null )
value = "";
return "\t<" + name + ">" + value.toString() + "";
}
/** */
public static String toXml( String method, String... items ) {
String msg = "";
if ( items != null && 0 < msg = "<">" + msg + "";
System.out.println( msg );
return msg;
}
torsdag 8. mai 2008
JNDI in JUnit tests
Sun har også en provider som kan brukes - se jndi-tutorial.
I ended up using Simple-JNDI - simple-jndi, thanks to:
James Strachan's Weblog
Injecting Constants as Spring Bean Properties | Unicon
java.naming.factory.initial=org.osjava.sj.SimpleContextFactory
org.osjava.sj.root=${project.build.directory}\\test-classes\\jndi
org.osjava.sj.colon.replace=--
org.osjava.sj.delimiter=/
src/test/resources/jndi/java--comp/env/jdbc/ds.properties:
type=javax.sql.DataSource
driver=oracle.jdbc.OracleDriver
url=${db.url}
user=${db.user}
password=${db.password}
I ended up using Simple-JNDI - simple-jndi, thanks to:
James Strachan's Weblog
Injecting Constants as Spring Bean Properties | Unicon
My setup for lookup-key "java:comp/env/jdbc/ds":
jndi.properties:java.naming.factory.initial=org.osjava.sj.SimpleContextFactory
org.osjava.sj.root=${project.build.directory}\\test-classes\\jndi
org.osjava.sj.colon.replace=--
org.osjava.sj.delimiter=/
src/test/resources/jndi/java--comp/env/jdbc/ds.properties:
type=javax.sql.DataSource
driver=oracle.jdbc.OracleDriver
url=${db.url}
user=${db.user}
password=${db.password}
Abonner på:
Innlegg (Atom)