KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > xpath > XPathConnectionPerfTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.driver.xpath;
17
18 import org.w3c.dom.Document JavaDoc;
19 import org.w3c.dom.Element JavaDoc;
20 import scriptella.AbstractTestCase;
21 import scriptella.configuration.MockConnectionEl;
22 import scriptella.configuration.StringResource;
23 import scriptella.spi.AbstractConnection;
24 import scriptella.spi.Connection;
25 import scriptella.spi.ConnectionParameters;
26 import scriptella.spi.IndexedQueryCallback;
27 import scriptella.spi.MockDriverContext;
28 import scriptella.spi.MockParametersCallbacks;
29 import scriptella.spi.ParametersCallback;
30
31 import javax.xml.parsers.ParserConfigurationException JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Map JavaDoc;
34
35 /**
36  * Tests for {@link scriptella.driver.xpath.XPathConnection}.
37  *
38  * @author Fyodor Kupolov
39  * @version 1.0
40  */

41 public class XPathConnectionPerfTest extends AbstractTestCase {
42     /**
43      * History:
44      * 19.01.2007 - Duron 1.7Mhz - 1125 ms
45      */

46     public void testQuery() {
47         //Create a configuration with non default values
48
Map JavaDoc<String JavaDoc, String JavaDoc> props = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
49         ConnectionParameters cp = new ConnectionParameters(new MockConnectionEl(props, getClass().getResource("excel.xml").toString()), MockDriverContext.INSTANCE);
50
51         Connection con = new Driver().connect(cp);
52         IndexedQueryCallback queryCallback = new IndexedQueryCallback() {
53             protected void processRow(final ParametersCallback parameters, final int rowNumber) {
54                 parameters.getParameter("Cell");
55             }
56         };
57         //Quering 200 times.
58
for (int i = 0; i < 200; i++) {
59             con.executeQuery(new StringResource("/$Workbook/Worksheet/Table/Row"), MockParametersCallbacks.NAME, queryCallback);
60         }
61         assertEquals(600, queryCallback.getRowsNumber());
62     }
63
64     /**
65      * History:
66      * 19.01.2007 - Duron 1.7Mhz - 1220 ms
67      */

68     public void testQueryLargeDOM() throws ParserConfigurationException JavaDoc {
69         //Create a configuration with non default values
70
Document JavaDoc doc = XPathConnection.DBF.newDocumentBuilder().newDocument();
71         Element JavaDoc root = doc.createElement("table");
72         doc.appendChild(root);
73         for (int i = 0; i < 4000; i++) {
74             Element JavaDoc row = doc.createElement("row");
75             row.setAttribute("id", String.valueOf(i));
76             root.appendChild(row);
77         }
78         //Quering 200 times.
79
XPathQueryExecutor qe = new XPathQueryExecutor(doc, new StringResource("/table/row[@id mod 2=0]"), new XPathExpressionCompiler(), new AbstractConnection.StatementCounter());
80         for (int i = 0; i < 20; i++) {
81             IndexedQueryCallback queryCallback = new IndexedQueryCallback() {
82                 protected void processRow(final ParametersCallback parameters, final int rowNumber) {
83                     assertTrue(Integer.parseInt((String JavaDoc) parameters.getParameter("id")) % 2 == 0);
84                 }
85             };
86             qe.execute(queryCallback, MockParametersCallbacks.NULL);
87             assertEquals(2000, queryCallback.getRowsNumber());
88         }
89
90
91     }
92
93
94 }
95
Popular Tags