KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > FilePropertiesTest


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;
17
18 import scriptella.execution.EtlExecutor;
19 import scriptella.execution.EtlExecutorException;
20 import scriptella.jdbc.QueryHelper;
21 import scriptella.spi.ParametersCallback;
22 import scriptella.spi.QueryCallback;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.util.Arrays JavaDoc;
30
31
32 /**
33  *
34  */

35 public class FilePropertiesTest extends DBTestCase {
36     private static final byte FILE[] = "test file/////".getBytes();
37
38     public void test() throws EtlExecutorException {
39         final Connection JavaDoc con = getConnection("fileproptst");
40         AbstractTestCase.testURLHandler = new TestURLHandler() {
41             public InputStream JavaDoc getInputStream(final URL JavaDoc u) {
42                 return new ByteArrayInputStream JavaDoc(FILE);
43             }
44
45             public OutputStream JavaDoc getOutputStream(final URL JavaDoc u) {
46                 throw new UnsupportedOperationException JavaDoc();
47             }
48
49             public int getContentLength(final URL JavaDoc u) {
50                 return FILE.length;
51             }
52         };
53
54         final EtlExecutor se = newEtlExecutor();
55         se.execute();
56
57         QueryHelper q = new QueryHelper("select (select count(id) from t), c from t");
58         q.execute(con,
59                 new QueryCallback() {
60                     public void processRow(final ParametersCallback rowEvaluator) {
61                         final byte b[] = (byte[]) rowEvaluator.getParameter("c");
62                         assertTrue(Arrays.equals(FILE, b));
63                         assertEquals(3, rowEvaluator.getParameter("1")); //3 rows
64
}
65                 });
66     }
67 }
68
Popular Tags