use of org.xwiki.query.QueryManager in project xwiki-platform by xwiki.
the class SolrQueryExecutorTest method testExecutorRegistration.
@Test
public void testExecutorRegistration() throws Exception {
QueryManager queryManager = this.componentManager.getInstance(QueryManager.class);
Assert.assertTrue(queryManager.getLanguages().contains(SolrQueryExecutor.SOLR));
}
use of org.xwiki.query.QueryManager in project xwiki-platform by xwiki.
the class DatabaseDocumentIteratorTest method iterateOneWiki.
@Test
public void iterateOneWiki() throws Exception {
DocumentReference rootReference = createDocumentReference("gang", Arrays.asList("A", "B"), "C", null);
Query emptyQuery = mock(Query.class);
when(emptyQuery.execute()).thenReturn(Collections.emptyList());
Query query = mock(Query.class);
when(query.setLimit(anyInt())).thenReturn(query);
when(query.setWiki(rootReference.getWikiReference().getName())).thenReturn(query);
when(query.setOffset(0)).thenReturn(query);
when(query.setOffset(100)).thenReturn(emptyQuery);
when(query.execute()).thenReturn(Collections.<Object>singletonList(new Object[] { "A.B", "C", "de", "3.1" }));
Map<String, Object> namedParameters = new HashMap<String, Object>();
namedParameters.put("space", "A.B");
namedParameters.put("name", "C");
when(query.getNamedParameters()).thenReturn(namedParameters);
Query countQuery = mock(Query.class);
when(countQuery.addFilter(mocker.<QueryFilter>getInstance(QueryFilter.class, "count"))).thenReturn(countQuery);
QueryManager queryManager = mocker.getInstance(QueryManager.class);
String whereClause = " where doc.space = :space and doc.name = :name";
when(queryManager.createQuery("select doc.space, doc.name, doc.language, doc.version from XWikiDocument doc" + whereClause + " order by doc.space, doc.name, doc.language", Query.HQL)).thenReturn(query);
when(queryManager.createQuery(whereClause, Query.HQL)).thenReturn(countQuery);
DocumentIterator<String> iterator = mocker.getComponentUnderTest();
iterator.setRootReference(rootReference);
List<Pair<DocumentReference, String>> actualResults = new ArrayList<Pair<DocumentReference, String>>();
while (iterator.hasNext()) {
actualResults.add(iterator.next());
}
List<Pair<DocumentReference, String>> expectedResults = new ArrayList<Pair<DocumentReference, String>>();
expectedResults.add(new ImmutablePair<DocumentReference, String>(new DocumentReference(rootReference, Locale.GERMAN), "3.1"));
assertEquals(expectedResults, actualResults);
verify(query).bindValue("space", "A.B");
verify(query).bindValue("name", "C");
verify(countQuery).bindValue("space", "A.B");
verify(countQuery).bindValue("name", "C");
}
use of org.xwiki.query.QueryManager in project xwiki-platform by xwiki.
the class MessageStreamTest method setupForLimitQueries.
private void setupForLimitQueries(final int expectedLimit, final int expectedOffset) throws ComponentLookupException, Exception {
final Query mockQuery = getMockQuery();
final QueryManager mockQueryManager = getComponentManager().getInstance(QueryManager.class);
final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class);
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
final EntityReferenceSerializer<String> mockSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
getMockery().checking(new Expectations() {
{
allowing(mockBridge).getCurrentUserReference();
will(returnValue(MessageStreamTest.this.currentUser));
allowing(mockSerializer).serialize(MessageStreamTest.this.currentUser);
will(returnValue("wiki:XWiki.JohnDoe"));
exactly(1).of(mockQuery).setLimit(expectedLimit);
will(returnValue(mockQuery));
exactly(1).of(mockQuery).setOffset(expectedOffset);
will(returnValue(mockQuery));
allowing(mockQuery).bindValue(with(any(String.class)), with("wiki:XWiki.JohnDoe"));
allowing(mockQueryManager).createQuery(with(aNonNull(String.class)), with(aNonNull(String.class)));
will(returnValue(mockQuery));
exactly(1).of(mockEventStream).searchEvents(with(mockQuery));
will(returnValue(null));
}
});
}
use of org.xwiki.query.QueryManager in project xwiki-platform by xwiki.
the class DatabaseDocumentIteratorTest method iterateAllWikis.
@Test
public void iterateAllWikis() throws Exception {
Query emptyQuery = mock(Query.class);
when(emptyQuery.execute()).thenReturn(Collections.emptyList());
Query chessQuery = mock(Query.class);
when(chessQuery.setOffset(0)).thenReturn(chessQuery);
when(chessQuery.setOffset(100)).thenReturn(emptyQuery);
when(chessQuery.execute()).thenReturn(Arrays.<Object>asList(new Object[] { "Blog.Code", "WebHome", "", "3.2" }, new Object[] { "Main", "Welcome", "en", "1.1" }, new Object[] { "XWiki.Syntax", "Links", "fr", "2.5" }));
DocumentReference chessBlogCodeWebHome = createDocumentReference("chess", Arrays.asList("Blog", "Code"), "WebHome", null);
DocumentReference chessMainWelcome = createDocumentReference("chess", Arrays.asList("Main"), "Welcome", Locale.ENGLISH);
DocumentReference chessXWikiSyntaxLinks = createDocumentReference("chess", Arrays.asList("XWiki", "Syntax"), "Links", Locale.FRENCH);
Query tennisQuery = mock(Query.class);
when(tennisQuery.setOffset(0)).thenReturn(tennisQuery);
when(tennisQuery.setOffset(100)).thenReturn(emptyQuery);
when(tennisQuery.execute()).thenReturn(Arrays.<Object>asList(new Object[] { "Main", "Welcome", "en", "2.1" }, new Object[] { "XWiki.Syntax", "Links", "fr", "1.3" }));
DocumentReference tennisMainWelcome = createDocumentReference("tennis", Arrays.asList("Main"), "Welcome", Locale.ENGLISH);
DocumentReference tennisXWikiSyntaxLinks = createDocumentReference("tennis", Arrays.asList("XWiki", "Syntax"), "Links", Locale.FRENCH);
Query query = mock(Query.class);
when(query.setLimit(anyInt())).thenReturn(query);
when(query.getNamedParameters()).thenReturn(Collections.<String, Object>emptyMap());
when(query.setWiki("chess")).thenReturn(chessQuery);
when(query.setWiki("tennis")).thenReturn(tennisQuery);
Query chessCountQuery = mock(Query.class);
when(chessCountQuery.execute()).thenReturn(Collections.<Object>singletonList(3L));
Query tennisCountQuery = mock(Query.class);
when(tennisCountQuery.execute()).thenReturn(Collections.<Object>singletonList(2L));
Query countQuery = mock(Query.class);
when(countQuery.addFilter(mocker.<QueryFilter>getInstance(QueryFilter.class, "count"))).thenReturn(countQuery);
when(countQuery.setWiki("chess")).thenReturn(chessCountQuery);
when(countQuery.setWiki("tennis")).thenReturn(tennisCountQuery);
QueryManager queryManager = mocker.getInstance(QueryManager.class);
when(queryManager.createQuery("select doc.space, doc.name, doc.language, doc.version from XWikiDocument doc" + " order by doc.space, doc.name, doc.language", Query.HQL)).thenReturn(query);
when(queryManager.createQuery("", Query.HQL)).thenReturn(countQuery);
DocumentIterator<String> iterator = mocker.getComponentUnderTest();
assertEquals(5L, iterator.size());
List<Pair<DocumentReference, String>> actualResults = new ArrayList<Pair<DocumentReference, String>>();
while (iterator.hasNext()) {
actualResults.add(iterator.next());
}
List<Pair<DocumentReference, String>> expectedResults = new ArrayList<Pair<DocumentReference, String>>();
expectedResults.add(new ImmutablePair<DocumentReference, String>(chessBlogCodeWebHome, "3.2"));
expectedResults.add(new ImmutablePair<DocumentReference, String>(chessMainWelcome, "1.1"));
expectedResults.add(new ImmutablePair<DocumentReference, String>(chessXWikiSyntaxLinks, "2.5"));
expectedResults.add(new ImmutablePair<DocumentReference, String>(tennisMainWelcome, "2.1"));
expectedResults.add(new ImmutablePair<DocumentReference, String>(tennisXWikiSyntaxLinks, "1.3"));
assertEquals(expectedResults, actualResults);
}
use of org.xwiki.query.QueryManager in project xwiki-platform by xwiki.
the class ClassSheetBinderTest method setUp.
@Before
public void setUp() throws Exception {
sheetBindingsQuery = mock(Query.class);
QueryManager queryManager = mocker.getInstance(QueryManager.class);
// This is called when the component is initialized.
when(queryManager.createQuery(any(), any())).thenReturn(sheetBindingsQuery);
}
Aggregations