incubator-alois-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fla...@apache.org
Subject svn commit: r1031127 [20/22] - in /incubator/alois/trunk: ./ bin/ debian/ doc/ etc/ etc/alois/ etc/alois/apache2/ etc/alois/environments/ etc/alois/prisma/ etc/cron.d/ etc/default/ etc/logrotate.d/ prisma/ prisma/bin/ prisma/conf/ prisma/conf/prisma/ p...
Date Thu, 04 Nov 2010 18:27:42 GMT
Added: incubator/alois/trunk/rails/test/functional/bookmarks_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/bookmarks_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/bookmarks_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/bookmarks_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,113 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'bookmarks_controller'
+
+# Re-raise errors caught by the controller.
+class BookmarksController; def rescue_action(e) raise e end; end
+
+class BookmarksControllerTest < ActionController::TestCase
+  fixtures :bookmarks
+
+  def setup
+    @controller = BookmarksController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+
+    @first_id = Bookmark.find(:first).id
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:bookmarks)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:bookmark)
+    assert assigns(:bookmark).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:bookmark)
+  end
+
+  def test_create
+    num_bookmarks = Bookmark.count
+
+    post :create, :bookmark => {:title => "Test", :controller => "SurveyController", :action => "list"}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_bookmarks + 1, Bookmark.count
+  end
+
+  def test_go
+    get :go, :id => @first_id
+
+    assert_response :redirect
+    assert_redirected_to({:action => 'list', :controller => "AlarmsController"})
+  end
+
+  def test_edit
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:bookmark)
+    assert assigns(:bookmark).valid?
+  end
+
+  def test_update
+    post :update, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'show', :id => @first_id
+  end
+
+  def test_destroy
+    assert_nothing_raised {
+      Bookmark.find(@first_id)
+    }
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      Bookmark.find(@first_id)
+    }
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/charts_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/charts_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/charts_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/charts_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,103 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'charts_controller'
+
+# Re-raise errors caught by the controller.
+class ChartsController; def rescue_action(e) raise e end; end
+
+class ChartsControllerTest < ActionController::TestCase
+  fixtures :charts, :views
+
+  def setup
+    @controller = ChartsController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+    
+    @first_id = Chart.find(:first).id
+  end
+  
+  def test_chart_image
+    c = self.class.test_chart
+    c.render(CHART_RENDER_OPTIONS)
+    
+    get :chart_image, 
+      :chart_tmpdir_hash => CHART_QUERY.hash,
+      :chart_yaml_hash =>  Object.yaml_hash(CHART_AFTER_RENDER_YAML)
+    
+    
+    assert_response :success
+    
+  end
+  
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+  end
+
+  def test_list
+    get :list
+    
+    assert_response :success
+    assert_template 'list'
+    
+    assert_not_nil assigns(:charts)
+  end
+  
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:chart)
+    assert assigns(:chart).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:chart)
+  end
+
+  def test_create
+    num_charts = Chart.count
+
+    post :create, :chart => {:column1 => "test"}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_charts + 1, Chart.count
+  end
+
+  def test_destroy
+    assert_not_nil Chart.find(@first_id)
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      Chart.find(@first_id)
+    }
+    
+  end
+  
+end

Added: incubator/alois/trunk/rails/test/functional/exception_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/exception_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/exception_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/exception_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,32 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'exception_controller'
+
+# Re-raise errors caught by the controller.
+class ExceptionController; def rescue_action(e) raise e end; end
+
+class ExceptionControllerTest < ActionController::TestCase
+  def setup
+    @controller = ExceptionController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+  end
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/filters_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/filters_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/filters_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/filters_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,108 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'filters_controller'
+
+# Re-raise errors caught by the controller.
+class FiltersController; def rescue_action(e) raise e end; end
+
+class FiltersControllerTest < ActionController::TestCase
+  fixtures :filters
+
+  def setup
+    @controller = FiltersController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+
+    @first_id = Filter.find(:first).id
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+    assert_tidy_html
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:filters)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:current_filter)
+    assert assigns(:current_filter).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:current_filter)
+  end
+
+  def test_create
+    num_filters = Filter.count
+
+    post :create, :current_filter => {}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_filters + 1, Filter.count
+  end
+
+  def test_edit_and_update
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:current_filter)
+    assert assigns(:current_filter).valid?
+
+    assert assigns(:state_id)
+    post :add_condition, :operator => "LIKE", :column => "test", :value => "test_value", :state_id => assigns(:state_id)       
+    post :update, :id => @first_id, :state_id => assigns(:state_id)
+    
+    f = Filter.find(@first_id)
+    assert f
+    assert f.conditions
+    assert 2, f.conditions.length
+  end
+
+  def test_destroy
+    assert_not_nil Filter.find(@first_id)
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      Filter.find(@first_id)
+    }
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/ip_ranges_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/ip_ranges_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/ip_ranges_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/ip_ranges_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,61 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class IpRangesControllerTest < ActionController::TestCase
+  fixtures :ip_ranges
+
+  def test_should_get_index
+    get :index
+    assert_response :success
+    assert_not_nil assigns(:ip_ranges)
+  end
+
+  def test_should_get_new
+    get :new
+    assert_response :success
+  end
+
+  def test_should_create_ip_range
+    assert_difference('IpRange.count') do
+      post :create, :ip_range => {:name => "xxx", :from_ip => "192.168.1.1" }
+    end
+
+    assert_redirected_to ip_range_path(assigns(:ip_range))
+  end
+
+  def test_should_show_ip_range
+    get :show, :id => IpRange.find(:first)
+    assert_response :success
+  end
+
+  def test_should_get_edit
+    get :edit, :id => IpRange.find(:first)
+    assert_response :success
+  end
+
+  def test_should_update_ip_range
+    put :update, :id => IpRange.find(:first), :ip_range => { }
+    assert_redirected_to ip_range_path(assigns(:ip_range))
+  end
+
+  def test_should_destroy_ip_range
+    assert_difference('IpRange.count', -1) do
+      delete :destroy, :id => IpRange.find(:first)
+    end
+
+    assert_redirected_to ip_ranges_path
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/prisma_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/prisma_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/prisma_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/prisma_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,54 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'prisma_controller'
+
+# Re-raise errors caught by the controller.
+class PrismaController; def rescue_action(e) raise e end; end
+
+class PrismaControllerTest < ActionController::TestCase
+  
+  def setup
+    @controller = PrismaController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+
+    @first_id = Alarm.find(:first).id
+  end
+
+  def test_overview
+    get :overview
+    assert_response :success
+    assert_tidy_html
+  end
+
+  def test_overview_1tier
+    get :overview, :installation_schema => "1tier"
+    assert_response :success
+    assert_tidy_html
+  end
+  def test_overview_3tier
+    get :overview, :installation_schema => "3tier"
+    assert_response :success
+    assert_tidy_html
+  end
+
+  def test_measure_inline   
+    for stat in PrismaController::STAT_NAMES
+      get :measure_inline, :type => stat
+    end    
+  end
+  
+end

