org.apache.jackrabbit.test.api.query
Class AbstractQueryTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.jackrabbit.test.JUnitTest
              extended by org.apache.jackrabbit.test.AbstractJCRTest
                  extended by org.apache.jackrabbit.test.api.query.AbstractQueryTest
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AbstractQOMTest, AbstractQueryLevel2Test, CreateQueryTest, DerefQueryLevel1Test, ElementTest, GetLanguageTest, GetPersistentQueryPathLevel1Test, GetPersistentQueryPathTest, GetPropertyNamesTest, GetStatementTest, GetSupportedQueryLanguagesTest, OrderByDateTest, OrderByDecimalTest, OrderByDoubleTest, OrderByLengthTest, OrderByLocalNameTest, OrderByLongTest, OrderByLowerCaseTest, OrderByMultiTypeTest, OrderByNameTest, OrderByStringTest, OrderByUpperCaseTest, OrderByURITest, PredicatesTest, QueryResultNodeIteratorTest, SetLimitTest, SetOffsetTest, SimpleSelectionTest, SQLJcrPathTest, SQLJoinTest, SQLOrderByTest, SQLPathTest, TextNodeTest, XPathDocOrderTest, XPathJcrPathTest, XPathOrderByTest, XPathPosIndexTest

public abstract class AbstractQueryTest
extends AbstractJCRTest

Abstract base class for query test cases.


Field Summary
protected  String jcrContains
          Resolved Name for jcr:contains
protected  String jcrDeref
          Resolved Name for jcr:deref
protected  String jcrPath
          Resolved Name for jcr:path
protected  String jcrRoot
          Resolved Name for jcr:root
protected  String jcrScore
          Resolved Name for jcr:score
protected  QueryObjectModelFactory qf
          The query object model factory for AbstractJCRTest.superuser.
protected  QueryManager qm
          The query manager for AbstractJCRTest.superuser
protected  ValueFactory vf
          The value factory for creating literals for the query object model.
protected  String xpathRoot
          The string /${jcrRoot}${testRoot} with all components of the test path properly escaped for XPath.
 
Fields inherited from class org.apache.jackrabbit.test.AbstractJCRTest
isReadOnly, jcrBaseVersion, jcrCopiedFrom, jcrCreated, jcrFrozenNode, jcrFrozenUuid, jcrIsCheckedOut, jcrlockIsDeep, jcrLockOwner, jcrMergeFailed, jcrMixinTypes, jcrPredecessors, jcrPrimaryType, jcrRootVersion, jcrSuccessors, jcrSystem, jcrUUID, jcrVersionHistory, mixLockable, mixReferenceable, mixShareable, mixSimpleVersionable, mixVersionable, nodeName1, nodeName2, nodeName3, nodeName4, NS_JCR_URI, NS_MIX_URI, NS_NT_URI, NS_SV_URI, ntBase, ntFrozenNode, ntQuery, ntUnstructured, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testNodeTypeNoChildren, testPath, testRoot, testRootNode, workspaceName
 
Fields inherited from class org.apache.jackrabbit.test.JUnitTest
log, logger
 
Constructor Summary
AbstractQueryTest()
           
 
Method Summary
protected  void checkResult(QueryResult result, int hits)
          Checks if the result contains a number of hits.
protected  void checkResult(QueryResult result, int hits, int properties)
          Checks if the result contains a number of hits and properties.
protected  void checkResult(QueryResult result, Node[] nodes)
          Checks if the result set contains exactly the nodes.
protected  Query createQuery(Session session, String statement, String language)
          Creates a Query for the given statement in the requested language, treating optional languages gracefully
protected  Query createQuery(org.apache.jackrabbit.test.api.query.Statement statement)
          Create a Query for a given Statement.
protected  Query createQuery(String statement, String language)
          Creates a Query for the given statement in the requested language, treating optional languages gracefully
protected  String escapeIdentifierForSQL(String identifier)
          Escape an identifier suitable for the SQL parser
protected  void evaluateResultOrder(QueryResult queryResult, String propName, boolean descending)
          Checks if the QueryResult is ordered according order property in direction of related argument.
protected  QueryResult execute(org.apache.jackrabbit.test.api.query.Statement statement)
          Creates and executes a Query for the given Statement
protected  QueryResult execute(String statement, String language)
          Creates and executes a Query for a given Statement in a given query language
protected  void executeSqlQuery(Session session, String sql, Node[] nodes)
          Executes the sql query and checks the results against the specified nodes.
protected  void executeXPathQuery(Session session, String xpath, Node[] nodes)
          Executes the xpath query and checks the results against the specified nodes.
protected  boolean isSupportedLanguage(String language)
           
protected  void setUp()
          Set-up the configuration values used for the test.
protected  void tearDown()
           
protected  Node[] toArray(NodeIterator it)
          Returns the nodes in it as an array of Nodes.
 
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureKnowsNodeType, ensureMixinType, ensureMultipleWorkspacesSupported, getHelper, getJcrValue, getLocalName, getNonExistingWorkspaceName, getProperty, getProperty, getSize, isSupported, needsMixin, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jcrScore

protected String jcrScore
Resolved Name for jcr:score


jcrPath

