-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an additional test to verify cells population
- Loading branch information
1 parent
089b296
commit a4e3ea3
Showing
14 changed files
with
141 additions
and
6 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
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
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,10 @@ | ||
package excel2db.service; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public interface GetFirstRow { | ||
|
||
public ResultSet getFirstRow (String tableName) throws SQLException; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/excel2db/service/impl/GetFirstRowDerbyImpl.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,24 @@ | ||
package excel2db.service.impl; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import excel2db.excel2db; | ||
import excel2db.service.GetFirstRow; | ||
|
||
public class GetFirstRowDerbyImpl implements GetFirstRow { | ||
|
||
ResultSet firstRow ; | ||
|
||
@Override | ||
public ResultSet getFirstRow(String tableName) throws SQLException { | ||
|
||
String sqlSelectFirstRow = "SELECT * FROM " + tableName + " FETCH FIRST ROW ONLY"; | ||
PreparedStatement pstmtSelectFirstRow = excel2db.connection.prepareStatement(sqlSelectFirstRow); | ||
firstRow = pstmtSelectFirstRow.executeQuery(); | ||
return firstRow; | ||
|
||
} | ||
|
||
} |
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
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
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
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
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,3 @@ | ||
|
||
public interface JUnitPopulateCellsCategory { | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
public class JUnitSuiteInitFiles { | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
|
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,14 @@ | ||
|
||
|
||
import org.junit.experimental.categories.Categories; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
|
||
@RunWith(Categories.class) | ||
@Categories.IncludeCategory(JUnitPopulateCellsCategory.class) | ||
@Suite.SuiteClasses(PopulateCellsImplTest.class) | ||
public class JUnitSuitePopulateCells { | ||
|
||
} | ||
|
||
|
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
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,66 @@ | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.ResultSet; | ||
|
||
import excel2db.excel2db; | ||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = "/spring.xml") | ||
@Category(JUnitPopulateCellsCategory.class) | ||
@TestPropertySource("/excel2db.properties") | ||
|
||
public class PopulateCellsImplTest { | ||
|
||
private Sheet sheet; | ||
private String resultSetValue; | ||
|
||
@Test | ||
public void testPopulateCellsImpl() throws Exception { | ||
|
||
//initializing application context | ||
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); | ||
excel2db app = (excel2db) context.getBean("excel2db"); | ||
//executing the test | ||
File fileName = new File(app.initConstants.workingDir + "/test.xlsx"); | ||
|
||
sheet = app.initInputFiles.initInputFiles(fileName); | ||
|
||
//create and populate a table | ||
app.dbConnection.establishDBConnection(); | ||
app.createTable.createTable(sheet, "TEST"); | ||
app.populateTable.populateTable(sheet, "TEST"); | ||
ResultSet rs = app.getFirstRow.getFirstRow("TEST"); | ||
|
||
//concatenate values in the result set row | ||
while (rs.next()){ | ||
resultSetValue = | ||
rs.getString("Column1") + " " + | ||
rs.getString("Column2") + " " + | ||
rs.getString("Column3") + " " + | ||
rs.getString("Column4") + " " + | ||
rs.getString("Column5") + " " + | ||
rs.getString("Column6") + " " + | ||
rs.getString("Column7") + " " + | ||
rs.getString("Column8") + " " + | ||
rs.getString("Column9") + " " + | ||
rs.getString("Column10") | ||
; | ||
} | ||
|
||
//compare with the expected result | ||
assertEquals("Value 11 Value 12 Value 13 Value 14 Value 15 Value 16 Value 17 Value 18 Value 19 Value 110", resultSetValue); | ||
|
||
} | ||
|
||
} |
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