-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c446430
commit e8061e8
Showing
3 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/test/org/fugerit/java/query/export/tool/TestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package test.org.fugerit.java.query.export.tool; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import org.junit.AfterClass; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TestBase { | ||
|
||
protected final static Logger logger = LoggerFactory.getLogger( TestBase.class ); | ||
|
||
/** | ||
* Database initialization for testing i.e. | ||
* <ul> | ||
* <li>Creating Table</li> | ||
* <li>Inserting record</li> | ||
* </ul> | ||
* | ||
* @throws SQLException | ||
*/ | ||
protected static void initDatabase() throws SQLException { | ||
try (Connection connection = getConnection(); Statement statement = connection.createStatement();) { | ||
statement.execute("CREATE TABLE test_export (id INT NOT NULL, name VARCHAR(50) NOT NULL," | ||
+ "email VARCHAR(50) NOT NULL, PRIMARY KEY (id))"); | ||
connection.commit(); | ||
statement.executeUpdate("INSERT INTO test_export VALUES (1001,'FieldA1', 'FieldB1')"); | ||
statement.executeUpdate("INSERT INTO test_export VALUES (1002,'FieldA2', 'FieldB2')"); | ||
statement.executeUpdate("INSERT INTO test_export VALUES (1003,'FieldA3', 'FieldB3')"); | ||
connection.commit(); | ||
} | ||
} | ||
|
||
/** | ||
* Create a connection | ||
* | ||
* @return connection object | ||
* @throws SQLException | ||
*/ | ||
protected static Connection getConnection() throws SQLException { | ||
return DriverManager.getConnection("jdbc:hsqldb:mem:employees", "vinod", "vinod"); | ||
} | ||
|
||
@AfterClass | ||
public static void destroy() throws SQLException, ClassNotFoundException, IOException { | ||
try (Connection connection = getConnection(); Statement statement = connection.createStatement();) { | ||
statement.executeUpdate("DROP TABLE test_export"); | ||
connection.commit(); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/test/org/fugerit/java/query/export/tool/TestCSV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package test.org.fugerit.java.query.export.tool; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
|
||
import org.fugerit.java.query.export.facade.QueryExportConfig; | ||
import org.fugerit.java.query.export.facade.QueryExportFacade; | ||
import org.junit.Test; | ||
|
||
public class TestCSV extends TestBase { | ||
|
||
@Test | ||
public void test() { | ||
try { | ||
initDatabase(); | ||
logger.info( "test start" ); | ||
FileOutputStream fos = new FileOutputStream( new File( "target/test_export.csv" ) ); | ||
String query = " SELECT * FROM test_export "; | ||
QueryExportConfig config = QueryExportConfig.newConfigCSV( fos , getConnection(), query ); | ||
QueryExportFacade.export( config ); | ||
logger.info( "test end" ); | ||
} catch (Exception e) { | ||
String message = "Error "+e.getMessage(); | ||
logger.error( message, e ); | ||
fail( message ); | ||
} | ||
|
||
} | ||
|
||
} |