HHH-6697 Added test case.

This commit is contained in:
Michael Rudolf 2011-09-29 21:03:37 +02:00 committed by Strong Liu
parent d76358cd03
commit 3bd95da6c5
1 changed files with 35 additions and 0 deletions

View File

@ -32,9 +32,11 @@ import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.FlushModeType;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.hibernate.FlushMode;
@ -234,6 +236,39 @@ public class EntityManagerTest extends TestCase {
em.close();
}
public void testPersistExisting() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
w.setModel( "Minimic" );
w.setSerial( "0100202002" );
em.persist( w );
w = new Wallet();
w.setBrand( "Lacoste" );
w.setModel( "Minimic" );
w.setSerial( "0100202002" );
try {
em.persist( w );
}
catch ( EntityExistsException eee ) {
//success
if ( em.getTransaction() != null ) {
em.getTransaction().rollback();
}
em.close();
return;
}
try {
em.getTransaction().commit();
fail( "Should have raised an exception" );
}
catch (PersistenceException pe) {}
finally {
em.close();
}
}
public void testSerializableException() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();