View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 org.kuali.common.jdbc.supplier;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.junit.Test;
22  import org.kuali.common.jdbc.DefaultSqlReader;
23  import org.kuali.common.jdbc.SqlMetaData;
24  import org.kuali.common.jdbc.SqlReader;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.util.Assert;
28  
29  public class ComplexStringSupplierTest {
30  
31  	private static final Logger logger = LoggerFactory.getLogger(ComplexStringSupplierTest.class);
32  
33  	@Test
34  	public void test() {
35  		String singleSqlStatement = "select sysdate from dual\n/\n";
36  		int count = 5;
37  		StringBuilder sb = new StringBuilder();
38  		for (int i = 0; i < count; i++) {
39  			sb.append(singleSqlStatement);
40  		}
41  		List<String> list = new ArrayList<String>();
42  		list.add(sb.toString());
43  		list.add(sb.toString());
44  		list.add(sb.toString());
45  		list.add("select sysdate from dual");
46  
47  		SqlReader reader = new DefaultSqlReader();
48  
49  		ComplexStringSupplier supplier = new ComplexStringSupplier();
50  		supplier.setStrings(list);
51  		supplier.setReader(reader);
52  
53  		supplier.fillInMetaData();
54  		SqlMetaData smd = supplier.getMetaData();
55  
56  		Assert.isTrue(smd.getCount() == count * 3 + 1);
57  
58  		supplier.open();
59  		List<String> sql = supplier.getSql();
60  		while (sql != null) {
61  			for (String s : sql) {
62  				logger.info(s);
63  			}
64  			sql = supplier.getSql();
65  		}
66  		supplier.close();
67  
68  	}
69  
70  }