protected String jcrPath
Resolved Name for jcr:path


jcrRoot

protected String jcrRoot
Resolved Name for jcr:root


jcrContains

protected String jcrContains
Resolved Name for jcr:contains


jcrDeref

protected String jcrDeref
Resolved Name for jcr:deref


xpathRoot

protected String xpathRoot
The string /${jcrRoot}${testRoot} with all components of the test path properly escaped for XPath.

See Also:
JCR-714

qf

protected QueryObjectModelFactory qf
The query object model factory for AbstractJCRTest.superuser.


vf

protected ValueFactory vf
The value factory for creating literals for the query object model.


qm

protected QueryManager qm
The query manager for AbstractJCRTest.superuser

Constructor Detail

AbstractQueryTest

public AbstractQueryTest()
Method Detail

setUp

protected void setUp()
              throws Exception
Set-up the configuration values used for the test. Per default retrieves a session, configures testRoot, and nodetype and checks if the query language for the current language is available.

Overrides:
setUp in class AbstractJCRTest
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class AbstractJCRTest
Throws:
Exception

createQuery

protected Query createQuery(org.apache.jackrabbit.test.api.query.Statement statement)
                     throws RepositoryException,
                            NotExecutableException
Create a Query for a given Statement.

Parameters:
statement - the query should be created for
Returns:
Throws:
RepositoryException
NotExecutableException
See Also:
createQuery(String, String)

createQuery

protected Query createQuery(String statement,
                            String language)
                     throws RepositoryException,
                            NotExecutableException
Creates a Query for the given statement in the requested language, treating optional languages gracefully

Throws:
RepositoryException
NotExecutableException

createQuery

protected Query createQuery(Session session,
                            String statement,
                            String language)
                     throws RepositoryException,
                            NotExecutableException
Creates a Query for the given statement in the requested language, treating optional languages gracefully

Throws:
RepositoryException
NotExecutableException

execute

protected QueryResult execute(org.apache.jackrabbit.test.api.query.Statement statement)
                       throws RepositoryException,
                              NotExecutableException
Creates and executes a Query for the given Statement

Parameters:
statement - to execute
Returns:
Throws:
RepositoryException
NotExecutableException
See Also:
execute(String, String)

execute

protected QueryResult execute(String statement,
                              String language)
                       throws RepositoryException,
                              NotExecutableException
Creates and executes a Query for a given Statement in a given query language

Parameters:
statement - the query should be build for
language - query language the stement is written in
Returns:
Throws:
RepositoryException
NotExecutableException

checkResult

protected void checkResult(QueryResult result,
                           int hits)
                    throws RepositoryException
Checks if the result contains a number of hits.

Parameters:
result - the QueryResult.
hits - the number of expected hits.
Throws:
RepositoryException - if an error occurs while iterating over the result nodes.

checkResult

protected void checkResult(QueryResult result,
                           int hits,
                           int properties)
                    throws RepositoryException
Checks if the result contains a number of hits and properties.

Parameters:
result - the QueryResult.
hits - the number of expected hits.
properties - the number of expected properties.
Throws:
RepositoryException - if an error occurs while iterating over the result nodes.

evaluateResultOrder

protected void evaluateResultOrder(QueryResult queryResult,
                                   String propName,
                                   boolean descending)
                            throws RepositoryException,
                                   NotExecutableException
Checks if the QueryResult is ordered according order property in direction of related argument.

Parameters:
queryResult - to be tested
propName - Name of the porperty to order by
descending - if true order has to be descending
Throws:
RepositoryException
NotExecutableException - in case of less than two results or all results have same size of value in its order-property

executeXPathQuery

protected void executeXPathQuery(Session session,
                                 String xpath,
                                 Node[] nodes)
                          throws RepositoryException,
                                 NotExecutableException
Executes the xpath query and checks the results against the specified nodes.

Parameters:
session - the session to use for the query.
xpath - the xpath query.
nodes - the expected result nodes.
Throws:
NotExecutableException
RepositoryException

executeSqlQuery

protected void executeSqlQuery(Session session,
                               String sql,
                               Node[] nodes)
                        throws RepositoryException,
                               NotExecutableException
Executes the sql query and checks the results against the specified nodes.

Parameters:
session - the session to use for the query.
sql - the sql query.
nodes - the expected result nodes.
Throws:
NotExecutableException
RepositoryException

checkResult

protected void checkResult(QueryResult result,
                           Node[] nodes)
                    throws RepositoryException
Checks if the result set contains exactly the nodes.

Parameters:
result - the query result.
nodes - the expected nodes in the result set.
Throws:
RepositoryException

toArray

protected Node[] toArray(NodeIterator it)
Returns the nodes in it as an array of Nodes.

Parameters:
it - the NodeIterator.
Returns:
the elements of the iterator as an array of Nodes.

escapeIdentifierForSQL

protected String escapeIdentifierForSQL(String identifier)
Escape an identifier suitable for the SQL parser


isSupportedLanguage

protected boolean isSupportedLanguage(String language)
                               throws RepositoryException
Parameters:
language - a query language.
Returns:
true if language is supported; false otherwise.
Throws:
RepositoryException - if an error occurs.


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.