Added: incubator/alois/trunk/rails/test/functional/report_templates_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/report_templates_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/report_templates_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/report_templates_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,140 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'report_templates_controller'
+
+# Re-raise errors caught by the controller.
+class ReportTemplatesController; def rescue_action(e) raise e end; end
+
+class ReportTemplatesControllerTest < ActionController::TestCase
+  fixtures :report_templates, :reports, :views, :filters
+  
+  def setup
+    @controller = ReportTemplatesController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+
+    @first_id = ReportTemplate.find(:first).id
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:report_templates)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:report_template)
+    #    assert assigns(:report_template).valid?, "Report template is not valid: #{assigns(:report_template).errors.full_messages} (#{assigns(:report_template).inspect})"
+  end
+
+  def disabled_test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:report_template)
+  end
+
+  def test_create
+    num_report_templates = ReportTemplate.count
+
+    post :create, :report_template => {}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_report_templates + 1, ReportTemplate.count
+  end
+
+  def test_edit
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:report_template)
+    assert assigns(:report_template).valid?
+  end
+
+  def test_update
+    post :update, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'show', :id => @first_id
+  end
+
+  def test_destroy
+    assert_nothing_raised {
+      ReportTemplate.find(@first_id)
+    }
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      ReportTemplate.find(@first_id)
+    }
+  end
+
+
+  def test_render_save
+    c = Report.count
+    get :show, :id => @first_id, :render => true, :time_span => "today", :table_name => "view_1", :commit => "Save as Report"
+
+    assert_response :redirect
+    assert_redirected_to :action => "show", :controller => "reports"
+
+    assert_not_nil assigns(:report)
+    assert assigns(:report).valid?
+    assert_equal c + 1, Report.count
+  end
+
+
+  def test_render_preview_fake
+    get :show, :id => @first_id, :render => true, :time_span => "today", :table_name => "view_1", :commit => "Preview with fake data"
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:report_template)
+    assert assigns(:report_template).valid?
+  end
+  def test_render_preview_real
+    get :show, :id => @first_id, :render => true, :time_span => "today", :table_name => "view_1", :commit => "Preview with real data"
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:report_template)
+    assert assigns(:report_template).valid?
+  end
+
+end

Added: incubator/alois/trunk/rails/test/functional/report_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/report_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/report_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/report_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,268 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ReportTest < ActiveSupport::TestCase
+  # because some create view statements will appear
+  self.use_transactional_fixtures = false
+
+  fixtures :reports,:report_templates, :charts_report_templates,
+    :alarms, :sentinels
+
+  def setup
+    ActionMailer::Base.deliveries = []
+  end
+
+  def test_no_template_given
+    sentinel = Sentinel.find(1)
+    assert sentinel
+    sentinel.report_template = nil    
+    assert sentinel.view.table.count > 0
+    sentinel.action = :alarm_and_report
+    sentinel.save
+
+    assert sentinel.is_alarm?
+    
+    rt_count = ReportTemplate.count
+    alarm_count = Alarm.count
+    report_count = Report.count
+
+    BaseMailer.expecting_mail
+    sentinel.process
+    assert sentinel.process_errors
+    assert_equal 1, sentinel.process_errors.length, sentinel.process_errors.inspect
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+    assert BaseMailer.latest_mail.to_s =~ /No report_template given./
+  end
+  
+  def test_report
+    my_test_report
+  end
+
+  def test_report_do_not_use_mysql_view
+    view = Sentinel.find(3).view
+    view.do_not_use_view_for_query = true
+    view.save
+    my_test_report
+  end
+
+  def my_test_report
+    alarm_count = Alarm.count
+    report_count = Report.count
+
+    SyslogdRaw.delete_all
+    LogMeta.delete_all
+    SyslogdMeta.delete_all
+
+    sentinel = Sentinel.find(3)
+
+    # run disabled sentinel
+    assert_equal :disabled, sentinel.action_name
+    err = assert_raise RuntimeError do
+      sentinel.process
+    end
+    assert_equal "This sentinel is disabled.",err.message
+
+    # run sentinel for yesterday to
+    # check that no report will be generated
+    sentinel.action = :alarm_and_report
+    assert_equal :alarm_and_report, sentinel.action_name
+    
+    alarm,report = sentinel.process
+    assert_nil sentinel.process_errors, sentinel.process_errors
+    assert alarm.nil?
+    assert report.nil?
+    assert_equal alarm_count, Alarm.count
+    assert_equal report_count, Report.count
+
+    # add new logs to syslogd_raws from
+    #  2 days ago
+    #  yesterday
+    #  today
+    days_count = {"2 days ago" => 11, 
+      "yesterday" => 5, 
+      "today" => 12}
+
+    days_count.each {|date, count|
+      
+      beginning,ending = rand(2),rand(2)
+      begin_date,end_date = "beginning #{date}".to_time,"ending #{date}".to_time
+      range = (begin_date..end_date).to_a
+
+      beginning.times{ SyslogdRaw.create_random_test_message(begin_date) }
+      ending.times{ SyslogdRaw.create_random_test_message(end_date) }
+      (count-beginning-ending).times { SyslogdRaw.create_random_test_message(range.rand) }
+    }
+
+    total_logs = days_count.sum(&:last)
+    assert_equal total_logs, SyslogdRaw.count
+        
+    # run prisma
+    Prisma::Transform.transform_all_raws(SyslogdRaw)
+    assert_equal total_logs, LogMeta.count
+    
+    # to reset cached count
+    sentinel = Sentinel.find(3)
+    # run sentinel for yesterday to
+    # check that no report will be generated
+    sentinel.action = :alarm_and_report
+    assert_equal :alarm_and_report, sentinel.action_name
+
+    # also check email delivery
+    sentinel.send_mail = true
+    sentinel.mail_to = "flavio.pellanda@logintas.ch"
+
+    # run sentinel for yesterday
+    assert_equal :error,sentinel.alarm_level_name
+    assert_equal :alarm_and_report, sentinel.action_name
+    assert sentinel.date_condition
+    assert_equal days_count["yesterday"],sentinel.count
+    assert_equal 0, sentinel.threshold
+    assert sentinel.is_alarm?, "Sentinel says its not an alarm."
+    assert sentinel.report_template
+
+    BaseMailer.expecting_mail(2)
+    alarm,report = sentinel.process
+    assert_nil sentinel.process_errors, sentinel.process_errors
+    assert alarm
+    # TODO: by a bug the text field only works
+    # if the alarm is reloaded
+    alarm = Alarm.find(alarm.id)
+    assert alarm.text =~ /original_text/
+    assert report
+    assert_equal sentinel.alarm_level, alarm.alarm_level
+
+    # check that a new report is generated
+    assert_equal report_count + 1, Report.count
+
+    # check that a new alarm was generated
+    assert_equal alarm_count + 1, Alarm.count
+    
+    # check that email was delivered
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+    assert_equal "#{$installation_name} - Report Testing log metas statistics for Alois-Basis log_metas with syslogd_metas and messages", BaseMailer.deliveries[-1].subject,
+      "Not the right mail was delivered: #{BaseMailer.deliveries[-1].subject}"
+    assert_equal "#{$installation_name} - Alarm For testing yesterday (error)", BaseMailer.deliveries[-2].subject,
+      "Not the right mail was delivered: #{BaseMailer.deliveries[-2].subject}"
+    assert BaseMailer.deliveries[-2].to_s =~ /Alarm ocurred/
+
+    # disable report
+    sentinel.action = :alarm
+
+    # run sentinel for yesterday again
+    BaseMailer.expecting_mail
+    alarm,report = sentinel.process
+    assert_nil sentinel.process_errors, sentinel.process_errors
+    assert alarm
+    assert report.nil?
+    assert_equal sentinel.alarm_level, alarm.alarm_level
+
+    # check that a new alarm was generated
+    assert_equal alarm_count + 2, Alarm.count
+
+    # check that a no new report is generated
+    assert_equal report_count + 1, Report.count
+
+    # check that email was delivered
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+    assert_equal "#{$installation_name} - Alarm For testing yesterday (error)", BaseMailer.latest_mail.subject,
+      "Not the right mail was delivered: #{BaseMailer.latest_mail.to_s}"
+    assert BaseMailer.latest_mail.to_s =~ /Alarm ocurred/
+
+    # disable alarm
+    sentinel.action = :report
+
+    # run sentinel for yesterday again
+    BaseMailer.expecting_mail
+    alarm,report = sentinel.process
+    assert_nil sentinel.process_errors, sentinel.process_errors
+    assert alarm.nil?
+    assert report
+
+    # check that a new alarm was generated
+    assert_equal alarm_count + 2, Alarm.count
+
+    # check that a no new report is generated
+    assert_equal report_count + 2, Report.count
+
+    # check that email was delivered
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+    assert_equal "#{$installation_name} - Report Testing log metas statistics for Alois-Basis log_metas with syslogd_metas and messages", BaseMailer.latest_mail.subject,
+      "Not the right mail was delivered: #{BaseMailer.latest_mail.to_s}"
+
+    # check that csv is attached
+    assert !( BaseMailer.latest_mail.to_s =~ /Alarm ocurred/)
+    assert_report
+    assert_csv
+
+    BaseMailer.expecting_mail
+    sentinel.include_csv_in_email = false
+    sentinel.include_report_in_email = false
+    alarm,report = sentinel.process
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+
+    # check that csv is not attached
+    assert_no_csv
+    assert_no_report
+
+    BaseMailer.expecting_mail
+    sentinel.include_csv_in_email = true
+    sentinel.include_report_in_email = false
+    alarm,report = sentinel.process
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+
+    assert_csv
+    assert_no_report
+
+    BaseMailer.expecting_mail
+    sentinel.include_csv_in_email = false
+    sentinel.include_report_in_email = true
+    alarm,report = sentinel.process
+    assert_equal 0, BaseMailer.not_delivered_mails_count
+
+    assert_no_csv
+    assert_report
+  end
+
+  def assert_attachment(regex = nil)
+    assert BaseMailer.latest_mail.attachments.length > 0, "No attachment"
+  end
+
+  def assert_csv
+    assert_equal 1,BaseMailer.latest_mail.attachments.select {|a| a.original_filename == "csv_datas.zip"}.length {
+      (save_email(BaseMailer.latest_mail, "error_mail");"Csv not found. (#{BaseMailer.latest_mail.attachments.map {|a| a.original_filename}.inspect})")}
+  end
+  
+  def assert_no_csv
+    assert_equal 0,BaseMailer.latest_mail.attachments.select {|a| a.original_filename == "csv_datas.zip"}.length {
+      (save_email(BaseMailer.latest_mail, "error_mail");"Csv found. (#{BaseMailer.latest_mail.attachments.map {|a| a.original_filename}.inspect})")}
+  end
+  
+  def assert_report
+    assert 0 < BaseMailer.latest_mail.attachments.select {|a| a.original_filename =~ /chart_/}.length {
+      (save_email(BaseMailer.latest_mail, "error_mail");"No Charts attached. (#{BaseMailer.latest_mail.attachments.map {|a| a.original_filename}.inspect})")}
+  end
+
+  def assert_no_report
+    assert_equal 0, BaseMailer.latest_mail.attachments.select {|a| a.original_filename =~ /chart_/}.length {
+      (save_email(BaseMailer.latest_mail, "error_mail");"Charts attached. (#{BaseMailer.latest_mail.attachments.map {|a| a.original_filename}.inspect})")}
+  end
+end
+
+    
+
+    
+    
+

