Permalink
Browse files

add testing of update_database destination

  • Loading branch information...
1 parent b7c3c46 commit 9073b9872988282c1c2675d76cf32715cc56c16c @gkfabs gkfabs committed Jun 1, 2011
Showing with 64 additions and 0 deletions.
  1. +34 −0 test/delimited_update.ctl
  2. +30 −0 test/destination_test.rb
View
@@ -0,0 +1,34 @@
+source :in, {
+ :file => 'data/delimited.txt',
+ :parser => {
+ :name => :delimited
+ }
+},
+[
+ :first_name,
+ :last_name,
+ :ssn,
+ :age,
+ :sex
+]
+
+#transform :age, :type, :type => :number
+transform :ssn, :sha1
+transform(:ssn){ |n, v, row| v[0,24] }
+transform :sex, :decode, {:decode_table_path => 'data/decode.txt'}
+
+destination :out, {
+ :type => :update_database,
+ :target => :data_warehouse,
+ :database => 'etl_unittest',
+ :table => 'people'
+},
+{
+ :conditions => [{:field => "\#{conn.quote_column_name(:id)}", :value => "\#{conn.quote(row[:id])}", :comp => "="}],
+ :order => [:id, :first_name, :last_name, :ssn, :age, :sex, :test, :calc_test],
+ :virtual => {
+ :id => :surrogate_key,
+ :test => "test!",
+ :calc_test => Time.now
+ },
+}
View
@@ -210,6 +210,36 @@ def test_excel_destination
assert_equal "US", sheet[0, 4]
end
+ # Test a update database destination
+ def test_update_database_destination
+ row = ETL::Row[:id => 1, :first_name => 'Bob', :last_name => 'Smith', :ssn => '111234444']
+ control = ETL::Control::Control.parse(File.dirname(__FILE__) +
+ '/delimited_update.ctl')
+
+ Person.delete_all
+ assert_equal 0, Person.count
+ test_database_destination
+
+ # First define a basic configuration to check defaults
+ configuration = {
+ :type => :update_database,
+ :target => :data_warehouse,
+ :database => 'etl_unittest',
+ :table => 'people',
+ :buffer_size => 0
+ }
+ mapping = {
+ :conditions => [{:field => "\#{conn.quote_column_name(:id)}", :value => "\#{conn.quote(row[:id])}", :comp => "="}],
+ :order => [:id, :first_name, :last_name, :ssn]
+ }
+ dest = ETL::Control::UpdateDatabaseDestination.new(control, configuration, mapping)
+ dest.write(row)
+ dest.close
+
+ assert_equal 1, Person.find(:all).length
+
+ end
+
# Test a insert update database destination
def test_insert_update_database_destination
row = ETL::Row[:id => 1, :first_name => 'Bob', :last_name => 'Smith', :ssn => '111234444']

0 comments on commit 9073b98

Please sign in to comment.