@Test
public void testWithPreferredVersion() throws Exception {
SearchResult result = null;
// Make sure the homepage doesn't get into our way
repository.delete(new PageURIImpl(site, "/"), true);
SearchQuery workPreferredQuery = new SearchQueryImpl(site).withPreferredVersion(WORK).sortByCreationDate(Order.Ascending);
SearchQuery livePreferredQuery = new SearchQueryImpl(site).withPreferredVersion(LIVE).sortByCreationDate(Order.Ascending);
SearchQuery workOnlyQuery = new SearchQueryImpl(site).withVersion(WORK).sortByCreationDate(Order.Ascending);
SearchQuery liveOnlyQuery = new SearchQueryImpl(site).withVersion(LIVE).sortByCreationDate(Order.Ascending);
// Test empty repository
assertEquals(0, repository.find(workPreferredQuery).getDocumentCount());
assertEquals(0, repository.find(livePreferredQuery).getDocumentCount());
assertEquals(0, repository.find(workOnlyQuery).getDocumentCount());
assertEquals(0, repository.find(liveOnlyQuery).getDocumentCount());
// Create URI and pages and add them to the repository
ResourceURI liveOnlyURI = new PageURIImpl(site, "/liveonly", LIVE);
ResourceURI liveAndWorkLiveURI = new PageURIImpl(site, "/liveandwork", LIVE);
ResourceURI liveAndWorkWorkURI = new PageURIImpl(site, "/liveandwork", WORK);
ResourceURI workOnlyURI = new PageURIImpl(site, "/workonly", WORK);
Page liveOnly = new PageImpl(liveOnlyURI);
liveOnly.setTemplate(template.getIdentifier());
Page liveAndWorkLive = new PageImpl(liveAndWorkLiveURI);
liveAndWorkLive.setTemplate(template.getIdentifier());