Added: incubator/alois/trunk/rails/test/functional/reports_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/reports_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/reports_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/reports_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,131 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'reports_controller'
+
+# Re-raise errors caught by the controller.
+class ReportsController; def rescue_action(e) raise e end; end
+
+class ReportsControllerTest < ActionController::TestCase
+  fixtures :reports, :report_templates, :views, :filters
+
+  def setup
+    @controller = ReportsController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+    @first_id = Report.find(:first).id
+
+    unless @report
+      @report_template = ReportTemplate.find(1)
+      @report_template.delete_cache
+      @options = {
+	:url => "someurl?",
+	:datasource => View.find(1) }
+      @report = Report.generate(@report_template,"test", @options)
+    end
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:reports)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:report)
+    assert assigns(:report).valid?
+  end
+
+
+  def disabled_test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:report)
+  end
+
+  def disabled_test_create
+    num_reports = Report.count
+
+    post :create, :report => {}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_reports + 1, Report.count
+  end
+
+  def disabled_test_edit
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:report)
+    assert assigns(:report).valid?
+  end
+
+  def disabled_test_update
+    post :update, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'show', :id => @first_id
+  end
+
+  def test_destroy
+    assert_nothing_raised {
+      Report.find(@first_id)
+    }
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      Report.find(@first_id)
+    }
+  end
+
+  def test_send_to_email
+    get :send_to_email, :id => @report
+    assert_response :success
+    assert_template 'send_to_email'    
+  end
+
+  def test_email_preview_simple
+    get :email_preview, :id => @report, :type => "simple"
+    assert_response :success
+  end
+
+  def test_email_preview_normal
+    get :email_preview, :id => @report, :type => "simple"
+    assert_response :success
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/sentinels_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/sentinels_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/sentinels_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/sentinels_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,124 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'sentinels_controller'
+
+# Re-raise errors caught by the controller.
+class SentinelsController; def rescue_action(e) raise e end; end
+
+class SentinelsControllerTest < ActionController::TestCase
+  fixtures :views,:sentinels
+
+  def setup
+    @controller = SentinelsController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+
+    @first_id = Sentinel.find(:first).id
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:sentinels)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:sentinel)
+    assert assigns(:sentinel).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:sentinel)
+  end
+
+  def test_create
+    num_sentinels = Sentinel.count
+
+    post :create, :sentinel => {
+      :name => "New Sentinel",
+      :view_id => View.find(:first).id,
+      :threshold => 0,
+      :cron_interval => "0 0 0 0 0"
+    }
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_sentinels + 1, Sentinel.count
+  end
+
+  def test_edit
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:sentinel)
+    assert assigns(:sentinel).valid?
+  end
+
+  def test_update
+    post :update, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'show', :id => @first_id
+  end
+
+  def test_destroy
+    assert_not_nil Sentinel.find(@first_id)
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      Sentinel.find(@first_id)
+    }
+  end
+
+  def test_load_yaml
+    post :new, :current_object_zip =>
+      "RY5BbsMwDATvfoWau9H06nN/kAcItL1wWEiiQTFO/PvQao2CF3KHu2Tf9+FD\n" +
+      "H+P+KeMPJhtuKMYFKXRkpjw+DHUIXQiFMoZwk4xQ/3ZcNc6ISmVxtqMadKbd\n" +
+      "dV+ZYyZOQ7hcLy4cfTRpUXZX1Luk+YSTSolc3L2RO65nOaJEmmPChtS8NBlL\n" +
+      "aS0f/q/DP6NOyusv+fbh/EBq5XxewcsPFEpxVVmUcgvZGM/4n6RYRS0a8prI\n" +
+      "0Ej3Bn4xW/o="
+    
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:sentinel)
+    assert "Some sentinel", assigns(:sentinel).name
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/survey_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/survey_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/survey_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/survey_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,237 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'survey_controller'
+
+# Re-raise errors caught by the controller.
+class SurveyController; def rescue_action(e) raise e end; end
+
+class SurveyControllerTest < ActionController::TestCase
+  fixtures :views, :application_logs
+
+  def setup
+    @controller = SurveyController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+    # without any record ruport would fail with: Ruport::FormatterError: Can't output table without data or column names.
+    ApplicationLog.create(:date => DateTime.now.strftime("%F"))
+  end
+
+
+  def test_index
+    get :index, :table => "application_logs"
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'    
+  end
+
+  def test_list_redirect
+    get :list, :table => "application_logs"
+    
+    assert_response :redirect
+    assert_redirected_to :action => 'list'    
+  end
+
+  def test_list
+    get :list, :table => "application_logs", :state_id => "test_state"
+    
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:records)
+  end
+
+  def test_show_syslog
+    get :show, :id => 1, :table => "application_logs"
+
+    assert_response :success
+    assert_template 'show'
+  end
+
+  def test_show_message
+    get :show, :id => 1, :table => "application_logs"
+
+    assert_response :success
+    assert_template 'show'
+  end
+
+  def test_new
+    assert_raises(ActionController::UnknownAction){
+      get :new, :table => "application_logs"
+    }
+  end
+
+  def test_create
+    assert_raises(ActionController::UnknownAction){
+      post :create, :table => "application_logs"
+    }
+  end
+
+  def test_edit
+    assert_raises(ActionController::UnknownAction){
+      get :edit, :id => 1, :table => "application_logs"
+    }
+  end
+
+  def test_update
+    assert_raises(ActionController::UnknownAction){
+      post :update, :id => 1, :table => "application_logs"
+    }
+  end
+
+  def test_destroy
+    assert_raises(ActionController::UnknownAction){
+      post :destroy, :id => 1, :table => "application_logs"
+    }
+  end
+
+  def test_txt
+    get :text, :id => 1, :table => "application_logs"
+    assert_response :success
+  end
+
+  def test_csv
+    get :csv, :id => 1, :table => "application_logs"
+    assert_response :success
+  end
+
+  def test_pdf
+    get :pdf, :id => 1, :table => "application_logs"
+    assert_response :success
+  end
+
+  def test_count
+    get :count_text, :table => "view_11"
+    assert_response :success
+    
+    assert @response.body =~ /This can take a very long time./
+  end
+
+  def test_count_slow
+    get :count_text, :table => "view_11", :slow_count => true, :no_default_filter => true
+    assert_response :success
+    
+    assert @response.body =~ /You have selected 10 records/, "'#{@response.body}'\n does not contain 'You have selected 80 records'. "
+  end
+
+  def test_default_condition
+    get :list, :table => "application_logs", :default_filter => "1=1"
+    assert_response :redirect
+    assert_redirected_to(:controller => "survey", :action => "list", :state_id => ApplicationHelper::TEST_STATE_ID)
+
+    assert_equal 2,@response.redirected_to.length
+    assert @response.redirected_to[:state_id]
+    get :list, @response.redirected_to
+    assert_response :success
+
+    assert_not_nil assigns(:records)
+    df = assigns(:current_filter)
+    assert_not_nil df
+    assert 1,df.conditions.length
+    cond = df.conditions[0]
+    
+    assert cond.is_a?(SqlCondition)
+    assert_equal "SQL",cond.operator
+    assert_equal "1=1",cond.value
+    assert_equal "( 1=1 )",cond.sql    
+  end
+
+
+  def test_add_condition
+    get :add_condition, :table => "application_logs", :state_id => "test_state",
+      :no_default_filter => "true", :column => "id", :operator => "=", :value => "1"
+
+    assert_response :redirect
+    assert_equal 1, assigns("current_filter").conditions.length
+    assert_equal Condition.new("id","=","1").sql, assigns("current_filter").conditions[0].sql
+  end
+
+  def test_add_condition2
+    get :add_condition, :table => "application_logs", :state_id => "test_state",
+      :no_default_filter => "true",
+      :column => "id", :operator => "=", :value => "1",
+      :column2 => "id", :operator2 => "LIKE", :value2 => "2"
+
+    assert_response :redirect
+    assert_equal 2, assigns("current_filter").conditions.length
+    assert_equal Condition.new("id","=","1").sql, assigns("current_filter").conditions[0].sql
+    assert_equal Condition.new("id","LIKE","2").sql, assigns("current_filter").conditions[1].sql
+  end
+
+  def test_add_conditions
+    get :add_condition, :table => "application_logs", :state_id => "test_state",
+      :no_default_filter => "true",
+      :columns => ["id","date","date"], :operators => ["=","LIKE","DATE"], :values => ["1","2008-01-01","today"]
+
+    assert_response :redirect
+    assert_equal 3, assigns("current_filter").conditions.length
+    assert_equal Condition.new("id","=","1").sql, assigns("current_filter").conditions[0].sql
+    assert_equal Condition.new("date","LIKE","2008-01-01").sql, assigns("current_filter").conditions[1].sql
+    assert_equal Condition.new("date","=",DateTime.now.strftime("%F")).sql, assigns("current_filter").conditions[2].sql.strip
+  end
+
+  def test_chart_click_compatibility
+    ## Leave this tests for backwarts compatibility!
+    @stateid = "teststate"    
+    get :chart_click,
+      :column1 => "request_status", :column2 => "", 
+      :series => "Serie 1", :category => "TCP_MISS"
+
+    assert_redirected_to :action => "add_condition", :state_id => assigns("state_id"),
+      :columns => ["request_status"],
+      :operators => ["="],
+      :values => ["TCP_MISS"]
+    
+    get :chart_click,
+      :column1 => "request_status", :column2 => "", 
+      :series => "Serie 1", :category => "TCP_REFRESH_HIT"
+
+    assert_redirected_to :action => "add_condition", :state_id => assigns("state_id"),
+      :columns => ["request_status"],
+      :operators => ["="], 
+      :values => ["TCP_REFRESH_HIT"]
+
+    # xy
+    get :chart_click,
+      :column1 => "request_status", :column2 => "hour",
+      :series => "hour=2", :category => "TCP_HIT"
+
+    assert_redirected_to :action => "add_condition", :state_id => assigns("state_id"),
+      :columns => ["request_status","hour"],
+      :operators => ["=","="], 
+      :values => ["TCP_HIT", "2"]
+    
+    get :chart_click,
+      :column1 => "request_status", :column2 => "hour", 
+      :series => "hour=6", :category => "TCP_REFRESH_HIT"
+
+    assert_redirected_to :action => "add_condition", :state_id => assigns("state_id"),
+      :columns => ["request_status","hour"],
+      :operators => ["=","="],
+      :values => ["TCP_REFRESH_HIT","6"]
+
+    # xyz
+    get :chart_click,
+      :category_column => "hour", :serie_column => "level",:range_column => "facility",
+      :category => "10", :series => "level=warning", :range => "facility=user"
+    
+    assert_redirected_to :action => "add_condition", :state_id => assigns("state_id"),
+      :columns => ["hour","level","facility"], 
+      :operators => ["=","=","="], 
+      :values => ["10","warning", "user"]
+
+  end
+
+end

