/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package ifc.sdb;
import com.sun.star.sdb.XSingleSelectQueryAnalyzer;
import lib.MultiMethodTest;
import com.sun.star.sdb.XSingleSelectQueryComposer;
import com.sun.star.uno.UnoRuntime;
import lib.StatusException;
import lib.Status;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XIndexAccess;
/**
* Testing com.sun.star.sdb.XSingleSelectQueryAnalyzer
* interface methods :
*
getQuery()
setQuery()
getFilter()
getStructuredFilter()
getGroup()
getGroupColumns()
getHavingClause()
getStructuredHavingClause()
getOrder()
getOrderColumns()
* @see com.sun.star.sdb.XSingleSelectQueryAnalyzer */ public class _XSingleSelectQueryAnalyzer extends MultiMethodTest { // oObj filled by MultiMethodTest public XSingleSelectQueryAnalyzer oObj = null ; private String queryString = "SELECT * FROM \"biblio\""; private XSingleSelectQueryComposer xComposer = null; /** * Receives the object relations: *
XSingleSelectQueryComposer xCompoer
* @see com.sun.star.sdb.XSingleSelectQueryComposer
*/
protected void before() {
xComposer = (XSingleSelectQueryComposer)
UnoRuntime.queryInterface(XSingleSelectQueryComposer.class,
tEnv.getObjRelation("xComposer"));
if (xComposer == null) {
throw new StatusException(Status.failed(
"Couldn't get object relation 'xComposer'. Test must be modified"));
}
}
/**
* call setQuery()
once with valid query, once with invalid
* query. Has ok if only on sceond call SQLException
was thrwon
*/
public void _setQuery() {
try{
oObj.setQuery("This is an invalid SQL query");
} catch (com.sun.star.sdbc.SQLException e){
log.println("expected Exception. ");
}
try{
oObj.setQuery(queryString);
} catch (com.sun.star.sdbc.SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setQuery()", false);
}
tRes.tested("setQuery()", true);
}
/**
* checks of the returned value of getQuery()
* equals the string which was set by setQuery()
*
* required methods: *
setQuery
xComposer
set a filter. This filter
* must returned while calling getFilter
*/
public void _getFilter() {
try{
String filter = "\"Identifier\" = 'BOR02b'";
xComposer.setFilter(filter);
tRes.tested("getFilter()", (oObj.getFilter().equals(filter)));
} catch (com.sun.star.sdbc.SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getFilter()", false);
}
}
/**
* Object relation xComposer
set a complex filter with method
. setFilter
. Then getStructuredFilter
returns a
* sequenze of PropertyValue
which was set with method
* setStructuredFilter
from * required methods: *
setQuery
getFilter
xComposer
set a goup. This group
* must returned while calling getGroup
*/
public void _getGroup() {
try{
String group = "\"Identifier\"";
xComposer.setGroup(group);
tRes.tested("getGroup()", (oObj.getGroup().equals(group)));
} catch (com.sun.star.sdbc.SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getGroup()", false);
}
}
/**
* Method getGroupColumns
retunrs a XIndexAccess
* Test has ok status if returned value is an useable XIndexAccess
*/
public void _getGroupColumns() {
try{
XIndexAccess xGroupColumns = oObj.getGroupColumns();
tRes.tested("getGroupColumns()", (xGroupColumns != null &&
xGroupColumns.getCount() == 1 &&
xGroupColumns.getByIndex(0) != null));
} catch (com.sun.star.lang.IndexOutOfBoundsException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getGroupColumns()", false);
} catch (com.sun.star.lang.WrappedTargetException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getGroupColumns()", false);
}
}
/**
* Object relation xComposer
set a clause. This clause
* must returned while calling getHavingClause
*/
public void _getHavingClause() {
try{
String clause = "\"Identifier\" = 'BOR02b'";
xComposer.setHavingClause(clause);
tRes.tested("getHavingClause()", (
oObj.getHavingClause().equals(clause)));
} catch (com.sun.star.sdbc.SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getHavingClause()", false);
}
}
/**
* Object relation xComposer
set a clause. This clause
* must returned while calling getHavingClause
* * required methods: *
setQuery
getFilter
getStructuredFilter
xComposer
set an order. This order
* must returned while calling getOrder
*/
public void _getOrder() {
try{
String order = "\"Identifier\"";
xComposer.setOrder(order);
tRes.tested("getOrder()", (oObj.getOrder().equals(order)));
} catch (com.sun.star.sdbc.SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getOrder()", false);
}
}
/**
* Method getGroupColumns
retunrs a XIndexAccess
* Test has ok status if returned value is an useable XIndexAccess
*/
public void _getOrderColumns() {
try{
XIndexAccess xOrderColumns = oObj.getOrderColumns();
tRes.tested("getOrderColumns()", (xOrderColumns != null &&
xOrderColumns.getCount() == 1 &&
xOrderColumns.getByIndex(0) != null));
} catch (com.sun.star.lang.IndexOutOfBoundsException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getOrderColumns()", false);
} catch (com.sun.star.lang.WrappedTargetException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("getOrderColumns()", false);
}
}
} // finish class _XSingleSelectQueryAnalyzer