* unique in the DB.
*/
public void testDuplicateInsertion() throws Exception
{
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
String name = "testDuplicateInsertion_" + System.currentTimeMillis();
String nameNew = "testDuplicateInsertion_New_" + System.currentTimeMillis();
db.open(databaseName, Database.OPEN_READ_WRITE);
//System.out.println("TEST: Database open");
// insert an object with UNIQUE field NAME="A site"
//System.out.println("TEST: Insert first object");
newSite(odmg, name, 2, 1);
// insert another object with UNIQUE field NAME="A site"
// This should not create a new object (UNIQUE fields conflict) but
// should resume gracefuly
//System.out.println("TEST: Insert second object, should fail");
try
{
newSite(odmg, name, 3, 2);
assertTrue("We should get a SqlException 'Violation of unique index'", false);
}
catch (Exception e)
{
// we wait for this exception
assertTrue(true);
}
// insert an object with new UNIQUE field NAME
// should always work
//System.out.println("TEST: Insert third object");
try
{
newSite(odmg, nameNew, 1, 2);
assertTrue(true);
}
catch (Exception e)
{
e.printStackTrace();
assertTrue("This exception should not happend: " + e.getMessage(), false);
throw e;
}
db.close();
//System.out.println("TEST: Database closed");
}