Added: incubator/alois/trunk/rails/test/functional/tablelist_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/tablelist_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/tablelist_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/tablelist_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,43 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'tablelist_controller'
+
+# Re-raise errors caught by the controller.
+class TablelistController; def rescue_action(e) raise e end; end
+
+class TablelistControllerTest < ActionController::TestCase
+  def setup
+    @controller = TablelistController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'index'
+  end
+
+  def test_count
+    for klass in Prisma::Database.get_classes
+      get :count, :table_name => klass.table_name
+
+      assert_response :success
+      assert_template 'count'
+    end
+  end
+
+end

Added: incubator/alois/trunk/rails/test/functional/tables_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/tables_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/tables_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/tables_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,60 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TablesControllerTest < ActionController::TestCase
+
+  def test_should_get_index
+    get :index
+    assert_response :success
+    assert assigns(:tables)
+  end
+
+  def test_should_get_new
+    get :new
+    assert_response :success
+  end
+
+  def test_should_create_table
+    assert_difference('Table.count') do
+      post :create, :table => {}
+    end
+
+    assert_redirected_to :action => "list"
+  end
+
+  def test_should_show_table
+    get :show, :id => Table.find(:first).id
+    assert_response :success
+  end
+
+  def test_should_get_edit
+    get :edit, :id => Table.find(:first).id
+    assert_response :success
+  end
+
+  def test_should_update_table
+    put :update, :id => Table.find(:first).id, :table => { }
+    assert_redirected_to 
+  end
+
+  def test_should_destroy_table
+    assert_difference('Table.count', -1) do
+      delete :destroy, :id => Table.find(:first).id
+    end
+
+    assert_redirected_to :action => "list"
+  end
+end

