diff --git a/dspace-api/src/test/java/org/dspace/content/CollectionTest.java b/dspace-api/src/test/java/org/dspace/content/CollectionTest.java index 850c3e3338..52c36e1d22 100644 --- a/dspace-api/src/test/java/org/dspace/content/CollectionTest.java +++ b/dspace-api/src/test/java/org/dspace/content/CollectionTest.java @@ -1961,6 +1961,8 @@ public class CollectionTest extends AbstractDSpaceObjectTest { //0 by default assertTrue("testCountItems 0", itemService.countItems(context, collection) == 0); + + //NOTE: a more thorough test of item counting is in ITCommunityCollection integration test } /** diff --git a/dspace-api/src/test/java/org/dspace/content/CommunityTest.java b/dspace-api/src/test/java/org/dspace/content/CommunityTest.java index b93d06229e..48d7745412 100644 --- a/dspace-api/src/test/java/org/dspace/content/CommunityTest.java +++ b/dspace-api/src/test/java/org/dspace/content/CommunityTest.java @@ -1480,7 +1480,9 @@ public class CommunityTest extends AbstractDSpaceObjectTest public void testCountItems() throws Exception { //0 by default - assertTrue("testCountItems 0", communityService.countItems(context, c) == 0); + assertTrue("testCountItems 0", itemService.countItems(context, c) == 0); + + //NOTE: a more thorough test of item counting is in ITCommunityCollection integration test } /** diff --git a/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java b/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java index 4925ba45e4..418fc2e781 100644 --- a/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java +++ b/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java @@ -125,35 +125,46 @@ public class ITCommunityCollection extends AbstractIntegrationTest /** * Tests that count items works as expected + * NOTE: Counts are currently expensive (take a while) */ @Test - @PerfTest(invocations = 25, threads = 1) + @PerfTest(invocations = 10, threads = 1) @Required(percentile95 = 2000, average= 1800) public void testCountItems() throws SQLException, AuthorizeException, IOException { - //make it an even number, not too high to reduce time during testing - int totalitems = 4; + int items_per_collection = 2; //we create the structure context.turnOffAuthorisationSystem(); - Community parent = communityService.create(null, context); - Community child1 = communityService.create(parent, context); + Community parentCom = communityService.create(null, context); + Community childCom = communityService.create(parentCom, context); - Collection col1 = collectionService.create(context, child1); - Collection col2 = collectionService.create(context, child1); + Collection col1 = collectionService.create(context, childCom); + Collection col2 = collectionService.create(context, childCom); - for(int count = 0; count < totalitems/2; count++) + // Add same number of items to each collection + for(int count = 0; count < items_per_collection; count++) { - Item item1 = installItemService.installItem(context, workspaceItemService.create(context, col1, false)); Item item2 = installItemService.installItem(context, workspaceItemService.create(context, col2, false)); } + + // Finally, let's throw in a small wrench and add a mapped item + // Add it to collection 1 + Item item3 = installItemService.installItem(context, workspaceItemService.create(context, col1, false)); + // Map it into collection 2 + collectionService.addItem(context, col2, item3); + + // Our total number of items should be + int totalitems = items_per_collection*2 + 1; + // Our collection counts should be + int collTotalItems = items_per_collection + 1; context.restoreAuthSystemState(); //verify it works as expected - assertThat("testCountItems 0", itemService.countItems(context, col1), equalTo(totalitems/2)); - assertThat("testCountItems 1", itemService.countItems(context, col2), equalTo(totalitems/2)); - assertThat("testCountItems 2", communityService.countItems(context, child1), equalTo(totalitems)); - assertThat("testCountItems 3", communityService.countItems(context, parent), equalTo(totalitems)); + assertThat("testCountItems 0", itemService.countItems(context, col1), equalTo(collTotalItems)); + assertThat("testCountItems 1", itemService.countItems(context, col2), equalTo(collTotalItems)); + assertThat("testCountItems 2", itemService.countItems(context, childCom), equalTo(totalitems)); + assertThat("testCountItems 3", itemService.countItems(context, parentCom), equalTo(totalitems)); } }