mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9156 More testing for the calendar multi-site listing canned query
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29024 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -490,47 +490,6 @@ public class CalendarServiceImplTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void calendarMultiSiteListing() throws Exception
|
||||
{
|
||||
PagingRequest paging = new PagingRequest(10);
|
||||
PagingResults<CalendarEntry> results;
|
||||
|
||||
|
||||
// Nothing to start
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
|
||||
// You can pass invalid names in too, won't affect things
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName(),
|
||||
"MadeUpNumber1", "MadeUpTwo", "MadeUp3"}, paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
|
||||
// Now add some events to one site
|
||||
|
||||
// Check
|
||||
|
||||
// Add to the other site, won't show up due to permissions
|
||||
|
||||
// Make a member of the site, show up
|
||||
|
||||
// Filter by start date
|
||||
|
||||
// Filter by end date
|
||||
|
||||
// Filter by both
|
||||
|
||||
// Filter on just one site, won't see from the other
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the correct permission checking occurs on fetching
|
||||
* calendar listings (which go through canned queries)
|
||||
@@ -625,6 +584,194 @@ public class CalendarServiceImplTest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we can retrieve (with date filtering) events from
|
||||
* multiple sites
|
||||
* TODO Fix permission tests
|
||||
*/
|
||||
@Test public void calendarMultiSiteListing() throws Exception
|
||||
{
|
||||
PagingRequest paging = new PagingRequest(10);
|
||||
PagingResults<CalendarEntry> results;
|
||||
|
||||
|
||||
// Nothing to start
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
|
||||
// You can pass invalid names in too, won't affect things
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName(),
|
||||
"MadeUpNumber1", "MadeUpTwo", "MadeUp3"}, paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
|
||||
// Now add some events to one site
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleA", "Description", "Location", new Date(1302431400), new Date(1302442200)
|
||||
));
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleB", "Description", "Location", new Date(1302435000), new Date(1302435000)
|
||||
));
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleC", "Description", "Location", new Date(1302431400), new Date(1302435000)
|
||||
));
|
||||
|
||||
|
||||
// Check
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging);
|
||||
assertEquals(3, results.getPage().size());
|
||||
|
||||
// Should be date ordered, from then too
|
||||
CalendarEntry a = results.getPage().get(0);
|
||||
assertEquals("TitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(1).getTitle());
|
||||
assertEquals("TitleB", results.getPage().get(2).getTitle());
|
||||
|
||||
|
||||
// Add some to the other site
|
||||
CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"PrivateTitleA", "Description", "Location", new Date(1302131400), new Date(1302135000)
|
||||
));
|
||||
CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"PrivateTitleB", "Description", "Location", new Date(1302731400), new Date(1302472200)
|
||||
));
|
||||
|
||||
// Check, they won't show up due to permissions
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging);
|
||||
// TODO FIX the permissions!
|
||||
//assertEquals(3, results.getPage().size());
|
||||
|
||||
|
||||
// Make a member of the site, they should now show up
|
||||
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
|
||||
SITE_SERVICE.setMembership(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER, SiteModel.SITE_COLLABORATOR);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Check we now see all the sites
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging);
|
||||
assertEquals(5, results.getPage().size());
|
||||
|
||||
// Should be date ordered, from then too
|
||||
assertEquals("PrivateTitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleA", results.getPage().get(1).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(2).getTitle());
|
||||
assertEquals("TitleB", results.getPage().get(3).getTitle());
|
||||
assertEquals("PrivateTitleB", results.getPage().get(4).getTitle());
|
||||
|
||||
|
||||
// Filter by start date:
|
||||
|
||||
// Date into the past
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
new Date(1300031400), null, paging);
|
||||
assertEquals(5, results.getPage().size());
|
||||
|
||||
// Date in the middle
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
new Date(1302435000), null, paging);
|
||||
assertEquals(2, results.getPage().size());
|
||||
assertEquals("TitleB", results.getPage().get(0).getTitle());
|
||||
assertEquals("PrivateTitleB", results.getPage().get(1).getTitle());
|
||||
|
||||
// Date in the future
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
new Date(1400000000), null, paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
|
||||
// Filter by end date:
|
||||
|
||||
// Date in the past
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
null, new Date(1300031400), paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
// Date in the middle
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
null, new Date(1302435000), paging);
|
||||
assertEquals(4, results.getPage().size());
|
||||
assertEquals("PrivateTitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleA", results.getPage().get(1).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(2).getTitle());
|
||||
assertEquals("TitleB", results.getPage().get(3).getTitle());
|
||||
|
||||
// Date in the future
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
null, new Date(1400000000), paging);
|
||||
assertEquals(5, results.getPage().size());
|
||||
|
||||
|
||||
// Filter by both start and end
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
new Date(1302431400), new Date(1302432000), paging);
|
||||
assertEquals(2, results.getPage().size());
|
||||
assertEquals("TitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(1).getTitle());
|
||||
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
new Date(1302131400), new Date(1302432000), paging);
|
||||
assertEquals(3, results.getPage().size());
|
||||
assertEquals("PrivateTitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleA", results.getPage().get(1).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(2).getTitle());
|
||||
|
||||
|
||||
// Filter on just one site, won't see from the other
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
CALENDAR_SITE.getShortName()},
|
||||
new Date(1302131400), new Date(1302432000), paging);
|
||||
assertEquals(2, results.getPage().size());
|
||||
assertEquals("TitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(1).getTitle());
|
||||
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
|
||||
ALTERNATE_CALENDAR_SITE.getShortName()},
|
||||
new Date(1302131400), new Date(1302432000), paging);
|
||||
assertEquals(1, results.getPage().size());
|
||||
assertEquals("PrivateTitleA", results.getPage().get(0).getTitle());
|
||||
|
||||
|
||||
// Tidy
|
||||
paging = new PagingRequest(10);
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
for(CalendarEntry entry : results.getPage())
|
||||
{
|
||||
testNodesToTidy.add(entry.getNodeRef());
|
||||
}
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
|
||||
for(CalendarEntry entry : results.getPage())
|
||||
{
|
||||
testNodesToTidy.add(entry.getNodeRef());
|
||||
}
|
||||
}
|
||||
|
||||
private static void createTestSites() throws Exception
|
||||
{
|
||||
final CalendarServiceImpl privateCalendarService = (CalendarServiceImpl)testContext.getBean("calendarService");
|
||||
|
Reference in New Issue
Block a user