Skip to content

Commit 2d60931

Browse files
milanmajchrakclaude
andcommitted
test: use explicit handles the sequence can never mint
RequiredMetadataIT and ItemHandleCheckerIT planted a random numeric handle (1000-1999) that handle_seq reaches late in the module run; the sequence mint path does no existence check, so the flush of whichever test was minting at that moment died on the handle unique index. Replace the random handles with deterministic non-numeric suffixes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b0c4850 commit 2d60931

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

dspace-api/src/test/java/org/dspace/curate/ItemHandleCheckerIT.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.IOException;
2020
import java.sql.SQLException;
2121
import java.util.List;
22-
import java.util.Random;
2322

2423
import okhttp3.mockwebserver.Dispatcher;
2524
import okhttp3.mockwebserver.MockResponse;
@@ -58,7 +57,9 @@
5857
public class ItemHandleCheckerIT extends AbstractIntegrationTestWithDatabase {
5958
private static final String TASK_NAME = "checkhandles";
6059

61-
private static final String HANDLE_COLLECTION = "123456789/" + randomString();
60+
// Non-numeric suffix the handle sequence can never mint, unique to this class so it cannot
61+
// clash with leftover handle rows of other tests either.
62+
private static final String HANDLE_COLLECTION = "123456789/handle-checker-test";
6263

6364
private static final String HANDLE_ITEM1 = HANDLE_COLLECTION + "-1";
6465
private static final String HANDLE_ITEM2 = HANDLE_COLLECTION + "-2";
@@ -280,10 +281,4 @@ private String getIdentifierUri(Item item) {
280281
private List<MetadataValue> getIdentifierUris(Item item) {
281282
return itemService.getMetadata(item, "dc", "identifier", "uri", Item.ANY);
282283
}
283-
284-
private static String randomString() {
285-
Random r = new Random();
286-
// Generate random integers in range 1000 to 1999
287-
return String.valueOf(1000 + r.nextInt(1000));
288-
}
289284
}

dspace-api/src/test/java/org/dspace/curate/RequiredMetadataIT.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import java.io.IOException;
1717
import java.sql.SQLException;
18-
import java.util.Random;
1918

2019
import org.dspace.AbstractIntegrationTestWithDatabase;
2120
import org.dspace.authorize.AuthorizeException;
@@ -44,7 +43,9 @@
4443
public class RequiredMetadataIT extends AbstractIntegrationTestWithDatabase {
4544
private static final String TASK_NAME = "requiredmetadata";
4645

47-
private static final String HANDLE_COLLECTION = "123456789/" + randomString();
46+
// Non-numeric suffix the handle sequence can never mint, unique to this class so it cannot
47+
// clash with leftover handle rows of other tests either.
48+
private static final String HANDLE_COLLECTION = "123456789/required-metadata-test";
4849
private static final String HANDLE_ITEM1 = HANDLE_COLLECTION + "-1";
4950
private static final String HANDLE_ITEM2 = HANDLE_COLLECTION + "-2";
5051
private static final String HANDLE_ITEM3 = HANDLE_COLLECTION + "-3";
@@ -154,10 +155,4 @@ private static String successResultForItem(Item item) {
154155
return "Item: " + item.getHandle() + " has all required fields";
155156
}
156157

157-
private static String randomString() {
158-
Random r = new Random();
159-
// Generate random integers in range 1000 to 1999
160-
return String.valueOf(1000 + r.nextInt(1000));
161-
}
162-
163158
}

dspace-api/src/test/java/org/dspace/xmlworkflow/XmlWorkflowFactoryTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public void init() {
7070
this.owningCommunity = communityService.create(null, context);
7171
this.mappedCollection =
7272
this.collectionService.create(context, owningCommunity, "123456789/workflow-test-1");
73-
this.nonMappedCollection = this.collectionService.create(context, owningCommunity, "123456789/999");
73+
// Non-numeric suffix so the handle sequence can never mint a colliding handle
74+
this.nonMappedCollection =
75+
this.collectionService.create(context, owningCommunity, "123456789/workflow-test-2");
7476
//we need to commit the changes so we don't block the table for testing
7577
context.restoreAuthSystemState();
7678
} catch (SQLException e) {

0 commit comments

Comments
 (0)