Added: incubator/alois/trunk/rails/test/functional/views_controller_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/functional/views_controller_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/functional/views_controller_test.rb (added)
+++ incubator/alois/trunk/rails/test/functional/views_controller_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,107 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'views_controller'
+
+# Re-raise errors caught by the controller.
+class ViewsController; def rescue_action(e) raise e end; end
+
+class ViewsControllerTest < ActionController::TestCase
+  # because some create view statements will appear
+  self.use_transactional_fixtures = false
+
+  fixtures :views, :sentinels
+
+  def setup
+    @controller = ViewsController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+    
+    @first_id = View.find(:first)
+  end
+
+  def test_index
+    get :index
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:views)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:view)
+    assert assigns(:view).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:view)
+  end
+
+  def test_create
+    num_views = View.count
+
+    post :create, :view => {:name=>"New View",:sql_declaration => "SELECT CURRENT_DATE as date"}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_views + 1, View.count
+  end
+
+  def test_edit
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:view)
+    assert assigns(:view).valid?
+  end
+
+  def test_update
+    post :update, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+  end
+
+  def test_destroy
+    assert_not_nil View.find(@first_id)
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      View.find(@first_id)
+    }
+  end
+end

Added: incubator/alois/trunk/rails/test/integration/script_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/integration/script_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/integration/script_test.rb (added)
+++ incubator/alois/trunk/rails/test/integration/script_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,69 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ScriptTest < ActiveSupport::TestCase
+  
+  ARCH_DIR = "#{RAILS_ROOT}/tmp/archive/test/prisma/"
+
+  def ttest_compress_archive_syslog
+    FileUtils.remove_dir(ARCH_DIR) if File.exist?(ARCH_DIR)
+
+    archivator = Archivator.new($archive_pattern, SyslogdRaw)
+    archivator.archivate(SyslogdRaw.new(:date => "2007-02-02", :time => "20:00:00"))
+    
+    assert File.exist?("#{ARCH_DIR}syslogd_raws/#{Time.now.strftime("%F")}/2007-02-02.arch")
+    FileUtils.move("#{ARCH_DIR}syslogd_raws/#{Time.now.strftime("%F")}","#{ARCH_DIR}syslogd_raws/2007-01-01")
+    assert File.exist?("#{ARCH_DIR}syslogd_raws/2007-01-01/2007-02-02.arch")    
+
+    archivator = Archivator.new($archive_pattern, SyslogdRaw)
+    archivator.archivate(SyslogdRaw.new(:date => "2007-02-02", :time => "20:00:00"))
+
+    assert File.exist?("#{ARCH_DIR}syslogd_raws/#{Time.now.strftime("%F")}/2007-02-02.arch")
+
+    ENV['RAILS_ENV'] = "test"
+    system("script/compress_archives")
+
+    assert File.exist?("#{ARCH_DIR}syslogd_raws/#{Time.now.strftime("%F")}/2007-02-02.arch")
+    assert !File.exist?("#{ARCH_DIR}syslogd_raws/2007-01-01/2007-02-02.arch")
+    assert File.exist?("#{ARCH_DIR}syslogd_raws/2007-01-01/2007-02-02.arch.gz")
+  end
+
+  def test_compress_archive_file
+    FileUtils.remove_dir(ARCH_DIR) if File.exist?(ARCH_DIR)
+
+    archivator = Archivator.new($archive_pattern, FileRaw)
+    archivator.archivate(FileRaw.new())
+    
+    assert File.exist?("#{ARCH_DIR}file_raws/#{Time.now.strftime("%F")}/#{Time.now.strftime("%F")}.arch")
+    FileUtils.move("#{ARCH_DIR}file_raws/#{Time.now.strftime("%F")}","#{ARCH_DIR}file_raws/2007-01-01")
+    FileUtils.move("#{ARCH_DIR}file_raws/2007-01-01/#{Time.now.strftime("%F")}.arch","#{ARCH_DIR}file_raws/2007-01-01/2007-02-03.arch")    
+    assert File.exist?("#{ARCH_DIR}file_raws/2007-01-01/2007-02-03.arch")
+
+    archivator = Archivator.new($archive_pattern, FileRaw)
+    archivator.archivate(FileRaw.new())
+    FileUtils.move("#{ARCH_DIR}file_raws/#{Time.now.strftime("%F")}/#{Time.now.strftime("%F")}.arch","#{ARCH_DIR}file_raws/#{Time.now.strftime("%F")}/2007-02-03.arch")
+
+    assert File.exist?("#{ARCH_DIR}file_raws/#{Time.now.strftime("%F")}/2007-02-03.arch")
+
+    ENV['RAILS_ENV'] = "test"
+    system("script/compress_archives")
+
+    assert File.exist?("#{ARCH_DIR}file_raws/#{Time.now.strftime("%F")}/2007-02-03.arch")
+    assert !File.exist?("#{ARCH_DIR}file_raws/2007-01-01/2007-02-03.arch")
+    assert File.exist?("#{ARCH_DIR}file_raws/2007-01-01/2007-02-03.arch.gz")
+  end
+
+end

