Junit4 : expected=Exception not working with SPRING

Hello,

I'm trying to use the @Test(expected = RuntimeException.class) annotation in order to test for an expected exception. My code is as follows:

@Test(expected = RuntimeException.class)
public void testSaveThrowsRuntimeException(){

User user = domain.save(null);

}

and my save method simple like this :
public User save(User newUser) {
if(newUser == null) {
throw new RuntimeException();
}
//saving code goes here
}

after debugging the code I found that code throwing the exception as expected but its getting eaten somewhere in between in spring framework classes.

I tried the same with old way (try catch block) but still I am not able to catch that exception in test and test keeps throwing errors in runafter method of Junit :
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1031)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:504)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:277)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:170)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:344)
at org.springframework.test.context.junit4.SpringMethodRoadie.runAfters(SpringMethodRoadie.java:307)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:338)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.transaction.RollbackException
at org.objectweb.jotm.TransactionImpl.commit(TransactionImpl.java:245)
at org.objectweb.jotm.Current.commit(Current.java:488)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1028)
... 23 more

And I am sure this is because of that RuntimeException I am throwing in save but not able catch it or pass the test with expected clause.

anybody have any idea whats going wrong?

Thanks in advance,

Posted at at 2:26 AM on Friday, July 24, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: ,

viewing firefox cache

Firefox has a nice way to view files that are in both your memory and file cache. In the Address Bar, type – about:cache. This will take you to a page that allows you to view a summary of your browser cache and also will allow you to browse the files stored in the cache.
Hit this link to change Firefox cache location.

Posted at at 2:26 AM on Tuesday, July 24, 2007 by Posted by Ravindra Nikam | 0 comments   | Filed under: ,

FTP command-line options

This is a list of the commands available when using the Microsoft Windows command-line FTP client :

Command-line options

As you're starting the program from a DOS prompt:
ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]
-v - Suppresses verbose display of remote server responses.
-n - Suppresses auto-login upon initial connection.
-i - Turns off interactive prompting during multiple file transfers.
-d - Enables debugging, displaying all ftp commands passed between the client and server.
-g - Disables filename globbing, which permits the use of wildcard chracters in local file and path names.
-s:filename - Specifies a text file containing ftp commands; the commands will automatically run after ftp starts. No spaces are allowed in this parameter. Use this switch instead of redirection (>).
-a - Use any local interface when binding data connection.
-w:windowsize - Overrides the default transfer buffer size of 4096.
computer - Specifies the computer name or IP address of the remote computer to connect to. The computer, if specified, must be the last parameter on the line.

Client commands

! - Runs the specified command on the local computer
? - Displays descriptions for ftp commands
append - Appends a local file to a file on the remote computer
ascii - Sets the file transfer type to ASCII, the default
bell - Toggles a bell to ring after each file transfer command is completed (default = OFF)
binary - Sets the file transfer type to binary
bye - Ends the FTP session and exits ftp
cd - Changes the working directory on the remote computer
close - Ends the FTP session and returns to the command interpreter
debug - Toggles debugging (default = OFF)
delete - Deletes a single file on a remote computer
dir - Displays a list of a remote directory's files and subdirectories
disconnect - Disconnects from the remote computer, retaining the ftp prompt
get - Copies a single remote file to the local computer
glob - Toggles filename globbing (wildcard characters) (default = ON)
hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF)
help - Displays descriptions for ftp commands
lcd - Changes the working directory on the local computer
literal - Sends arguments, verbatim, to the remote FTP server
ls - Displays an abbreviated list of a remote directory's files and subdirectories
mdelete - Deletes one or more files on a remote computer
mdir - Displays a list of a remote directory's files and subdirectories
mget - Copies one or more remote files to the local computer
mkdir - Creates a remote directory
mls - Displays an abbreviated list of a remote directory's files and subdirectories
mput - Copies one or more local files to the remote computer
open - Connects to the specified FTP server
prompt - Toggles prompting (default = ON)
put - Copies a single local file to the remote computer
pwd - Displays the current directory on the remote computer (literally, "print working directory")
quit - Ends the FTP session with the remote computer and exits ftp (same as "bye")
quote - Sends arguments, verbatim, to the remote FTP server (same as "literal")
recv - Copies a remote file to the local computer
remotehelp - Displays help for remote commands
rename - Renames remote files
rmdir - Deletes a remote directory
send - Copies a local file to the remote computer (same as "put")
status - Displays the current status of FTP connections
trace - Toggles packet tracing (default = OFF)
type - Sets or displays the file transfer type (default = ASCII)
user - Specifes a user to the remote computer
verbose - Toggles verbose mode (default = ON)

For more : MSFTP

Posted at at 6:45 AM on Monday, February 12, 2007 by Posted by Ravindra Nikam | 0 comments   | Filed under: