KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > DBTableCopyTest


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.sql.Connection JavaDoc;
25
26
27 /**
28  * TODO: Add documentation
29  *
30  * @author Fyodor Kupolov
31  * @version 1.0
32  */

33 public class DBTableCopyTest extends DBTestCase {
34     /**
35      * This test copies a data from Table ot Table2
36      */

37     public void test() throws EtlExecutorException {
38         final Connection JavaDoc con = getConnection("test");
39         final EtlExecutor se = newEtlExecutor("DBTableCopyTest.xml");
40         se.execute();
41
42         QueryHelper s = new QueryHelper("select * from test2");
43         final int n[] = new int[]{0};
44
45         s.execute(con,
46                 new QueryCallback() {
47                     public void processRow(final ParametersCallback row) {
48                         n[0]++;
49                         assertEquals(n[0], row.getParameter("ID"));
50                         if (n[0] == 3) { //3rd row column value2 has 'value'
51
assertEquals("value", row.getParameter("value2"));
52                         } else {
53                             assertNull(row.getParameter("value2"));
54                         }
55                     }
56                 });
57         assertEquals(n[0], 3);
58     }
59
60     /**
61      * This test copies data from db1.Table to db2.Table2
62      */

63     public void test2() throws EtlExecutorException {
64         final Connection JavaDoc con = getConnection("test");
65         final Connection JavaDoc con2 = getConnection("test2");
66         final EtlExecutor se = newEtlExecutor("DBTableCopyTest2.xml");
67         se.execute();
68
69         QueryHelper s = new QueryHelper("select * from test2");
70         final int n[] = new int[]{0};
71
72         s.execute(con2,
73                 new QueryCallback() {
74                     public void processRow(final ParametersCallback row) {
75                         n[0]++;
76                         assertEquals(n[0], row.getParameter("ID"));
77                     }
78                 });
79         assertEquals(n[0], 3);
80
81         try {
82             new QueryHelper("select * from test2").execute(con, null);
83             fail("Test2 is absent in the 1st database");
84         } catch (IllegalStateException JavaDoc e) {
85             //OK
86
}
87     }
88 }
89
Popular Tags