Added: incubator/alois/trunk/rails/test/performance/prisma_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/performance/prisma_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/performance/prisma_test.rb (added)
+++ incubator/alois/trunk/rails/test/performance/prisma_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,64 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'performance_test_help'
+
+# Profiling results for each test method are written to tmp/performance.
+# kcachegrind can be used to analyze tree
+class PrismaTest < ActionController::PerformanceTest
+  def setup
+    SyslogdRaw.delete_all
+    kern = true
+    if kern
+      date_time = DateTime.now
+      date = date_time.strftime("%F")
+      time = date_time.strftime("%T")
+      500.times {
+        SyslogdRaw.create(:ip => "127.0.0.111",
+                          :host => "testhost",
+                          :facility => "kern",
+                          :priority => "info",
+                          :level => "info",
+                          :tag => "",
+                          :date => date,
+                          :time => time,
+                          :program => "Alois Random",
+                          :msg => "kernel: [13049117.712831] Swl:FORWARD:1:REJECT:IN=vpnbr100 OUT=eth1 PHYSIN=eth2 SRC=192.168.100.111 DST=130.117.190.134 LEN=52 TOS=0x00 PREC=0x00 TTL=127 ID=14019 DF PROTO=TCP SPT=63965 DPT=80 WINDOW=8192 RES=0x00 SYN URGP=0")
+      }
+    else
+      Prisma.generate_random_raws(500)      
+    end
+
+  end
+
+  def test_performance
+
+    assert 500, SyslogdRaw.count
+
+#    time = Benchmark.measure {
+      Prisma.transform_all_raws(SyslogdRaw)
+#    }.real
+#    assert_equal 0, SyslogdRaw.count
+    # Genuine Intel(R) CPU           T2400  @ 1.83GHz it took about 6 seconds
+#    assert time < 15, "Should not take more than 15 seconds. It was #{time}."
+#    print "Time OK: #{time}\n"
+
+    # 2010-09-16, in vbox guest
+    # PrismaTest#test_performance (27.30 sec warmup)
+    #        process_time: 43.15 sec
+
+    assert 0, SyslogdRaw.count
+  end
+end

