KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > h2 > H2ScriptTest


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.h2;
17
18 import scriptella.AbstractTestCase;
19 import scriptella.execution.EtlExecutor;
20 import scriptella.execution.EtlExecutorException;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.sql.Connection JavaDoc;
25 import java.sql.DriverManager JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.List JavaDoc;
31
32 /**
33  * Tests a script working with H2.
34  *
35  * @author Fyodor Kupolov
36  * @version 1.0
37  */

38 public class H2ScriptTest extends AbstractTestCase {
39     /**
40      * Runs the script and checks if transformations has been made.
41      *
42      * @throws EtlExecutorException
43      * @throws SQLException
44      * @throws ClassNotFoundException
45      */

46     public void test() throws EtlExecutorException, SQLException JavaDoc, ClassNotFoundException JavaDoc, IOException JavaDoc {
47         Class.forName("org.h2.Driver");
48         //Opening a connection before executing a script to disable shutdown on last connection close.
49
Connection JavaDoc con = DriverManager.getConnection("jdbc:h2:mem:tst");
50         EtlExecutor se = newEtlExecutor();
51         se.execute();
52         ResultSet JavaDoc rs = con.createStatement().executeQuery("SELECT * FROM Test ORDER BY ID");
53         List JavaDoc actual = new ArrayList JavaDoc();
54         while (rs.next()) {
55             Integer JavaDoc n = (Integer JavaDoc) rs.getObject(1);
56             actual.add(n);
57             byte[] expBlob = new byte[4];
58             Arrays.fill(expBlob, n.byteValue());
59             ByteArrayInputStream JavaDoc bais = (ByteArrayInputStream JavaDoc) rs.getObject(2);
60             byte[] actualBlob = new byte[4];
61             bais.read(actualBlob);
62             assertTrue(bais.read()<0); //no bytes are left
63

64             assertTrue(Arrays.equals(expBlob, actualBlob));
65
66         }
67         List JavaDoc exp = Arrays.asList(1, 2, 3);
68         assertEquals(exp, actual);
69
70
71     }
72 }
73
Popular Tags