Class AbstractQueryTest
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.apache.jackrabbit.test.JUnitTest
-
- org.apache.jackrabbit.test.AbstractJCRTest
-
- 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
Fields Modifier and Type Field Description protected StringjcrContainsResolved Name for jcr:containsprotected StringjcrDerefResolved Name for jcr:derefprotected StringjcrPathResolved Name for jcr:pathprotected StringjcrRootResolved Name for jcr:rootprotected StringjcrScoreResolved Name for jcr:scoreprotected QueryObjectModelFactoryqfThe query object model factory forAbstractJCRTest.superuser.protected QueryManagerqmThe query manager forAbstractJCRTest.superuserprotected StringqsSQLThe identifier for the "SQL" query syntaxprotected StringqsXPATHThe identifier for the "XPATH" query syntaxprotected ValueFactoryvfThe value factory for creating literals for the query object model.protected StringxpathRootThe 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, mixTitle, mixVersionable, nodeName1, nodeName2, nodeName3, nodeName4, NS_JCR_URI, NS_MIX_URI, NS_NT_URI, NS_SV_URI, ntActivity, ntBase, ntFrozenNode, ntQuery, ntUnstructured, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testNodeTypeNoChildren, testNodeTypeTestRoot, testPath, testRoot, testRootNode, workspaceName
-
-
Constructor Summary
Constructors Constructor Description AbstractQueryTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckResult(QueryResult result, int hits)Checks if theresultcontains a number ofhits.protected voidcheckResult(QueryResult result, int hits, int properties)Checks if theresultcontains a number ofhitsandproperties.protected voidcheckResult(QueryResult result, Node[] expectedNodes)Checks if the result set contains exactly thenodes.protected voidcheckResult(QueryResult result, Node[] requiredNodes, Node[] optionalNodes)Checks if the result set contains exactly thenodes.protected QuerycreateQuery(String statement, String language)Creates aQueryfor the given statement in the requested language, treating optional languages gracefullyprotected QuerycreateQuery(Session session, String statement, String language)Creates aQueryfor the given statement in the requested language, treating optional languages gracefullyprotected QuerycreateQuery(org.apache.jackrabbit.test.api.query.Statement statement)Create aQueryfor a givenStatement.protected StringescapeIdentifierForSQL(String identifier)Escape an identifier suitable for the SQL parserprotected voidevaluateResultOrder(QueryResult queryResult, String propName, boolean descending)Checks if theQueryResultis ordered according order property in direction of related argument.protected QueryResultexecute(String statement, String language)Creates and executes aQueryfor a given Statement in a given query languageprotected QueryResultexecute(org.apache.jackrabbit.test.api.query.Statement statement)Creates and executes aQueryfor the givenStatementprotected voidexecuteSqlQuery(Session session, String sql, Node[] expectedNodes)Executes thesqlquery and checks the results against the specifiednodes.protected voidexecuteSqlQuery(Session session, String sql, Node[] requiredNodes, Node[] optionalNodes)Executes thesqlquery and checks the results against the specifiednodes.protected voidexecuteXPathQuery(Session session, String xpath, Node[] expectedNodes)Executes thexpathquery and checks the results against the specifiednodes.protected booleanisSupportedLanguage(String language)protected voidsetUp()Set-up the configuration values used for the test.protected voidtearDown()protected Node[]toArray(NodeIterator it)Returns the nodes initas an array of Nodes.-
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureKnowsNodeType, ensureLockingSupported, ensureMixinType, ensureMultipleWorkspacesSupported, getHelper, getJcrValue, getLocalName, getNonExistingWorkspaceName, getPrefix, getProperty, getProperty, getQualifiedName, getSize, isSupported, needsMixin, run
-
Methods inherited from class junit.framework.TestCase
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, runBare, runTest, setName, toString
-
-
-
-
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 forAbstractJCRTest.superuser.
-
vf
protected ValueFactory vf
The value factory for creating literals for the query object model.
-
qm
protected QueryManager qm
The query manager forAbstractJCRTest.superuser
-
qsXPATH
protected String qsXPATH
The identifier for the "XPATH" query syntax
-
qsSQL
protected String qsSQL
The identifier for the "SQL" query syntax
-
-
Method Detail
-
setUp
protected void setUp() throws ExceptionSet-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:
setUpin classAbstractJCRTest- Throws:
Exception
-
tearDown
protected void tearDown() throws Exception- Overrides:
tearDownin classAbstractJCRTest- Throws:
Exception
-
createQuery
protected Query createQuery(org.apache.jackrabbit.test.api.query.Statement statement) throws RepositoryException, NotExecutableException
Create aQueryfor a givenStatement.- Parameters:
statement- the query should be created for- Returns:
- Throws:
RepositoryExceptionNotExecutableException- See Also:
createQuery(String, String)
-
createQuery
protected Query createQuery(String statement, String language) throws RepositoryException, NotExecutableException
Creates aQueryfor the given statement in the requested language, treating optional languages gracefully
-
createQuery
protected Query createQuery(Session session, String statement, String language) throws RepositoryException, NotExecutableException
Creates aQueryfor the given statement in the requested language, treating optional languages gracefully
-
execute
protected QueryResult execute(org.apache.jackrabbit.test.api.query.Statement statement) throws RepositoryException, NotExecutableException
Creates and executes aQueryfor the givenStatement- Parameters:
statement- to execute- Returns:
- Throws:
RepositoryExceptionNotExecutableException- See Also:
execute(String, String)
-
execute
protected QueryResult execute(String statement, String language) throws RepositoryException, NotExecutableException
Creates and executes aQueryfor a given Statement in a given query language- Parameters:
statement- the query should be build forlanguage- query language the stement is written in- Returns:
- Throws:
RepositoryExceptionNotExecutableException
-
checkResult
protected void checkResult(QueryResult result, int hits) throws RepositoryException
Checks if theresultcontains a number ofhits.- Parameters:
result- theQueryResult.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 theresultcontains a number ofhitsandproperties.- Parameters:
result- theQueryResult.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 theQueryResultis ordered according order property in direction of related argument.- Parameters:
queryResult- to be testedpropName- Name of the porperty to order bydescending- iftrueorder has to be descending- Throws:
RepositoryExceptionNotExecutableException- 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[] expectedNodes) throws RepositoryException, NotExecutableException
Executes thexpathquery and checks the results against the specifiednodes.- Parameters:
session- the session to use for the query.xpath- the xpath query.expectedNodes- the expected nodes.- Throws:
NotExecutableExceptionRepositoryException
-
executeSqlQuery
protected void executeSqlQuery(Session session, String sql, Node[] expectedNodes) throws RepositoryException, NotExecutableException
Executes thesqlquery and checks the results against the specifiednodes.- Parameters:
session- the session to use for the query.sql- the sql query.expectedNodes- the expected nodes.- Throws:
NotExecutableExceptionRepositoryException
-
executeSqlQuery
protected void executeSqlQuery(Session session, String sql, Node[] requiredNodes, Node[] optionalNodes) throws RepositoryException, NotExecutableException
Executes thesqlquery and checks the results against the specifiednodes.- Parameters:
session- the session to use for the query.sql- the sql query.requiredNodes- the nodes that need to be in the result set (null if no node is required).optionalNodes- the nodes that may be in the result set (null if no node is optional).- Throws:
NotExecutableExceptionRepositoryException
-
checkResult
protected void checkResult(QueryResult result, Node[] expectedNodes) throws RepositoryException
Checks if the result set contains exactly thenodes.- Parameters:
result- the query result.expectedNodes- the expected nodes.- Throws:
RepositoryException
-
checkResult
protected void checkResult(QueryResult result, Node[] requiredNodes, Node[] optionalNodes) throws RepositoryException
Checks if the result set contains exactly thenodes.- Parameters:
result- the query result.requiredNodes- the nodes that need to be in the result set (null if no node is required).optionalNodes- the nodes that may be in the result set (null if no node is optional).- Throws:
RepositoryException
-
toArray
protected Node[] toArray(NodeIterator it)
Returns the nodes initas 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 parserTODO: currently only handles dash character
-
isSupportedLanguage
protected boolean isSupportedLanguage(String language) throws RepositoryException
- Parameters:
language- a query language.- Returns:
trueiflanguageis supported;falseotherwise.- Throws:
RepositoryException- if an error occurs.
-
-