Added: incubator/alois/trunk/rails/test/test_helper.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/test_helper.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/test_helper.rb (added)
+++ incubator/alois/trunk/rails/test/test_helper.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,239 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+require 'test_help'
+
+class ActiveSupport::TestCase
+  # Transactional fixtures accelerate your tests by wrapping each test method
+  # in a transaction that's rolled back on completion.  This ensures that the
+  # test database remains unchanged so your fixtures don't have to be reloaded
+  # between every test method.  Fewer database queries means faster tests.
+  #
+  # Read Mike Clark's excellent walkthrough at
+  #   http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
+  #
+  # Every Active Record database supports transactions except MyISAM tables
+  # in MySQL.  Turn off transactional fixtures in this case; however, if you
+  # don't care one way or the other, switching from MyISAM to InnoDB tables
+  # is recommended.
+  #
+  # The only drawback to using transactional fixtures is when you actually 
+  # need to test transactions.  Since your test is bracketed by a transaction,
+  # any transactions started in your code will be automatically rolled back.
+  self.use_transactional_fixtures = true #false
+
+  # Instantiated fixtures are slow, but give you @david where otherwise you
+  # would need people(:david).  If you don't want to migrate your existing
+  # test cases which use the @david style and don't mind the speed hit (each
+  # instantiated fixtures translates to a database query per test method),
+  # then set this back to true.
+  self.use_instantiated_fixtures  = false
+
+  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+  #
+  # Note: You'll currently still have to declare fixtures explicitly in integration tests
+  # -- they do not yet inherit this setting
+  fixtures :all
+
+  # Add more helper methods to be used by all tests here...
+
+  # compare yaml, sort first to ensure matching if
+  # some attribtues changed, this is not a 100%
+  # test but should be enough for testing
+  def assert_equal_yaml(yaml1, yaml2, text = nil)
+    assert_equal yaml1.split("\n").sort, yaml2.split("\n").sort, text
+  end
+
+  def self.import_file(file)
+    print "File #{file}.\n"
+    Prisma.transform_file(file,"type=#{File.extname(file)[1..-1]}")
+
+    source = Prisma::SourceDbMeta.new(:all, Prisma::FileRaw)
+    source.transform
+  end
+
+  def file_info(filename)
+    basename = Pathname.new(filename).basename.to_s
+    unless basename =~ /([^\.]*)\.(.*)/
+      g = Dir.glob(filename + ".*").reject {|f| f =~ /\~$/ or f=~/\..*\./}
+      throw "More than one file found. (#{g.inspect})" if g.length > 1
+      throw "File not found '#{filename + ".*"}'" if g.length == 0
+      filename = g[0]
+    end
+    basename = Pathname.new(filename).basename.to_s
+    throw "Malformed filename '#{filename}'" unless basename =~ /([^\.]*)\.(.*)/
+    table_name, type = $1,$2
+    table_class = Prisma.get_class_from_tablename(table_name)
+    throw "Table '#{table_name}' not found." unless table_class
+    
+    ret = {:type => type, :table_class => table_class, :filename => filename}
+  end
+
+  def load_file(filename)
+    fi = file_info(filename)
+    table_class = fi[:table_class]
+
+    case fi[:type]
+    when "messages"
+      Message.delete_all
+      msgs = []
+      for line in open(fi[:filename])
+	# correct windows linefeeds
+	line = line[0..-3] + "\n" if line.ends_with?("\r\n")
+
+	parent = table_class.new()
+	message = Message.new(parent,line)
+	message.save
+	msgs.push message
+      end
+      return msgs
+    when "archive"
+      a = ArchiveMeta.new(fi[:filename])
+      a.save            
+      return a
+    else
+      throw "unknown type '#{type}'."
+    end
+  end
+
+  def load_and_transform_file(filename, expected_message_count = 0)
+    fi = file_info(filename)
+    Message.delete_all
+    fi[:table_class].delete_all
+
+    ret = load_file(filename)
+    Prisma.transform_messages
+    if Message.count > 0
+      Message.find(:all).each {|m|
+	p m.msg
+      }
+      print "Found still #{Message.count} messages.\n"
+    end
+    assert_equal expected_message_count, Message.count
+  end
+
+  # from http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabasesWithFixtures
+  
+  cattr_accessor :classes_cache
+  #class cache for storing already founded classes from models
+  @@classes_cache = {}
+
+  def table_names_and_classes(table_names)
+    table_names = table_names.flatten.collect{|t| t.to_s}
+    tables = table_names.map {|table_name|
+      unless @@classes_cache[table_name].nil?
+        klass = @@classes_cache[table_name]
+      else
+        begin 
+          #try to find class name from table name
+          klass = eval(table_name.classify)
+        rescue
+          #go to model directory, run through all models and search for table name
+          classes = Dir.entries(RAILS_ROOT + "/app/models").select{|d| d.include?(".rb")}.collect{|f| File.basename(f, ".rb").classify}
+          klass_names = classes.select{|f| (eval("#{f}.table_name") rescue false)==table_name }
+          klass_name = klass_names.blank? ? table_name.classify : klass_names.first
+          klass = eval(klass_name)
+        end
+        @@classes_cache[table_name] = klass
+      end
+      [table_name, klass]
+    }
+  end
+
+
+  def load_user_fixtures(*table_names)
+    tables = table_names_and_classes(table_names)
+
+    # clear tables
+    tables.each {|table_name,klass|
+      klass.delete_all
+    }
+
+    tables.each {|table_name, klass|
+      fs = Dir.glob(File.dirname(__FILE__) + "/fixtures_*").map {|f_path|
+	fix = Fixtures.new(klass.connection, 
+			   klass.table_name,
+			   klass.name,
+			   f_path + "/" + klass.table_name) #, file_filter = DEFAULT_FILTER_RE)
+	fix.insert_fixtures
+      }
+    }
+
+    # check if fixtures are loaded
+    tables.each {|table_name,klass|
+      raise "Fixtures of class #{klass.name} not loaded"if klass.count == 0
+    }
+  end
+    
+
+  #  CHART_YAML =  "--- !ruby/object:Chart \nattributes: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\n"
+  #  CHART_YAML =  "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: \"0\"\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  aggregation_function: COUNT\n  width: \"300\"\n  column2: time\n"
+  CHART_YAML =  "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  flipped: f\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: f\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\n"
+  
+  CHART_QUERY = "SELECT date, time, COUNT(date) AS data FROM application_logs WHERE `date` = '2008-04-09'  GROUP BY time, date ORDER BY date, time"
+  
+  CHART_RENDER_OPTIONS = {:conditions => "1=1", :datasource => ApplicationLog}
+  
+  #  CHART_AFTER_RENDER_YAML = "--- !ruby/object:Chart \nattributes: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\nexternal_link: http://localhost:3001/alois/table/application_logs/chart_click?default_filter=%60date%60+%3D+%272008-04-09%27++AND+1%3D1&\noption_conditions: 1=1\ntable_name: application_logs\n"
+  #  CHART_AFTER_RENDER_YAML = "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: \"0\"\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  aggregation_function: COUNT\n  width: \"300\"\n  column2: time\nexternal_link: https://localhost:3001/alois/table/application_logs/chart_click?default_filter=%60date%60+%3D+%272008-04-09%27++AND+1%3D1&\noption_conditions: 1=1\ntable_name: application_logs\n"  
+  CHART_AFTER_RENDER_YAML = "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  flipped: f\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: f\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\nexternal_link: https://localhost:3001/alois/table/application_logs/chart_click?default_filter=%60date%60+%3D+%272008-04-09%27++AND+1%3D1&\noption_conditions: 1=1\ntable_name: application_logs\n"
+
+
+  def self.test_chart
+    c = Chart.find(:first)
+    c.datasource = ApplicationLog
+    c
+  end
+
+  def save_email(mail, name)
+    file = "#{RAILS_ROOT}/tmp/#{name}.eml"
+    open("#{file}","w") {|f| f.write(mail.encoded)}
+    print "Email saved to '#{file}'.\n"
+    if false
+      print "Starting kmail..."
+      system " kmail --view '#{file}'\n"    
+      print "done\n"
+    end
+    print "Check it in thunderbird.\n"
+    print "/!\\ Thunderbird does not display inline pictures if\n"
+    print "/!\\ the message is saved on disk."
+  end
+  def email_body(part)
+    # or something with that? TMail::Base64.folding_encode(body)
+    (part.body + part.parts.map {|p| email_body(p)}.join).gsub("=\n","").gsub("=3D","=")
+  end
+
+  def check_links_in_email(mail)
+    assert !(mail.body =~ /href=\"(\/[^\"]*)\"/), "Link without domain found '#{$1}'! (href=\"/), maybe you forgegotten option , :only_path => false in link_to."
+  end
+  
+  def assert_tidy_html
+    tidy_command = "tidy -errors -quiet"
+    open("|#{tidy_command} 2>&1 > /dev/null","w") {|f|
+      f.write(@response.body)
+    }
+    if $?.to_i != 0
+      @response.body.split("\n").each_with_index{|l,i|
+	print "#{(i+1).to_s.rjust(3)}: #{l}\n"
+      }
+    end
+    open("|#{tidy_command} > /dev/null","w") {|f|
+      f.write(@response.body)
+    }
+    assert_equal 0,$?.to_i,"Tidy is not happy with the html output."
+  end
+
+end

Added: incubator/alois/trunk/rails/test/unit/alarm_mailer_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/alarm_mailer_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/alarm_mailer_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/alarm_mailer_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,48 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'alarm_mailer'
+
+class AlarmMailerTest < ActiveSupport::TestCase
+  fixtures :alarms, :sentinels
+  # using howto on:
+  # http://manuals.rubyonrails.com/read/chapter/64
+  def setup
+    ActionMailer::Base.delivery_method = :test
+    ActionMailer::Base.perform_deliveries = true
+    ActionMailer::Base.deliveries = []
+
+    @alarm = Alarm.find(1)
+  end
+
+  def test_simple
+    response = AlarmMailer.create_simple(["test@logintas.com","test2@logintas.com"],@alarm)
+    check_links_in_email(response)
+    body = email_body(response)
+    save_email(response,"alarm_simple")
+
+    assert_match /Alarm Some sentinel \(warning\)$/, response.subject
+    # plaintextlink
+    assert_match /Link: https:\/\/localhost:3001\/alois\/alarms\/show\/1/, body
+    # htmllink
+
+    assert_match /<a href=\"https:\/\/localhost:3001\/alois\/alarms\/show\/1\" style=\"[^\"]*\">Alarm \#1<\/a>/, body
+
+    #@alarm = Alarm.find(1)
+    #AlarmMailer.create_simple(["flavio.pellanda@logintas.ch"],@alarm)
+    
+  end
+
+end

Added: incubator/alois/trunk/rails/test/unit/alarm_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/alarm_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/alarm_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/alarm_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,43 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class AlarmTest < ActiveSupport::TestCase
+  fixtures :alarms
+
+  # Replace this with your real tests.
+  def test_status_color
+#    assert_equal "green",Alarm.status_color
+    Alarm.delete_all
+    assert_equal "green",Alarm.status_color
+    Alarm.create(:alarm_level => 7)
+    assert_equal 1,Alarm.count
+    assert_equal "green",Alarm.status_color
+    Alarm.create(:alarm_level => 6)
+    assert_equal "green",Alarm.status_color
+    Alarm.create(:alarm_level => 5)
+    assert_equal "green",Alarm.status_color
+    Alarm.create(:alarm_level => 4)
+    assert_equal "yellow",Alarm.status_color
+    Alarm.create(:alarm_level => 3)
+    assert_equal "orange",Alarm.status_color
+    Alarm.create(:alarm_level => 2)
+    assert_equal "red",Alarm.status_color
+    Alarm.create(:alarm_level => 1)
+    assert_equal "red",Alarm.status_color
+    Alarm.create(:alarm_level => 0)
+    assert_equal "red",Alarm.status_color
+  end
+end

Added: incubator/alois/trunk/rails/test/unit/bookmark_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/bookmark_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/bookmark_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/bookmark_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,24 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class BookmarkTest < ActiveSupport::TestCase
+  fixtures :bookmarks
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

Added: incubator/alois/trunk/rails/test/unit/chart_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/chart_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/chart_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/chart_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,95 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ChartTest < ActiveSupport::TestCase
+  fixtures :charts, :views
+    
+  def test_yaml_hash
+    c = Chart.find(:first)
+    c.datasource = ApplicationLog
+    
+    assert_equal ApplicationLog, c.datasource
+    
+
+    assert_equal_yaml "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n",
+                      "--- !ruby/object:Chart \nattributes: \n  time_range: \"2008-04-09\"\n  column3: \n"
+
+    assert_equal_yaml CHART_YAML,c.to_yaml    
+    assert_equal Object.yaml_hash(CHART_YAML),Object.yaml_hash(c.to_yaml)
+    assert_equal Object.yaml_hash(CHART_YAML),c.yaml_hash
+
+    assert_equal ApplicationLog, c.datasource
+
+    c.render(CHART_RENDER_OPTIONS)
+
+    assert_equal_yaml CHART_AFTER_RENDER_YAML,c.to_yaml
+    assert_equal Object.yaml_hash(CHART_AFTER_RENDER_YAML),Object.yaml_hash(c.to_yaml)
+    assert_equal Object.yaml_hash(CHART_AFTER_RENDER_YAML),c.yaml_hash
+  end
+
+  def test_create_png    
+    file_rel = "charts/#{CHART_QUERY.hash}/chart_bar_300x300_#{Object.yaml_hash(CHART_AFTER_RENDER_YAML)}.png"
+    file = "#{RAILS_ROOT}/tmp/#{file_rel}"
+    link = "<IMG SRC=\"%s\" WIDTH=\"300\" HEIGHT=\"300\" BORDER=\"0\" USEMAP=\"#chart\">"
+
+    c = self.class.test_chart
+    assert_equal CHART_QUERY, c.query    
+    c.render(CHART_RENDER_OPTIONS)
+    assert_equal_yaml CHART_AFTER_RENDER_YAML, c.to_yaml
+
+    assert File.exist?(file), "File '#{file}' does not exist."
+    
+    assert_equal link % "XXX?a=b&action=chart_image&chart_tmpdir_hash=#{CHART_QUERY.hash}&chart_yaml_hash=#{Object.yaml_hash(CHART_AFTER_RENDER_YAML)}", c.image_tag(:url => "XXX?a=b")
+
+
+    assert_equal link % Pathname.new(file).realpath.to_s,c.image_tag(:absolute_path => true)
+   
+    assert_equal link % file_rel,c.image_tag(:relative_path => "#{RAILS_ROOT}/tmp/")
+
+  end
+
+  def test_load_yaml
+    c = self.class.test_chart
+    c.render(CHART_RENDER_OPTIONS)
+    
+    img_tag = c.image_tag(:relative_path => "#{RAILS_ROOT}/tmp/")
+
+    c2 = Chart.load_yaml(CHART_QUERY.hash.to_s, Object.yaml_hash(CHART_AFTER_RENDER_YAML).to_s)    
+    
+    assert_equal c, c2
+    assert_equal img_tag, c.image_tag(:relative_path => "#{RAILS_ROOT}/tmp/")
+
+    assert_raise RuntimeError do
+      c2.conditions = "(1=1)"
+    end
+    assert_raise RuntimeError do
+      c2.datasource = nil
+    end
+    assert_equal img_tag, c.image_tag(:relative_path => "#{RAILS_ROOT}/tmp/")
+    
+  end
+
+  def test_mapping
+    ["2008-01-01","2008-01-31","2008-12-01","2008-12-31"].each {|v|
+      assert_equal v, Chart.map_to_date(Chart.map_to_number(v))
+    }	
+
+    ["00:00:00","23:59:59","00:30:01","12:12:30"].each {|v|
+      assert_equal v, Chart.map_to_time(Chart.map_to_number(v))
+    }	
+  end
+  
+end

Added: incubator/alois/trunk/rails/test/unit/compression_meta_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/compression_meta_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/compression_meta_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/compression_meta_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,22 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class CompressionMetaTest < ActiveSupport::TestCase
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

Added: incubator/alois/trunk/rails/test/unit/condition_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/condition_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/condition_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/condition_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,44 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ConditionTest < ActiveSupport::TestCase
+
+  def test_sql_serialize
+    c = Condition.create(nil,"SQL","a=b")
+    re = Prisma.from_yaml(c.to_yaml)
+    assert re
+    assert "SQL",c.operator
+    assert "( a=b )", c.value
+  end
+
+  def test_sql_serialize_arr
+    c = Condition.create(nil,"SQL","a=b")
+    re = Prisma.from_yaml([c].to_yaml)[0]
+    assert re
+    assert "SQL",c.operator
+    assert "( a=b )", c.value
+  end
+  
+  def test_sql_condition
+    c = Condition.create(nil,"SQL","a=b")
+    assert_equal "SQL", c.operator
+    assert_equal "a=b", c.value
+    assert_equal "( a=b )", c.sql
+    assert_equal "", c.column
+    assert c.valid?(ApplicationLog)
+  end
+
+end

Added: incubator/alois/trunk/rails/test/unit/connection_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/connection_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/connection_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/connection_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,22 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'test_helper'
+
+class ConnectionTest < ActiveSupport::TestCase
+  # Replace this with your real tests.
+  test "the truth" do
+    assert true
+  end
+end

Added: incubator/alois/trunk/rails/test/unit/convert_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/convert_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/convert_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/convert_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,28 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ConvertTest < ActiveSupport::TestCase
+  
+  def do_test_zip(obj)
+    assert_equal obj, Object.from_zip(Object.to_zip(obj))
+  end
+
+  def test_tip
+    do_test_zip("lskjfslfjklkj")
+  end
+  
+end
+

Added: incubator/alois/trunk/rails/test/unit/ip_range_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/test/unit/ip_range_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/test/unit/ip_range_test.rb (added)
+++ incubator/alois/trunk/rails/test/unit/ip_range_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,52 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class IpRangeTest < ActiveSupport::TestCase
+  fixtures :ip_ranges
+
+  # Replace this with your real tests.
+  def test_ip_range_condition
+    # possible values:
+    # an ip: 192.168.1.1
+    # a range: 192.168.1.1-192.168.1.50
+    # an id of a range: 3
+    # the name of a filter: Filter 1
+    
+
+    assert_equal "INET_ATON(`ip`) = INET_ATON('192.168.1.1') ",
+      Condition.create("ip", "IPRANGE", "192.168.1.1").sql
+    assert_equal "INET_ATON(`ip`) = INET_ATON('192.168.001.001') ",
+      Condition.create("ip", "IPRANGE", "192.168.001.001 ").sql
+
+    assert_equal "INET_ATON(`ip`) >= INET_ATON('192.168.1.1') AND INET_ATON(`ip`) <= INET_ATON('192.168.1.50') ",
+      Condition.create("ip", "IPRANGE", "192.168.1.1-192.168.1.50").sql
+    assert_equal "INET_ATON(`ip`) >= INET_ATON('192.168.1.1') AND INET_ATON(`ip`) <= INET_ATON('192.168.01.50') ",
+      Condition.create("ip", "IPRANGE", " 192.168.1.1 - 192.168.01.50 ").sql
+
+    # by id
+    assert_equal "INET_ATON(`ip`) = INET_ATON('192.168.1.1') ",
+      Condition.create("ip", "IPRANGE", "1").sql
+    assert_equal "INET_ATON(`ip`) >= INET_ATON('192.168.1.1') AND INET_ATON(`ip`) <= INET_ATON('192.168.1.22') ",
+      Condition.create("ip", "IPRANGE", "3").sql
+
+    # by name
+    assert_equal "INET_ATON(`ip`) = INET_ATON('192.168.1.1') ",
+      Condition.create("ip", "IPRANGE", "aa").sql
+    assert_equal "INET_ATON(`ip`) >= INET_ATON('192.168.1.1') AND INET_ATON(`ip`) <= INET_ATON('192.168.1.22') ",
+      Condition.create("ip", "IPRANGE", "ccc").sql
+    
+  end
+end



Mime
View raw message