diff --git a/src/main/java/excel2db/Excel2dbTask.java b/src/main/java/excel2db/Excel2dbTask.java new file mode 100644 index 0000000..34b9b34 --- /dev/null +++ b/src/main/java/excel2db/Excel2dbTask.java @@ -0,0 +1,40 @@ +package excel2db; + +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; + +import com.ge.mdm.tools.common.ApplicationException; +import org.apache.commons.io.FilenameUtils; + +public class Excel2dbTask extends Thread { + + public Excel2dbTask(excel2db app, File fileName) { + this.app = app; + this.fileName = fileName; + } + + public excel2db app; + public File fileName; + + String tableName; + + @Override + public void run() { + try { + app.initInputFiles.initInputFiles(fileName); + + tableName = FilenameUtils.removeExtension(fileName.getName()); + app.createTable.createTable(tableName); + app.populateTable.populateTable(tableName); + + } catch (IOException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (ApplicationException e) { + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/excel2db/InsertDBRecord.java b/src/main/java/excel2db/InsertDBRecord.java new file mode 100644 index 0000000..6c7ad4b --- /dev/null +++ b/src/main/java/excel2db/InsertDBRecord.java @@ -0,0 +1,35 @@ +package excel2db; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + + +public class InsertDBRecord extends Thread { + + public InsertDBRecord(PreparedStatement insertDBRecordStatement) { + this.insertDBRecordStatement = insertDBRecordStatement; + } + + public PreparedStatement insertDBRecordStatement; + + public static final Logger logger = LoggerFactory.getLogger(InsertDBRecord.class); + + @Override + public void run() { + try { + logger.info("Thread " + getName() + " started"); + insertDBRecordStatement.execute(); + logger.info("Thread " + getName() + " finished"); + } catch (SQLException e) { + //Log the error somehow + } +// catch (InterruptedException e) { +// //Log the error somehow +// } + + } + +} diff --git a/src/main/java/excel2db/excel2db.java b/src/main/java/excel2db/excel2db.java index 1ca87e5..c51a08d 100644 --- a/src/main/java/excel2db/excel2db.java +++ b/src/main/java/excel2db/excel2db.java @@ -1,114 +1,96 @@ - package excel2db; +import java.io.File; +import java.sql.Connection; +import java.sql.SQLException; import com.ge.mdm.tools.common.ApplicationException; -import com.ge.mdm.tools.common.SheetEntityManager; import excel2db.service.CreateTable; import excel2db.service.DBConnection; +import excel2db.service.GenerateFileList; +import excel2db.service.InitConstants; +import excel2db.service.InitInputFiles; import excel2db.service.PopulateTable; -import org.apache.commons.io.FilenameUtils; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.io.File; -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; public class excel2db + { + public static final Logger logger = LoggerFactory.getLogger(excel2db.class); // declaring the constructor to meet to the Spring framework convention // constructor injection method (CI)) - public excel2db (CreateTable createTable, PopulateTable populateTable) { + public excel2db(CreateTable createTable, PopulateTable populateTable) { this.createTable = createTable; this.populateTable = populateTable; } - private Workbook workbook; - - private File inputSheetFile; - private File outputSheetFile; - private String fileExtension; //vars are used in interface implementations public static Connection connection = null; - public static SheetEntityManager sheetEntityManager; - public static Sheet sheet; - public static Short numberProcessedRecords = Short.valueOf((short)0); + public static Short numberProcessedRecords = Short.valueOf((short) 0); // declaring variables to meet to the Spring framework convention public DBConnection dbConnection; + public InitInputFiles initInputFiles; + public GenerateFileList generateFileList; public CreateTable createTable; public PopulateTable populateTable; + public InitConstants initConstants; - - public File getInputSheetFile() { return inputSheetFile; } - - public void setInputSheetFile(File inputSheetFile) - { - this.inputSheetFile = inputSheetFile; - } - - public File getOutputSheetFile() { - return outputSheetFile; - } - - public void setOutputSheetFile(File outputSheetFile) { - this.outputSheetFile = outputSheetFile; - } - + public static ThreadPoolTaskExecutor taskExecutor; // declaring setters to meet to the Spring framework convention. // Setter injection method (SI)) - public void setDbConnection(DBConnection dbConnection) - { + public void setDbConnection(DBConnection dbConnection) { this.dbConnection = dbConnection; } + public void setInitInputFiles(InitInputFiles initInputFiles) { + this.initInputFiles = initInputFiles; + } + public void setGenerateFileList(GenerateFileList generateFileList) { + this.generateFileList = generateFileList; + } + public void setInitConstants(InitConstants initConstants) { + this.initConstants = initConstants; + } - public static void main(String[] args) - { - if (args.length < 1) { - logger.error("Need file name as an argument."); - System.exit(1); - } - - logger.info("excel2db : Passing file name as an argument ; " + String.join(" ", args)); - File inputFile = new File(args[0]); + public static void main(String[] args) { - try - { + try { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); - excel2db app = (excel2db)context.getBean("excel2db"); + excel2db app = (excel2db) context.getBean("excel2db"); - app.setInputSheetFile(inputFile); - app.initAndValidate(); + taskExecutor = (ThreadPoolTaskExecutor) context.getBean("taskExecutor"); //this way we call methods for objects that is already initialized by the Spring app.dbConnection.establishDBConnection(); - app.createTable.createTable(); - app.populateTable.populateTable(); + + // iterate through file name values inn properties file + for (String fileNameValue : app.generateFileList.generateFileList()) { + File fileName = new File(fileNameValue); + taskExecutor.execute(new Excel2dbTask(app, fileName)); + } + + // Wait until all threads are finished + logger.info("Waiting until active threads exist"); + while (excel2db.taskExecutor.getActiveCount() != 0) { + } + logger.info("All threads are inactive"); app.closeConnections(); - } - catch (Exception e) { + } catch (Exception e) { logger.error("An exception occurred while running application", e); System.exit(1); } @@ -116,71 +98,17 @@ public static void main(String[] args) } - public void initAndValidate() - throws ApplicationException, IOException - { - logger.info("Reading input file '{}'...", inputSheetFile.getAbsolutePath()); - - - fileExtension = FilenameUtils.getExtension(inputSheetFile.getName()); - if (fileExtension.equalsIgnoreCase("xlsx")) { - workbook = createWorkbook(openOPCPackage(inputSheetFile)); - } else { - workbook = createWorkbook(openNPOIFSFileSystemPackage(inputSheetFile)); - } - - sheet = workbook.getSheetAt(0); - if (sheet == null) { - throw new ApplicationException("Workbook does not contain a sheet with index 0"); - } - - sheetEntityManager = new SheetEntityManager(sheet); - } - - - private static OPCPackage openOPCPackage(File file) - throws ApplicationException - { - try - { - return OPCPackage.open(file); - } catch (InvalidFormatException e) { - throw new ApplicationException("Unable to open OPC package from " + file.getAbsolutePath(), e); - } - } - - private static NPOIFSFileSystem openNPOIFSFileSystemPackage(File file) throws ApplicationException - { - try { - return new NPOIFSFileSystem(file); - } catch (IOException e) { - throw new ApplicationException("Unable to open NPOIFSFileSystem package from " + file.getAbsolutePath(), e); - } - } - - private static Workbook createWorkbook(OPCPackage pkg) throws ApplicationException - { - try { - return new XSSFWorkbook(pkg); - } catch (IOException e) { - throw new ApplicationException("Unable to create workbook from OPC package", e); - } - } - - private static Workbook createWorkbook(NPOIFSFileSystem pkg) throws ApplicationException - { - try { - return new HSSFWorkbook(pkg); - } catch (IOException e) { - throw new ApplicationException("Unable to create workbook from NPOIFSFileSystem package", e); - } - } - public void closeConnections() throws ApplicationException, SQLException { logger.info("Closing connections"); connection.close(); - logger.info("The Process is Completed"); - logger.info("Number of Processed Records: " + numberProcessedRecords.toString()); + + logger.info("Closing task executor "); + taskExecutor.shutdown(); + logger.info("Task executor is stopped"); + + logger.info("The process is completed"); + logger.info("Number of processed records: " + numberProcessedRecords.toString()); + } } \ No newline at end of file diff --git a/src/main/java/excel2db/service/CreateTable.java b/src/main/java/excel2db/service/CreateTable.java index d73f319..3d49482 100644 --- a/src/main/java/excel2db/service/CreateTable.java +++ b/src/main/java/excel2db/service/CreateTable.java @@ -4,6 +4,6 @@ public interface CreateTable { - public void createTable () throws SQLException; + public void createTable(String tableName) throws SQLException; } diff --git a/src/main/java/excel2db/service/DBConnection.java b/src/main/java/excel2db/service/DBConnection.java index 517f26a..9b6a8f4 100644 --- a/src/main/java/excel2db/service/DBConnection.java +++ b/src/main/java/excel2db/service/DBConnection.java @@ -1,7 +1,6 @@ - package excel2db.service; -public interface DBConnection { +public interface DBConnection { public void establishDBConnection(); diff --git a/src/main/java/excel2db/service/GenerateFileList.java b/src/main/java/excel2db/service/GenerateFileList.java new file mode 100644 index 0000000..fb7e3f5 --- /dev/null +++ b/src/main/java/excel2db/service/GenerateFileList.java @@ -0,0 +1,8 @@ +package excel2db.service; + +import java.util.HashSet; + +public interface GenerateFileList { + public HashSet generateFileList(); +} + diff --git a/src/main/java/excel2db/service/InitConstants.java b/src/main/java/excel2db/service/InitConstants.java new file mode 100644 index 0000000..f3e4b03 --- /dev/null +++ b/src/main/java/excel2db/service/InitConstants.java @@ -0,0 +1,7 @@ +package excel2db.service; + +public class InitConstants { + + public final static String workingDir = System.getProperty("user.dir"); + +} diff --git a/src/main/java/excel2db/service/InitInputFiles.java b/src/main/java/excel2db/service/InitInputFiles.java new file mode 100644 index 0000000..5baf6dd --- /dev/null +++ b/src/main/java/excel2db/service/InitInputFiles.java @@ -0,0 +1,12 @@ +package excel2db.service; + +import java.io.File; +import java.io.IOException; + +import com.ge.mdm.tools.common.ApplicationException; +import org.apache.poi.ss.usermodel.Sheet; + +public interface InitInputFiles { + public Sheet initInputFiles(File inputFile) throws IOException, ApplicationException; +} + diff --git a/src/main/java/excel2db/service/PopulateTable.java b/src/main/java/excel2db/service/PopulateTable.java index f27668e..6fe97ea 100644 --- a/src/main/java/excel2db/service/PopulateTable.java +++ b/src/main/java/excel2db/service/PopulateTable.java @@ -4,6 +4,6 @@ public interface PopulateTable { - public void populateTable () throws SQLException; + public Integer populateTable(String tableName) throws SQLException; } diff --git a/src/main/java/excel2db/service/impl/CreateTablePostgresImpl.java b/src/main/java/excel2db/service/impl/CreateTablePostgresImpl.java index 554be34..ae2b336 100644 --- a/src/main/java/excel2db/service/impl/CreateTablePostgresImpl.java +++ b/src/main/java/excel2db/service/impl/CreateTablePostgresImpl.java @@ -1,24 +1,32 @@ package excel2db.service.impl; -import excel2db.excel2db; -import excel2db.service.CreateTable; - import java.sql.PreparedStatement; import java.sql.SQLException; -public class CreateTablePostgresImpl implements CreateTable { +import com.ge.mdm.tools.common.SheetEntityManager; +import excel2db.excel2db; +import excel2db.service.CreateTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - public void createTable() throws SQLException - { - String sqlTableDropStatement = "DROP TABLE IF EXISTS excel2db;"; +public class CreateTablePostgresImpl implements CreateTable { + public static final Logger logger = LoggerFactory.getLogger(CreateTablePostgresImpl.class); + private SheetEntityManager sheetEntityManager; - StringBuilder sqlTableCreateStatement = new StringBuilder(); + public void createTable(String tableName) throws SQLException { - sqlTableCreateStatement.append("CREATE TABLE excel2db("); + sheetEntityManager = new SheetEntityManager(InitInputFilesImpl.sheet); + //dropping statement + String sqlTableDropStatement = "DROP TABLE IF EXISTS \"" + + tableName + "\""; - for (String headerColumnName : excel2db.sheetEntityManager.header.keySet()) { + //creating statement + StringBuilder sqlTableCreateStatement = new StringBuilder(); + sqlTableCreateStatement.append("CREATE TABLE \"" + + tableName + "\"("); + for (String headerColumnName : sheetEntityManager.header.keySet()) { sqlTableCreateStatement.append("\"" + headerColumnName + "\"" + " text, "); } @@ -27,12 +35,17 @@ public void createTable() throws SQLException sqlTableCreateStatement.append(") WITH (OIDS=FALSE);"); - + //dropping + logger.info("The table " + tableName + " is being dropped"); PreparedStatement pstmtDrop = excel2db.connection.prepareStatement(sqlTableDropStatement); pstmtDrop.execute(); + logger.info("The table " + tableName + " has been dropped"); + //creating + logger.info("The table " + tableName + " is being created"); PreparedStatement pstmtCreate = excel2db.connection.prepareStatement(sqlTableCreateStatement.toString()); pstmtCreate.execute(); + logger.info("The table " + tableName + " has been created"); } diff --git a/src/main/java/excel2db/service/impl/DBConnectionOracleImpl.java b/src/main/java/excel2db/service/impl/DBConnectionOracleImpl.java index f9ee5d6..5765272 100644 --- a/src/main/java/excel2db/service/impl/DBConnectionOracleImpl.java +++ b/src/main/java/excel2db/service/impl/DBConnectionOracleImpl.java @@ -26,9 +26,9 @@ public class DBConnectionOracleImpl implements DBConnection { public static final Logger logger = LoggerFactory.getLogger(DBConnectionPostgresImpl.class); public void establishDBConnection() { - { - logger.info("Oracle connection is not implemented yet"); - } + { + logger.info("Oracle connection is not implemented yet"); + } } } diff --git a/src/main/java/excel2db/service/impl/DBConnectionPostgresImpl.java b/src/main/java/excel2db/service/impl/DBConnectionPostgresImpl.java index bf3a7ba..50287c6 100644 --- a/src/main/java/excel2db/service/impl/DBConnectionPostgresImpl.java +++ b/src/main/java/excel2db/service/impl/DBConnectionPostgresImpl.java @@ -1,14 +1,14 @@ package excel2db.service.impl; +import java.sql.DriverManager; +import java.sql.SQLException; + import excel2db.excel2db; import excel2db.service.DBConnection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import java.sql.DriverManager; -import java.sql.SQLException; - public class DBConnectionPostgresImpl implements DBConnection { // connection parameters @@ -27,13 +27,14 @@ public class DBConnectionPostgresImpl implements DBConnection { @Value("${db.database}") String dbDatabase; + public static final Logger logger = LoggerFactory.getLogger(DBConnectionPostgresImpl.class); public void establishDBConnection() { try { excel2db.connection = DriverManager.getConnection( - "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbDatabase, dbUser, dbPassword) - ; + "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbDatabase, dbUser, dbPassword) + ; } catch (SQLException e) { logger.error("Connection Failed! Check output console"); @@ -46,5 +47,4 @@ public void establishDBConnection() { logger.error("Failed to make connection!"); } } - } diff --git a/src/main/java/excel2db/service/impl/GenerateFileListImpl.java b/src/main/java/excel2db/service/impl/GenerateFileListImpl.java new file mode 100644 index 0000000..d9632c7 --- /dev/null +++ b/src/main/java/excel2db/service/impl/GenerateFileListImpl.java @@ -0,0 +1,26 @@ + +package excel2db.service.impl; + +import java.util.Arrays; +import java.util.HashSet; + +import excel2db.service.GenerateFileList; +import org.springframework.beans.factory.annotation.Value; + +public class GenerateFileListImpl implements GenerateFileList { + + @Value("${input.files}") + String inputFilesList; + + @Override + public HashSet generateFileList() { + + String[] fileNameArray = inputFilesList.split(","); + + // hash set to eliminate duplicates + HashSet fileList = new HashSet<>(Arrays.asList(fileNameArray)); + + return fileList; + + } +} diff --git a/src/main/java/excel2db/service/impl/InitInputFilesImpl.java b/src/main/java/excel2db/service/impl/InitInputFilesImpl.java new file mode 100644 index 0000000..f297c39 --- /dev/null +++ b/src/main/java/excel2db/service/impl/InitInputFilesImpl.java @@ -0,0 +1,103 @@ +package excel2db.service.impl; + +import java.io.File; +import java.io.IOException; + +import com.ge.mdm.tools.common.ApplicationException; +import excel2db.service.InitInputFiles; +import org.apache.commons.io.FilenameUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class InitInputFilesImpl implements InitInputFiles { + + //now implement reading from settings file + + private Workbook workbook; + private File inputSheetFile; + private String fileExtension; + + public static Sheet sheet; + + + public File getInputSheetFile() { + return inputSheetFile; + } + + public void setInputSheetFile(File inputSheetFile) { + this.inputSheetFile = inputSheetFile; + } + + public static final Logger logger = LoggerFactory.getLogger(InitInputFilesImpl.class); + + @Override + public Sheet initInputFiles(File inputFile) + throws ApplicationException, IOException { + + setInputSheetFile(inputFile); + + logger.info("Reading input file '{}'...", inputSheetFile.getAbsolutePath()); + + + fileExtension = FilenameUtils.getExtension(inputSheetFile.getName()); + if (fileExtension.equalsIgnoreCase("xlsx")) { + workbook = createWorkbook(openOPCPackage(inputSheetFile)); + } else { + workbook = createWorkbook(openNPOIFSFileSystemPackage(inputSheetFile)); + } + + sheet = workbook.getSheetAt(0); + if (sheet == null) { + throw new ApplicationException("Workbook does not contain a sheet with index 0"); + } + + return sheet; + + } + + + private static OPCPackage openOPCPackage(File file) + throws ApplicationException { + try { + return OPCPackage.open(file); + } catch (InvalidFormatException e) { + throw new ApplicationException("Unable to open OPC package from " + file.getAbsolutePath(), e); + } + } + + + private static NPOIFSFileSystem openNPOIFSFileSystemPackage(File file) throws ApplicationException { + try { + return new NPOIFSFileSystem(file); + } catch (IOException e) { + throw new ApplicationException("Unable to open NPOIFSFileSystem package from " + file.getAbsolutePath(), e); + } + } + + + private static Workbook createWorkbook(OPCPackage pkg) throws ApplicationException { + try { + return new XSSFWorkbook(pkg); + } catch (IOException e) { + throw new ApplicationException("Unable to create workbook from OPC package", e); + } + } + + + private static Workbook createWorkbook(NPOIFSFileSystem pkg) throws ApplicationException { + try { + return new HSSFWorkbook(pkg); + } catch (IOException e) { + throw new ApplicationException("Unable to create workbook from NPOIFSFileSystem package", e); + } + } + + +} diff --git a/src/main/java/excel2db/service/impl/PopulateTablePostgresImpl.java b/src/main/java/excel2db/service/impl/PopulateTablePostgresImpl.java index 13a5422..2a4ed4f 100644 --- a/src/main/java/excel2db/service/impl/PopulateTablePostgresImpl.java +++ b/src/main/java/excel2db/service/impl/PopulateTablePostgresImpl.java @@ -1,37 +1,47 @@ package excel2db.service.impl; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Iterator; + import excel2db.excel2db; import excel2db.service.PopulateTable; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Iterator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PopulateTablePostgresImpl implements PopulateTable { + public static final Logger logger = LoggerFactory.getLogger(PopulateTablePostgresImpl.class); + private String cellStringValue; + private Integer numOfProcessedRows = 0; + + public Integer populateTable(String tableName) + throws SQLException { - public void populateTable() - throws SQLException - { - Iterator rowIterator = excel2db.sheet.rowIterator(); + Iterator rowIterator = InitInputFilesImpl.sheet.rowIterator(); + //skip a header if (rowIterator.hasNext()) { rowIterator.next(); } - while (rowIterator.hasNext()) - { - Row row = (Row)rowIterator.next(); + logger.info("The table {} is being populated", tableName); + while (rowIterator.hasNext()) { - Short localShort1 = excel2db.numberProcessedRecords;Short localShort2 = excel2db.numberProcessedRecords = Short.valueOf((short)(excel2db.numberProcessedRecords.shortValue() + 1)); + Row row = (Row) rowIterator.next(); + numOfProcessedRows = numOfProcessedRows++; + + Short localShort1 = excel2db.numberProcessedRecords; + Short localShort2 = excel2db.numberProcessedRecords = Short.valueOf((short) (excel2db.numberProcessedRecords.shortValue() + 1)); StringBuilder sqlTableInsertStatement = new StringBuilder(); - sqlTableInsertStatement.append("INSERT INTO excel2db VALUES"); + sqlTableInsertStatement.append("INSERT INTO \"" + + tableName + "\"" + "VALUES"); sqlTableInsertStatement.append("("); @@ -39,21 +49,28 @@ public void populateTable() short minColIdx = row.getFirstCellNum(); short maxColIdx = row.getLastCellNum(); - for (short colIdx = minColIdx; colIdx < maxColIdx; colIdx = (short)(colIdx + 1)) { + + for (short colIdx = minColIdx; colIdx < maxColIdx; colIdx = (short) (colIdx + 1)) { cellStringValue = ""; Cell cell = row.getCell(colIdx); - if (cell == null) cellStringValue = ""; else cellStringValue = cell.toString(); + if (cell == null) cellStringValue = ""; + else cellStringValue = cell.toString(); sqlTableInsertStatement.append("'" + cellStringValue.replace("'", "''") + "'" + ","); } + sqlTableInsertStatement.setLength(sqlTableInsertStatement.length() - 1); sqlTableInsertStatement.append(")"); PreparedStatement pstmtInsertRow = excel2db.connection.prepareStatement(sqlTableInsertStatement.toString()); + pstmtInsertRow.execute(); } + + return numOfProcessedRows; + } diff --git a/src/main/resources/spring-batch.xml b/src/main/resources/spring-batch.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/spring-job.xml b/src/main/resources/spring-job.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/InitInputFilesImplTest.java b/src/test/java/InitInputFilesImplTest.java new file mode 100644 index 0000000..8a12445 --- /dev/null +++ b/src/test/java/InitInputFilesImplTest.java @@ -0,0 +1,24 @@ +import java.io.File; + +import excel2db.excel2db; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import static org.junit.Assert.assertEquals; + +public class InitInputFilesImplTest { + + @Test + public void testInitInputFilesImpl() throws Exception { + + ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); + excel2db app = (excel2db) context.getBean("excel2db"); + File fileName = new File(app.initConstants.workingDir + "/unitTest.xls"); + + //here we should initialize the sheet object + assertEquals("UnitTestSheet", app.initInputFiles.initInputFiles(fileName).getSheetName()); + + } + +} \ No newline at end of file diff --git a/src/test/java/PopulateTablePostgresImplTest.java b/src/test/java/PopulateTablePostgresImplTest.java new file mode 100644 index 0000000..467b684 --- /dev/null +++ b/src/test/java/PopulateTablePostgresImplTest.java @@ -0,0 +1,16 @@ +import excel2db.service.impl.PopulateTablePostgresImpl; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class PopulateTablePostgresImplTest { + + @Test + public void testPopulateTable() throws Exception { + Integer processedRows = 100; + PopulateTablePostgresImpl popTableObject = new PopulateTablePostgresImpl(); + + //here we should initialize the sheet object + assertEquals(processedRows, processedRows ); + + } +} \ No newline at end of file