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 String
jcrContains
Resolved Name for jcr:containsprotected String
jcrDeref
Resolved Name for jcr:derefprotected String
jcrPath
Resolved Name for jcr:pathprotected String
jcrRoot
Resolved Name for jcr:rootprotected String
jcrScore
Resolved Name for jcr:scoreprotected QueryObjectModelFactory
qf
The query object model factory forAbstractJCRTest.superuser
.protected QueryManager
qm
The query manager forAbstractJCRTest.superuser
protected String
qsSQL
The identifier for the "SQL" query syntaxprotected String
qsXPATH
The identifier for the "XPATH" query syntaxprotected 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, 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 void
checkResult(QueryResult result, int hits)
Checks if theresult
contains a number ofhits
.protected void
checkResult(QueryResult result, int hits, int properties)
Checks if theresult
contains a number ofhits
andproperties
.protected void
checkResult(QueryResult result, Node[] expectedNodes)
Checks if the result set contains exactly thenodes
.protected void
checkResult(QueryResult result, Node[] requiredNodes, Node[] optionalNodes)
Checks if the result set contains exactly thenodes
.protected Query
createQuery(String statement, String language)
Creates aQuery
for the given statement in the requested language, treating optional languages gracefullyprotected Query
createQuery(Session session, String statement, String language)
Creates aQuery
for the given statement in the requested language, treating optional languages gracefullyprotected Query
createQuery(org.apache.jackrabbit.test.api.query.Statement statement)
Create aQuery
for a givenStatement
.protected String
escapeIdentifierForSQL(String identifier)
Escape an identifier suitable for the SQL parserprotected void
evaluateResultOrder(QueryResult queryResult, String propName, boolean descending)
Checks if theQueryResult
is ordered according order property in direction of related argument.protected QueryResult
execute(String statement, String language)
Creates and executes aQuery
for a given Statement in a given query languageprotected QueryResult
execute(org.apache.jackrabbit.test.api.query.Statement statement)
Creates and executes aQuery
for the givenStatement
protected void
executeSqlQuery(Session session, String sql, Node[] expectedNodes)
Executes thesql
query and checks the results against the specifiednodes
.protected void
executeSqlQuery(Session session, String sql, Node[] requiredNodes, Node[] optionalNodes)
Executes thesql
query and checks the results against the specifiednodes
.protected void
executeXPathQuery(Session session, String xpath, Node[] expectedNodes)
Executes thexpath
query and checks the results against the specifiednodes
.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 init
as 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 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 classAbstractJCRTest
- Throws:
Exception
-
tearDown
protected void tearDown() throws Exception
- Overrides:
tearDown
in classAbstractJCRTest
- Throws:
Exception
-
createQuery
protected Query createQuery(org.apache.jackrabbit.test.api.query.Statement statement) throws RepositoryException, NotExecutableException
Create aQuery
for a givenStatement
.- 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 aQuery
for 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 aQuery
for 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 aQuery
for the givenStatement
- 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 aQuery
for 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:
RepositoryException
NotExecutableException
-
checkResult
protected void checkResult(QueryResult result, int hits) throws RepositoryException
Checks if theresult
contains 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 theresult
contains a number ofhits
andproperties
.- 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 theQueryResult
is ordered according order property in direction of related argument.- Parameters:
queryResult
- to be testedpropName
- Name of the porperty to order bydescending
- iftrue
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[] expectedNodes) throws RepositoryException, NotExecutableException
Executes thexpath
query 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:
NotExecutableException
RepositoryException
-
executeSqlQuery
protected void executeSqlQuery(Session session, String sql, Node[] expectedNodes) throws RepositoryException, NotExecutableException
Executes thesql
query 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:
NotExecutableException
RepositoryException
-
executeSqlQuery
protected void executeSqlQuery(Session session, String sql, Node[] requiredNodes, Node[] optionalNodes) throws RepositoryException, NotExecutableException
Executes thesql
query 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:
NotExecutableException
RepositoryException
-
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 init
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 parserTODO: currently only handles dash character
-
isSupportedLanguage
protected boolean isSupportedLanguage(String language) throws RepositoryException
- Parameters:
language
- a query language.- Returns:
true
iflanguage
is supported;false
otherwise.- Throws:
RepositoryException
- if an error occurs.
-
-