Search in sources :

Example 6 with DefaultQuery

use of org.xwiki.query.internal.DefaultQuery in project xwiki-platform by xwiki.

the class HqlQueryExecutorTest method execute.

private void execute(String statement, Boolean withProgrammingRights) throws QueryException {
    this.hasProgrammingRight = withProgrammingRights != null ? withProgrammingRights : true;
    DefaultQuery query = new DefaultQuery(statement, Query.HQL, this.executor);
    if (withProgrammingRights != null) {
        query.checkCurrentAuthor(true);
    }
    this.executor.execute(query);
}
Also used : DefaultQuery(org.xwiki.query.internal.DefaultQuery)

Example 7 with DefaultQuery

use of org.xwiki.query.internal.DefaultQuery in project xwiki-platform by xwiki.

the class HqlQueryExecutorTest method executeNamed.

private void executeNamed(String name, Boolean withProgrammingRights) throws QueryException {
    this.hasProgrammingRight = withProgrammingRights;
    DefaultQuery query = new DefaultQuery(name, this.executor);
    if (withProgrammingRights != null) {
        query.checkCurrentAuthor(true);
    }
    this.executor.execute(query);
}
Also used : DefaultQuery(org.xwiki.query.internal.DefaultQuery)

Example 8 with DefaultQuery

use of org.xwiki.query.internal.DefaultQuery in project xwiki-platform by xwiki.

the class SolrQueryExecutorTest method testMultiValuedQueryArgs.

@Test
public void testMultiValuedQueryArgs() throws Exception {
    when(solr.query(any(SolrQuery.class))).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            SolrQuery solrQuery = (SolrQuery) invocation.getArguments()[0];
            Assert.assertArrayEquals(ITERABLE_PARAM_EXPECTED, solrQuery.getParams(ITERABLE_PARAM_NAME));
            Assert.assertArrayEquals(INT_ARR_PARAM_EXPECTED, solrQuery.getParams(INT_ARR_PARAM_NAME));
            Assert.assertArrayEquals(STR_ARR_PARAM_EXPECTED, solrQuery.getParams(STR_ARR_PARAM_NAME));
            Assert.assertEquals(SINGLE_PARAM_EXPECTED, solrQuery.get(SINGLE_PARAM_NAME));
            // Check that the default list of supported locales is taken from the wiki configuration.
            Assert.assertEquals("en,fr,de", solrQuery.get("xwiki.supportedLocales"));
            QueryResponse r = mock(QueryResponse.class);
            when(r.getResults()).thenReturn(new SolrDocumentList());
            return r;
        }
    });
    DefaultQuery query = new DefaultQuery("TestQuery", null);
    query.bindValue(ITERABLE_PARAM_NAME, ITERABLE_PARAM_VALUE);
    query.bindValue(INT_ARR_PARAM_NAME, INT_ARR_PARAM_VALUE);
    query.bindValue(STR_ARR_PARAM_NAME, STR_ARR_PARAM_VALUE);
    query.bindValue(SINGLE_PARAM_NAME, SINGLE_PARAM_VALUE);
    // The default list of supported locales should be taken from the wiki configuration.
    XWikiContext xcontext = this.oldCore.getXWikiContext();
    doReturn(Arrays.asList(Locale.ENGLISH, Locale.FRENCH, Locale.GERMAN)).when(this.oldCore.getSpyXWiki()).getAvailableLocales(xcontext);
    this.componentManager.getComponentUnderTest().execute(query);
}
Also used : DefaultQuery(org.xwiki.query.internal.DefaultQuery) InvocationOnMock(org.mockito.invocation.InvocationOnMock) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) XWikiContext(com.xpn.xwiki.XWikiContext) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Aggregations

DefaultQuery (org.xwiki.query.internal.DefaultQuery)8 Test (org.junit.Test)6 Query (org.xwiki.query.Query)4 SQLQuery (org.hibernate.SQLQuery)3 Session (org.hibernate.Session)3 QueryFilter (org.xwiki.query.QueryFilter)3 WrappingQuery (org.xwiki.query.WrappingQuery)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 HibernateSessionFactory (com.xpn.xwiki.store.hibernate.HibernateSessionFactory)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrParams (org.apache.solr.common.params.SolrParams)1 NamedSQLQueryDefinition (org.hibernate.engine.NamedSQLQueryDefinition)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1