public void testGetQueryWithIdAndParentSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); dbtlc.setIdField("doc.name"); dbtlc.setParentField("doc.name"); assertEquals( "select distinct doc.name, doc.name, doc.name from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setParentField("obj.className"); assertEquals( "select distinct doc.name, doc.name, obj.className" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setParentField("property"); assertEquals( "select distinct doc.name, doc.name, doc.property from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setIdField("obj.className"); dbtlc.setParentField("doc.name"); assertEquals( "select distinct obj.className, obj.className, doc.name" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setParentField("obj.className"); assertEquals( "select distinct obj.className, obj.className, obj.className" + " from BaseObject as obj", dbtlc.getQuery(getContext())); dbtlc.setParentField("property"); assertEquals( "select distinct obj.className, obj.className, doc.property" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setIdField("property"); dbtlc.setParentField("doc.name"); assertEquals( "select distinct doc.property, doc.property, doc.name" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setParentField("obj.className"); assertEquals( "select distinct doc.property, doc.property, obj.className" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setParentField("property"); assertEquals( "select distinct doc.property, doc.property, doc.property" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setParentField("property2"); assertEquals( "select distinct doc.property, doc.property, doc.property2" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); }
public void testGetQueryWithSqlScriptSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); assertEquals("", dbtlc.getSql()); String sql = "select doc.name, doc.title, doc.creator from XWikiDocument as doc"; dbtlc.setSql(sql); assertEquals(sql, dbtlc.getQuery(getContext())); }
public void testGetQueryWithValueSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); dbtlc.setValueField("doc.name"); assertEquals( "select distinct doc.name, doc.name, doc.parent from XWikiDocument as doc", dbtlc.getQuery(getContext())); }
public void testGetQueryWithIdValueParentAndClassSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); dbtlc.setClassname("XWiki.XWikiUsers"); dbtlc.setIdField("doc.name"); dbtlc.setValueField("doc.name"); dbtlc.setParentField("doc.name"); assertEquals( "select distinct doc.name, doc.name, doc.name" + " from XWikiDocument as doc, BaseObject as obj" + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", dbtlc.getQuery(getContext())); dbtlc.setIdField("prop1"); dbtlc.setValueField("prop1"); dbtlc.setParentField("prop1"); assertEquals( "select distinct idprop.value, idprop.value, idprop.value" + " from BaseObject as obj, StringProperty as idprop" + " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'", dbtlc.getQuery(getContext())); dbtlc.setValueField("prop2"); assertEquals( "select distinct idprop.value, valueprop.value, idprop.value" + " from BaseObject as obj, StringProperty as idprop, StringProperty as valueprop" + " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'" + " and obj.id=valueprop.id.id and valueprop.id.name='prop2'", dbtlc.getQuery(getContext())); dbtlc.setParentField("prop2"); assertEquals( "select distinct idprop.value, valueprop.value, valueprop.value" + " from BaseObject as obj, StringProperty as idprop, StringProperty as valueprop" + " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'" + " and obj.id=valueprop.id.id and valueprop.id.name='prop2'", dbtlc.getQuery(getContext())); dbtlc.setParentField("prop3"); assertEquals( "select distinct idprop.value, valueprop.value, parentprop.value" + " from BaseObject as obj, StringProperty as idprop," + " StringProperty as valueprop, StringProperty as parentprop" + " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'" + " and obj.id=valueprop.id.id and valueprop.id.name='prop2'" + " and obj.id=parentprop.id.id and parentprop.id.name='prop3'", dbtlc.getQuery(getContext())); }
public void testGetQueryWithClassSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); dbtlc.setClassname("XWiki.XWikiUsers"); assertEquals( "select distinct doc.fullName, doc.fullName, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", dbtlc.getQuery(getContext())); }
public void testGetQueryWithIdAndClassnameSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); dbtlc.setClassname("XWiki.XWikiUsers"); dbtlc.setIdField("doc.name"); assertEquals( "select distinct doc.name, doc.name, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", dbtlc.getQuery(getContext())); dbtlc.setIdField("obj.className"); assertEquals( "select distinct obj.className, obj.className, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", dbtlc.getQuery(getContext())); dbtlc.setIdField("property"); assertEquals( "select distinct idprop.value, idprop.value, doc.parent" + " from XWikiDocument as doc, BaseObject as obj, StringProperty as idprop" + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='property'", dbtlc.getQuery(getContext())); }
public void testGetQueryWhenNoSQLSCriptSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); assertEquals( "select doc.name from XWikiDocument doc where 1 = 0", dbtlc.getQuery(getContext())); }
public void testGetQueryWithIdAndValueSpecified() { DBTreeListClass dbtlc = new DBTreeListClass(); dbtlc.setIdField("doc.name"); dbtlc.setValueField("doc.name"); assertEquals( "select distinct doc.name, doc.name, doc.parent" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setValueField("doc.creator"); assertEquals( "select distinct doc.name, doc.creator, doc.parent" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setValueField("obj.className"); assertEquals( "select distinct doc.name, obj.className, doc.parent" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setValueField("property"); assertEquals( "select distinct doc.name, doc.property, doc.parent" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setIdField("obj.className"); dbtlc.setValueField("doc.name"); assertEquals( "select distinct obj.className, doc.name, doc.parent" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setValueField("obj.className"); assertEquals( "select distinct obj.className, obj.className, doc.parent" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setValueField("obj.id"); assertEquals( "select distinct obj.className, obj.id, doc.parent" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setValueField("property"); assertEquals( "select distinct obj.className, doc.property, doc.parent" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setIdField("property"); dbtlc.setValueField("doc.name"); assertEquals( "select distinct doc.property, doc.name, doc.parent" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setValueField("obj.className"); assertEquals( "select distinct doc.property, obj.className, doc.parent" + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", dbtlc.getQuery(getContext())); dbtlc.setValueField("property"); assertEquals( "select distinct doc.property, doc.property, doc.parent" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); dbtlc.setValueField("otherProperty"); assertEquals( "select distinct doc.property, doc.otherProperty, doc.parent" + " from XWikiDocument as doc", dbtlc.getQuery(getContext())); }