Commits

tbrugz  committed 54d85c7

test: added SQLRunTest

  • Participants
  • Parent commits 6e0908b

Comments (0)

Files changed (5)

File src_test/tbrugz/sqldump/AllTestSuite.java

 import tbrugz.sqldiff.SQLDiff;
 import tbrugz.sqldiff.test.SQLDiffTest;
 import tbrugz.sqldump.datadump.DataDumpTest;
+import tbrugz.sqldump.sqlrun.SQLRunTest;
 import tbrugz.sqldump.test.SQLDumpTestSuite;
-import tbrugz.sqldump.util.ParametrizedProperties;
 import tbrugz.sqldump.util.ParametrizedPropertiesTest;
 import tbrugz.sqlrun.test.CSVImportTest;
 
 	ParametrizedPropertiesTest.class,
 	SQLDumpTestSuite.class,
 	SQLDiffTest.class,
+	SQLRunTest.class
 })
 public class AllTestSuite {
 

File src_test/tbrugz/sqldump/sqlrun/SQLRunTest.java

+package tbrugz.sqldump.sqlrun;
+
+import org.junit.Test;
+
+import tbrugz.sqldump.SQLDump;
+
+public class SQLRunTest {
+	@Test
+	public void doRun() throws Exception {
+		String[] vmparams = {
+				"-Dsqlrun.exec.01.file=src_test/tbrugz/sqldump/sqlrun/empdept.sql",
+				"-Dsqlrun.exec.02.import=csv",
+				"-Dsqlrun.exec.02.inserttable=dept",
+				"-Dsqlrun.exec.02.importfile=src_test/tbrugz/sqldump/sqlrun/dept.csv",
+				"-Dsqlrun.exec.02.skipnlines=1",
+				"-Dsqlrun.exec.05.import=csv",
+				"-Dsqlrun.exec.05.inserttable=emp",
+				"-Dsqlrun.exec.05.importfile=src_test/tbrugz/sqldump/sqlrun/emp.csv",
+				"-Dsqlrun.exec.05.skipnlines=1",
+				"-Dsqlrun.driverclass=org.h2.Driver",
+				"-Dsqlrun.dburl=jdbc:h2:work/db/empdept",
+				"-Dsqlrun.user=h",
+				"-Dsqlrun.password=h"
+				};
+		String[] params = {};
+		setProperties(vmparams);
+		SQLRun.main(params);
+		
+		String[] vmparamsDump = {
+					"-Dsqldump.schemagrab.grabclass=JDBCSchemaGrabber",
+					"-Dsqldump.schemadump.dumpclasses=JAXBSchemaXMLSerializer, SchemaModelScriptDumper",
+					"-Dsqldump.processingclasses=DataDump",
+					"-Dsqldump.mainoutputfilepattern=work/output/dbobjects.sql",
+					"-Dsqldump.schemadump.dumpdropstatements=true",
+					"-Dsqldump.datadump.dumpsyntaxes=insertinto",
+					"-Dsqldump.datadump.outfilepattern=work/output/${tablename}.${syntaxfileext}",
+					"-Dsqldump.datadump.writebom=false",
+					"-Dsqldump.xmlserialization.jaxb.outfile=work/output/empdept.jaxb.xml",
+					"-Dsqldump.driverclass=org.h2.Driver",
+					"-Dsqldump.dburl=jdbc:h2:work/db/empdept",
+					"-Dsqldump.user=h",
+					"-Dsqldump.password=h"
+					};
+		setProperties(vmparamsDump);
+		SQLDump.main(params);
+	}
+	
+	void setProperties(String[] vmparams) {
+		for(String s: vmparams) {
+			String key = null, value = null; 
+			if(s.startsWith("-D")) {
+				int i = s.indexOf("=");
+				key = s.substring(2,i);
+				value = s.substring(i+1);
+				System.setProperty(key, value);
+			}
+		}
+	}
+}

File src_test/tbrugz/sqldump/sqlrun/dept.csv

+id,name,parent_id
+0,CEO,0
+1,HR,0
+2,Engineering,0

File src_test/tbrugz/sqldump/sqlrun/emp.csv

+id,name,supervisor_id,department_id,salary
+1,john,1,1,2000
+2,mary,2,2,2000
+3,jane,2,2,1000
+4,lucas,2,2,1200
+5,wilson,1,1,1000

File src_test/tbrugz/sqldump/sqlrun/empdept.sql

+drop table emp if exists;
+
+create table emp (
+	id integer not null,
+	name varchar(100) not null,
+	supervisor_id integer,
+	department_id integer,
+	salary integer,
+	constraint emp_pk primary key (id),
+	constraint emp_emp_fk foreign key (supervisor_id) references emp (id)
+);
+
+drop table dept if exists;
+
+create table dept (
+	id integer not null,
+	name varchar(100),
+	parent_id integer,
+	constraint dept_pk primary key (id),
+);
+
+alter table emp add constraint emp_dept_fk foreign key (department_id) references dept (id);