mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-02 17:35:18 +00:00
- Single configuration entry point for JCR and non-JCR clients (i.e. application-context.xml) - Addition of build-war, incremental-war build targets (no deploy) - Remove build of JCR TCK war file by default git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2777 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
88 lines
2.5 KiB
Java
88 lines
2.5 KiB
Java
package org.alfresco.jcr.query;
|
|
|
|
import javax.jcr.Node;
|
|
import javax.jcr.NodeIterator;
|
|
import javax.jcr.Property;
|
|
import javax.jcr.Session;
|
|
import javax.jcr.SimpleCredentials;
|
|
import javax.jcr.Value;
|
|
import javax.jcr.query.Query;
|
|
import javax.jcr.query.QueryManager;
|
|
import javax.jcr.query.QueryResult;
|
|
import javax.jcr.query.Row;
|
|
import javax.jcr.query.RowIterator;
|
|
|
|
import org.alfresco.jcr.test.BaseJCRTest;
|
|
|
|
public class QueryManagerImplTest extends BaseJCRTest
|
|
{
|
|
|
|
protected Session superuserSession;
|
|
|
|
@Override
|
|
protected void setUp() throws Exception
|
|
{
|
|
super.setUp();
|
|
|
|
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
|
superuserSession = repository.login(superuser, getWorkspace());
|
|
}
|
|
|
|
@Override
|
|
protected void tearDown() throws Exception
|
|
{
|
|
superuserSession.logout();
|
|
super.tearDown();
|
|
}
|
|
|
|
|
|
public void testQuery()
|
|
throws Exception
|
|
{
|
|
QueryManager queryMgr = superuserSession.getWorkspace().getQueryManager();
|
|
String[] languages = queryMgr.getSupportedQueryLanguages();
|
|
assertEquals(1, languages.length);
|
|
assertEquals(Query.XPATH, languages[0]);
|
|
|
|
Query query = queryMgr.createQuery("//*", Query.XPATH);
|
|
QueryResult result = query.execute();
|
|
String[] columnNames = result.getColumnNames();
|
|
|
|
// iterate via row iterator
|
|
int rowCnt = 0;
|
|
RowIterator rowIterator = result.getRows();
|
|
while(rowIterator.hasNext())
|
|
{
|
|
Row row = rowIterator.nextRow();
|
|
for (String columnName : columnNames)
|
|
{
|
|
Value value = row.getValue(columnName);
|
|
if (value != null)
|
|
{
|
|
String strValue = value.getString();
|
|
assertNotNull(strValue);
|
|
}
|
|
}
|
|
rowCnt++;
|
|
}
|
|
|
|
// iterate via node iterator
|
|
int nodeCnt = 0;
|
|
NodeIterator nodeIterator = result.getNodes();
|
|
while(nodeIterator.hasNext())
|
|
{
|
|
Node node = nodeIterator.nextNode();
|
|
Property property = node.getProperty("sys:node-uuid");
|
|
Value value = property.getValue();
|
|
String uuid = value.getString();
|
|
assertNotNull(uuid);
|
|
nodeCnt++;
|
|
}
|
|
|
|
// check same number of items returned from each iterator
|
|
assertEquals(rowCnt, nodeCnt);
|
|
}
|
|
|
|
|
|
}
|