mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-09 02:54:20 +00:00
port PR 1867
This commit is contained in:
@@ -223,6 +223,124 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
assertFalse("testFindBySubmitter 3", all.hasNext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of findInArchiveOrWithdrawnDiscoverableModifiedSince method, of class Item.
|
||||
*/
|
||||
@Test
|
||||
public void testFindInArchiveOrWithdrawnDiscoverableModifiedSince() throws Exception {
|
||||
// Init item to be both withdrawn and discoverable
|
||||
it.setWithdrawn(true);
|
||||
it.setArchived(false);
|
||||
it.setDiscoverable(true);
|
||||
// Test 0: Using a future 'modified since' date, we should get non-null list, with no items
|
||||
Iterator<Item> all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
boolean added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 1: we should NOT find our item in this list
|
||||
assertFalse("List should not contain item when passing a date newer than item last-modified date", added);
|
||||
// Test 2: Using a past 'modified since' date, we should get a non-null list containing our item
|
||||
all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),-1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 3: we should find our item in this list
|
||||
assertTrue("List should contain item when passing a date older than item last-modified date", added);
|
||||
// Repeat Tests 2, 3 with withdrawn = false and archived = true as this should result in same behaviour
|
||||
it.setWithdrawn(false);
|
||||
it.setArchived(true);
|
||||
// Test 4: Using a past 'modified since' date, we should get a non-null list containing our item
|
||||
all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),-1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 5: We should find our item in this list
|
||||
assertTrue("List should contain item when passing a date older than item last-modified date", added);
|
||||
// Test 6: Make sure non-discoverable items are not returned, regardless of archived/withdrawn state
|
||||
it.setDiscoverable(false);
|
||||
all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),-1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 7: We should not find our item in this list
|
||||
assertFalse("List should not contain non-discoverable items", added);
|
||||
}
|
||||
/**
|
||||
* Test of findInArchiveOrWithdrawnNonDiscoverableModifiedSince method, of class Item.
|
||||
*/
|
||||
@Test
|
||||
public void testFindInArchiveOrWithdrawnNonDiscoverableModifiedSince() throws Exception {
|
||||
// Init item to be both withdrawn and discoverable
|
||||
it.setWithdrawn(true);
|
||||
it.setArchived(false);
|
||||
it.setDiscoverable(false);
|
||||
// Test 0: Using a future 'modified since' date, we should get non-null list, with no items
|
||||
Iterator<Item> all = itemService.findInArchiveOrWithdrawnNonDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
boolean added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 1: We should NOT find our item in this list
|
||||
assertFalse("List should not contain item when passing a date newer than item last-modified date", added);
|
||||
// Test 2: Using a past 'modified since' date, we should get a non-null list containing our item
|
||||
all = itemService.findInArchiveOrWithdrawnNonDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),-1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 3: We should find our item in this list
|
||||
assertTrue("List should contain item when passing a date older than item last-modified date", added);
|
||||
// Repeat Tests 2, 3 with discoverable = true
|
||||
it.setDiscoverable(true);
|
||||
// Test 4: Now we should still get a non-null list with NO items since item is discoverable
|
||||
all = itemService.findInArchiveOrWithdrawnNonDiscoverableModifiedSince(context,
|
||||
DateUtils.addDays(it.getLastModified(),-1));
|
||||
assertThat("Returned list should not be null", all, notNullValue());
|
||||
added = false;
|
||||
while (all.hasNext()) {
|
||||
Item tmp = all.next();
|
||||
if (tmp.equals(it)) {
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
// Test 5: We should NOT find our item in this list
|
||||
assertFalse("List should not contain discoverable items", added);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getID method, of class Item.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user