1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.sdb; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.sdb.XSingleSelectQueryAnalyzer; 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir import com.sun.star.sdb.XSingleSelectQueryComposer; 29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 30cdf0e10cSrcweir import lib.StatusException; 31cdf0e10cSrcweir import lib.Status; 32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 33cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code> 37cdf0e10cSrcweir * interface methods : 38cdf0e10cSrcweir * <ul> 39cdf0e10cSrcweir * <li><code>getQuery()</code></li> 40cdf0e10cSrcweir * <li><code>setQuery()</code></li> 41cdf0e10cSrcweir * <li><code>getFilter()</code></li> 42cdf0e10cSrcweir * <li><code>getStructuredFilter()</code></li> 43cdf0e10cSrcweir * <li><code>getGroup()</code></li> 44cdf0e10cSrcweir * <li><code>getGroupColumns()</code></li> 45cdf0e10cSrcweir * <li><code>getHavingClause()</code></li> 46cdf0e10cSrcweir * <li><code>getStructuredHavingClause()</code></li> 47cdf0e10cSrcweir * <li><code>getOrder()</code></li> 48cdf0e10cSrcweir * <li><code>getOrderColumns()</code></li> 49cdf0e10cSrcweir 50cdf0e10cSrcweir * </ul> <p> 51cdf0e10cSrcweir * @see com.sun.star.sdb.XSingleSelectQueryAnalyzer 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir public class _XSingleSelectQueryAnalyzer extends MultiMethodTest { 54cdf0e10cSrcweir 55cdf0e10cSrcweir // oObj filled by MultiMethodTest 56cdf0e10cSrcweir public XSingleSelectQueryAnalyzer oObj = null ; 57cdf0e10cSrcweir 58cdf0e10cSrcweir private String queryString = "SELECT * FROM \"biblio\""; 59cdf0e10cSrcweir 60cdf0e10cSrcweir private XSingleSelectQueryComposer xComposer = null; 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** 63cdf0e10cSrcweir * Recieves the object relations: 64cdf0e10cSrcweir * <ul> 65cdf0e10cSrcweir * <li><code>XSingleSelectQueryComposer xCompoer</code></li> 66cdf0e10cSrcweir * </ul> <p> 67cdf0e10cSrcweir * @see om.sun.star.sdb.XSingleSelectQueryComposer 68cdf0e10cSrcweir */ 69cdf0e10cSrcweir protected void before() { 70cdf0e10cSrcweir 71cdf0e10cSrcweir xComposer = (XSingleSelectQueryComposer) 72cdf0e10cSrcweir UnoRuntime.queryInterface(XSingleSelectQueryComposer.class, 73cdf0e10cSrcweir tEnv.getObjRelation("xComposer")); 74cdf0e10cSrcweir 75cdf0e10cSrcweir if (xComposer == null) { 76cdf0e10cSrcweir throw new StatusException(Status.failed( 77cdf0e10cSrcweir "Couldn't get object relation 'xComposer'. Test must be modified")); 78cdf0e10cSrcweir 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir } 82cdf0e10cSrcweir /** 83cdf0e10cSrcweir * call <code>setQuery()</code> once with valid query, once with invalid 84cdf0e10cSrcweir * query. Has ok if only on sceond call <code>SQLException</code> was thrwon 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir public void _setQuery() { 87cdf0e10cSrcweir 88cdf0e10cSrcweir try{ 89cdf0e10cSrcweir oObj.setQuery("This is an invalid SQL query"); 90cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 91cdf0e10cSrcweir log.println("expected Exception. "); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir try{ 95cdf0e10cSrcweir oObj.setQuery(queryString); 96cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 97cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 98cdf0e10cSrcweir tRes.tested("setQuery()", false); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir tRes.tested("setQuery()", true); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** 104cdf0e10cSrcweir * checks of the returned value of <code>getQuery()</code> 105cdf0e10cSrcweir * equals the string which was set by <code>setQuery()</code> 106cdf0e10cSrcweir * <p> 107cdf0e10cSrcweir * required methods: 108cdf0e10cSrcweir *<ul> 109cdf0e10cSrcweir * <li><code>setQuery</code></li> 110cdf0e10cSrcweir *</ul> 111cdf0e10cSrcweir */ 112cdf0e10cSrcweir public void _getQuery() { 113cdf0e10cSrcweir this.requiredMethod("setQuery()"); 114cdf0e10cSrcweir 115cdf0e10cSrcweir boolean res = false; 116cdf0e10cSrcweir 117cdf0e10cSrcweir res = oObj.getQuery().equals(queryString); 118cdf0e10cSrcweir 119cdf0e10cSrcweir tRes.tested("getQuery()", res); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir /** 124cdf0e10cSrcweir * Object relation <code>xComposer</code> set a filter. This filter 125cdf0e10cSrcweir * must returned while calling <code>getFilter</code> 126cdf0e10cSrcweir */ 127cdf0e10cSrcweir public void _getFilter() { 128cdf0e10cSrcweir try{ 129cdf0e10cSrcweir String filter = "\"Identifier\" = 'BOR02b'"; 130cdf0e10cSrcweir xComposer.setFilter(filter); 131cdf0e10cSrcweir tRes.tested("getFilter()", (oObj.getFilter().equals(filter))); 132cdf0e10cSrcweir 133cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 134cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 135cdf0e10cSrcweir tRes.tested("getFilter()", false); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir /** 140cdf0e10cSrcweir * Object relation <code>xComposer</code> set a complex filter with method 141cdf0e10cSrcweir . <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a 142cdf0e10cSrcweir * sequenze of <code>PropertyValue</code> which was set with method 143cdf0e10cSrcweir * <code>setStructuredFilter</code> from <xComposer>. 144cdf0e10cSrcweir * Then test has ok status if <getFilter> returns the complex filter. 145cdf0e10cSrcweir * <p> 146cdf0e10cSrcweir * required methods: 147cdf0e10cSrcweir *<ul> 148cdf0e10cSrcweir * <li><code>setQuery</code></li> 149cdf0e10cSrcweir * <li><code>getFilter</code></li> 150cdf0e10cSrcweir *</ul> 151cdf0e10cSrcweir */ 152cdf0e10cSrcweir public void _getStructuredFilter() { 153cdf0e10cSrcweir requiredMethod("setQuery()"); 154cdf0e10cSrcweir requiredMethod("getFilter()"); 155cdf0e10cSrcweir try{ 156cdf0e10cSrcweir oObj.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\""); 157cdf0e10cSrcweir String complexFilter = "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )"; 158cdf0e10cSrcweir xComposer.setFilter(complexFilter); 159cdf0e10cSrcweir PropertyValue[][] aStructuredFilter = oObj.getStructuredFilter(); 160cdf0e10cSrcweir xComposer.setFilter(""); 161cdf0e10cSrcweir xComposer.setStructuredFilter(aStructuredFilter); 162cdf0e10cSrcweir tRes.tested("getStructuredFilter()", (oObj.getFilter().equals(complexFilter))); 163cdf0e10cSrcweir 164cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 165cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 166cdf0e10cSrcweir tRes.tested("getStructuredFilter()", false); 167cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e){ 168cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 169cdf0e10cSrcweir tRes.tested("getStructuredFilter()", false); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir /** 174cdf0e10cSrcweir * Object relation <code>xComposer</code> set a goup. This group 175cdf0e10cSrcweir * must returned while calling <code>getGroup</code> 176cdf0e10cSrcweir */ 177cdf0e10cSrcweir public void _getGroup() { 178cdf0e10cSrcweir try{ 179cdf0e10cSrcweir String group = "\"Identifier\""; 180cdf0e10cSrcweir xComposer.setGroup(group); 181cdf0e10cSrcweir tRes.tested("getGroup()", (oObj.getGroup().equals(group))); 182cdf0e10cSrcweir 183cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 184cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 185cdf0e10cSrcweir tRes.tested("getGroup()", false); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir /** 190cdf0e10cSrcweir * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code> 191cdf0e10cSrcweir * Test has ok status if returned value is an useable <code>XIndexAccess</code> 192cdf0e10cSrcweir */ 193cdf0e10cSrcweir public void _getGroupColumns() { 194cdf0e10cSrcweir try{ 195cdf0e10cSrcweir XIndexAccess xGroupColumns = oObj.getGroupColumns(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir tRes.tested("getGroupColumns()", (xGroupColumns != null && 198cdf0e10cSrcweir xGroupColumns.getCount() == 1 && 199cdf0e10cSrcweir xGroupColumns.getByIndex(0) != null)); 200cdf0e10cSrcweir 201cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e){ 202cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 203cdf0e10cSrcweir tRes.tested("getGroupColumns()", false); 204cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 205cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 206cdf0e10cSrcweir tRes.tested("getGroupColumns()", false); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir /** 211cdf0e10cSrcweir * Object relation <code>xComposer</code> set a clause. This clause 212cdf0e10cSrcweir * must returned while calling <code>getHavingClause</code> 213cdf0e10cSrcweir */ 214cdf0e10cSrcweir public void _getHavingClause() { 215cdf0e10cSrcweir try{ 216cdf0e10cSrcweir String clause = "\"Identifier\" = 'BOR02b'"; 217cdf0e10cSrcweir xComposer.setHavingClause(clause); 218cdf0e10cSrcweir tRes.tested("getHavingClause()", ( 219cdf0e10cSrcweir oObj.getHavingClause().equals(clause))); 220cdf0e10cSrcweir 221cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 222cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 223cdf0e10cSrcweir tRes.tested("getHavingClause()", false); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir /** 228cdf0e10cSrcweir * Object relation <code>xComposer</code> set a clause. This clause 229cdf0e10cSrcweir * must returned while calling <code>getHavingClause</code> 230cdf0e10cSrcweir * <p> 231cdf0e10cSrcweir * required methods: 232cdf0e10cSrcweir *<ul> 233cdf0e10cSrcweir * <li><code>setQuery</code></li> 234cdf0e10cSrcweir * <li><code>getFilter</code></li> 235cdf0e10cSrcweir * <li><code>getStructuredFilter</code></li> 236cdf0e10cSrcweir *</ul> 237cdf0e10cSrcweir */ 238cdf0e10cSrcweir public void _getStructuredHavingClause() { 239cdf0e10cSrcweir requiredMethod("setQuery()"); 240cdf0e10cSrcweir requiredMethod("getFilter()"); 241cdf0e10cSrcweir executeMethod("getStructuredFilter()"); 242cdf0e10cSrcweir String complexFilter = "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )"; 243cdf0e10cSrcweir 244cdf0e10cSrcweir try{ 245cdf0e10cSrcweir xComposer.setHavingClause(complexFilter); 246cdf0e10cSrcweir PropertyValue[][] aStructuredHaving = oObj.getStructuredHavingClause(); 247cdf0e10cSrcweir xComposer.setHavingClause(""); 248cdf0e10cSrcweir xComposer.setStructuredHavingClause(aStructuredHaving); 249cdf0e10cSrcweir tRes.tested("getStructuredHavingClause()", 250cdf0e10cSrcweir (oObj.getHavingClause().equals(complexFilter))); 251cdf0e10cSrcweir 252cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 253cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 254cdf0e10cSrcweir tRes.tested("getStructuredHavingClause()", false); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir /** 259cdf0e10cSrcweir * Object relation <code>xComposer</code> set an order. This order 260cdf0e10cSrcweir * must returned while calling <code>getOrder</code> 261cdf0e10cSrcweir */ 262cdf0e10cSrcweir public void _getOrder() { 263cdf0e10cSrcweir try{ 264cdf0e10cSrcweir String order = "\"Identifier\""; 265cdf0e10cSrcweir xComposer.setOrder(order); 266cdf0e10cSrcweir tRes.tested("getOrder()", (oObj.getOrder().equals(order))); 267cdf0e10cSrcweir 268cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e){ 269cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 270cdf0e10cSrcweir tRes.tested("getOrder()", false); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir /** 275cdf0e10cSrcweir * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code> 276cdf0e10cSrcweir * Test has ok status if returned value is an useable <code>XIndexAccess</code> 277cdf0e10cSrcweir */ 278cdf0e10cSrcweir public void _getOrderColumns() { 279cdf0e10cSrcweir try{ 280cdf0e10cSrcweir XIndexAccess xOrderColumns = oObj.getOrderColumns(); 281cdf0e10cSrcweir tRes.tested("getOrderColumns()", (xOrderColumns != null && 282cdf0e10cSrcweir xOrderColumns.getCount() == 1 && 283cdf0e10cSrcweir xOrderColumns.getByIndex(0) != null)); 284cdf0e10cSrcweir 285cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e){ 286cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 287cdf0e10cSrcweir tRes.tested("getOrderColumns()", false); 288cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 289cdf0e10cSrcweir log.println("unexpected Exception: " + e.toString()); 290cdf0e10cSrcweir tRes.tested("getOrderColumns()", false); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir 295cdf0e10cSrcweir } // finish class _XSingleSelectQueryAnalyzer 296