Search in sources :

Example 86 with Query

use of org.xwiki.query.Query in project xwiki-platform by xwiki.

the class DefaultDBListQueryBuilderTest method build.

@Test
public void build() throws Exception {
    DBListClass dbListClass = new DBListClass();
    DefaultParameterizedType dbListQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, DBListClass.class);
    QueryBuilder<DBListClass> explicitlyAllowedValuesQueryBuilder = this.mocker.getInstance(dbListQueryBuilderType, "explicitlyAllowedValues");
    QueryBuilder<DBListClass> implicitlyAllowedValuesQueryBuilder = this.mocker.getInstance(dbListQueryBuilderType, "implicitlyAllowedValues");
    Query explicitlyAllowedValuesQuery = mock(Query.class, "explicit");
    when(explicitlyAllowedValuesQueryBuilder.build(dbListClass)).thenReturn(explicitlyAllowedValuesQuery);
    Query implicitlyAllowedValuesQuery = mock(Query.class, "implicit");
    when(implicitlyAllowedValuesQueryBuilder.build(dbListClass)).thenReturn(implicitlyAllowedValuesQuery);
    assertSame(implicitlyAllowedValuesQuery, this.mocker.getComponentUnderTest().build(dbListClass));
    dbListClass.setSql("test");
    assertSame(explicitlyAllowedValuesQuery, this.mocker.getComponentUnderTest().build(dbListClass));
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) Query(org.xwiki.query.Query) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Example 87 with Query

use of org.xwiki.query.Query in project xwiki-platform by xwiki.

the class ImplicitlyAllowedValuesDBListQueryBuilderTest method assertQuery.

private Query assertQuery(String statement) throws Exception {
    Query query = mock(Query.class);
    when(this.queryManager.createQuery(statement, Query.HQL)).thenReturn(query);
    assertSame(query, this.mocker.getComponentUnderTest().build(this.dbListClass));
    return query;
}
Also used : Query(org.xwiki.query.Query)

Example 88 with Query

use of org.xwiki.query.Query in project xwiki-platform by xwiki.

the class ImplicitlyAllowedValuesDBListQueryBuilderTest method buildWithIdAndClassName.

@Test
public void buildWithIdAndClassName() throws Exception {
    this.dbListClass.setClassname("XWiki.XWikiUsers");
    this.dbListClass.setIdField("doc.name");
    Query query = assertQuery("select distinct doc.fullName as unfilterable0, doc.name " + "from XWikiDocument as doc, BaseObject as obj " + "where doc.fullName = obj.name and obj.className = :className and doc.fullName <> :templateName");
    verify(query).bindValue("className", "XWiki.XWikiUsers");
    verify(query).bindValue("templateName", "XWiki.XWikiUsersTemplate");
    this.dbListClass.setIdField("obj.className");
    assertQuery("select distinct doc.fullName as unfilterable0, obj.className " + "from XWikiDocument as doc, BaseObject as obj " + "where doc.fullName = obj.name and obj.className = :className and doc.fullName <> :templateName");
    this.dbListClass.setIdField("property");
    query = assertQuery("select distinct doc.fullName as unfilterable0, idProp.value " + "from XWikiDocument as doc, BaseObject as obj, StringProperty as idProp " + "where doc.fullName = obj.name and obj.className = :className and doc.fullName <> :templateName" + " and obj.id = idProp.id.id and idProp.id.name = :idProp");
    verify(query).bindValue("idProp", "property");
}
Also used : Query(org.xwiki.query.Query) Test(org.junit.Test)

Example 89 with Query

use of org.xwiki.query.Query in project xwiki-platform by xwiki.

the class ImplicitlyAllowedValuesDBListQueryBuilderTest method buildWithClassName.

@Test
public void buildWithClassName() throws Exception {
    this.dbListClass.setClassname("Blog.CategoryClass");
    Query query = assertQuery("select distinct doc.fullName from XWikiDocument as doc, BaseObject as obj" + " where doc.fullName = obj.name and obj.className = :className and doc.fullName <> :templateName");
    verify(query).bindValue("className", "Blog.CategoryClass");
    verify(query).bindValue("templateName", "Blog.CategoryTemplate");
}
Also used : Query(org.xwiki.query.Query) Test(org.junit.Test)

Example 90 with Query

use of org.xwiki.query.Query in project xwiki-platform by xwiki.

the class UsedValuesListQueryBuilderTest method buildForStringListProperty.

@Test
public void buildForStringListProperty() throws Exception {
    listClass.setMultiSelect(true);
    listClass.setRelationalStorage(false);
    Query query = mock(Query.class);
    when(this.queryManager.createQuery("select prop.textValue, count(*) as unfilterable0 " + "from BaseObject as obj, StringListProperty as prop " + "where obj.className = :className and obj.name <> :templateName" + " and prop.id.id = obj.id and prop.id.name = :propertyName " + "group by prop.textValue " + "order by count(*) desc", Query.HQL)).thenReturn(query);
    assertSame(query, this.mocker.getComponentUnderTest().build(listClass));
}
Also used : Query(org.xwiki.query.Query) Test(org.junit.Test)

Aggregations

Query (org.xwiki.query.Query)129 DocumentReference (org.xwiki.model.reference.DocumentReference)41 Test (org.junit.Test)39 QueryException (org.xwiki.query.QueryException)36 ArrayList (java.util.ArrayList)29 XWikiException (com.xpn.xwiki.XWikiException)18 QueryFilter (org.xwiki.query.QueryFilter)18 QueryManager (org.xwiki.query.QueryManager)18 XWikiContext (com.xpn.xwiki.XWikiContext)15 HashMap (java.util.HashMap)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 Map (java.util.Map)11 List (java.util.List)9 Before (org.junit.Before)9 SecureQuery (org.xwiki.query.SecureQuery)9 XWiki (com.xpn.xwiki.XWiki)8 BaseObject (com.xpn.xwiki.objects.BaseObject)8 SQLQuery (org.hibernate.SQLQuery)8 WikiReference (org.xwiki.model.reference.WikiReference)8 WrappingQuery (org.xwiki.query.WrappingQuery)8