/** * Tests the creation of identifiers with sequence numbers. * * @param prefix The prefix of the records to add. * @param count The number of records to add (in addition of the "main" one). */ private void addRecords(final String prefix, final int count) throws SQLException { assertEquals("The very first record added should not have any suffix.", prefix, addRecord(prefix)); for (int i=1; i<=count; i++) { assertEquals("Any record added after the first one should have a sequential number in suffix.", prefix + IdentifierGenerator.SEPARATOR + i, addRecord(prefix)); } }
addRecords("TD", 324); removeAndAddRecords("TD"); addRecords("OT", 30);
/** * Tries to remove a few pre-selected record, then add them again. */ private void removeAndAddRecords(final String prefix) throws SQLException { assertEquals(5, stmt.executeUpdate("DELETE FROM \"" + TABLE + "\" WHERE " + "ID='" + prefix + IdentifierGenerator.SEPARATOR + "4' OR " + "ID='" + prefix + IdentifierGenerator.SEPARATOR + "12' OR " + "ID='" + prefix + IdentifierGenerator.SEPARATOR + "32' OR " + "ID='" + prefix + IdentifierGenerator.SEPARATOR + "125' OR " + "ID='" + prefix + IdentifierGenerator.SEPARATOR + "224'")); assertEquals("12 is before 4 in alphabetical order.", prefix+"-12", addRecord(prefix)); assertEquals("125 is next to 12 in alphabetical order.", prefix+"-125", addRecord(prefix)); assertEquals("224 is before 32 in alphabetical order.", prefix+"-224", addRecord(prefix)); assertEquals("32 is before 4 in alphabetical order.", prefix+"-32", addRecord(prefix)); assertEquals("4 is last in alphabetical order.", prefix+"-4", addRecord(prefix)); } }