2020import org .apache .avro .generic .GenericDatumReader ;
2121import org .apache .avro .generic .GenericRecord ;
2222import org .apache .avro .io .DatumReader ;
23- import org .apache .derby .jdbc .EmbeddedDriver ;
24- import org .apache .nifi .util .file .FileUtils ;
25- import org .junit .jupiter .api .AfterEach ;
26- import org .junit .jupiter .api .BeforeAll ;
2723import org .junit .jupiter .api .Test ;
28- import org .junit .jupiter .api .io .TempDir ;
2924
3025import java .io .ByteArrayInputStream ;
3126import java .io .ByteArrayOutputStream ;
32- import java .io .File ;
3327import java .io .IOException ;
3428import java .io .InputStream ;
3529import java .sql .Connection ;
36- import java .sql .DriverManager ;
3730import java .sql .ResultSet ;
3831import java .sql .SQLException ;
3932import java .sql .Statement ;
4033
4134import static org .junit .jupiter .api .Assertions .assertEquals ;
4235import static org .junit .jupiter .api .Assertions .assertNotNull ;
43- import static org .junit .jupiter .api .Assertions .assertThrows ;
4436
45- public class TestJdbcClobReadable {
46-
47- private static final String DERBY_LOG_PROPERTY = "derby.stream.error.file" ;
48-
49- @ TempDir
50- private static File tempDir ;
51-
52- @ BeforeAll
53- public static void setDerbyLog () {
54- final File derbyLog = new File (tempDir , "derby.log" );
55- System .setProperty (DERBY_LOG_PROPERTY , derbyLog .getAbsolutePath ());
56- }
57-
58- @ AfterEach
59- public void cleanup () throws IOException {
60- if (folder != null && folder .exists ()) {
61- final SQLException exception = assertThrows (SQLException .class , () -> DriverManager .getConnection ("jdbc:derby:;shutdown=true" ));
62- assertEquals ("XJ015" , exception .getSQLState ());
63- FileUtils .deleteFile (folder , true );
64- }
65- }
37+ class TestJdbcClobReadable extends AbstractConnectionTest {
6638
6739 String createTable = "create table users ("
6840 + " id int NOT NULL GENERATED ALWAYS AS IDENTITY, "
@@ -74,38 +46,25 @@ public void cleanup() throws IOException {
7446 String dropTable = "drop table users" ;
7547
7648 @ Test
77- public void testClobWithChinese () throws SQLException , IOException , ClassNotFoundException {
49+ void testClobWithChinese () throws SQLException , IOException {
7850 String chineseContent = "中国China" ;
7951 validateClob (chineseContent );
8052 }
8153
8254 @ Test
83- public void testClobWithJapanese () throws SQLException , IOException , ClassNotFoundException {
55+ void testClobWithJapanese () throws SQLException , IOException {
8456 String japaneseContent = "にほんJapan" ;
8557 validateClob (japaneseContent );
8658 }
8759
8860 @ Test
89- public void testClobWithKorean () throws SQLException , IOException , ClassNotFoundException {
61+ void testClobWithKorean () throws SQLException , IOException {
9062 String koreanContent = "にほんKorea" ;
9163 validateClob (koreanContent );
9264 }
9365
94- // many test use Derby as database, so ensure driver is available
95- @ Test
96- public void testDriverLoad () throws ClassNotFoundException , SQLException {
97- //Adding this because apparently the driver gets unloaded and unregistered
98- DriverManager .registerDriver (new EmbeddedDriver ());
99- final Class <?> clazz = Class .forName ("org.apache.derby.jdbc.EmbeddedDriver" );
100- assertNotNull (clazz );
101- }
102-
103- private File folder ;
104-
105- private void validateClob (String someClob ) throws SQLException , ClassNotFoundException , IOException {
106- File topLevelTempDir = new File (tempDir , String .valueOf (System .currentTimeMillis ()));
107- folder = new File (topLevelTempDir , "db" );
108- final Connection con = createConnection (folder .getAbsolutePath ());
66+ private void validateClob (String someClob ) throws SQLException , IOException {
67+ final Connection con = getConnection ();
10968 final Statement st = con .createStatement ();
11069
11170 try {
@@ -143,10 +102,4 @@ record = dataFileReader.next(record);
143102 }
144103 }
145104 }
146-
147- private Connection createConnection (String location ) throws ClassNotFoundException , SQLException {
148- DriverManager .registerDriver (new EmbeddedDriver ());
149- Class .forName ("org.apache.derby.jdbc.EmbeddedDriver" );
150- return DriverManager .getConnection ("jdbc:derby:" + location + ";create=true" );
151- }
152105}
0 commit comments