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));
}
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;
}
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");
}
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");
}
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));
}
Aggregations