summaryrefslogtreecommitdiff
path: root/t/test-custodian-alertfactory.rb
blob: 3138fa6074e64f03f628bd924aa94583f4f346e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/ruby -Ilib/ -I../lib/


require 'test/unit'

require 'custodian/alerts'



class TestAlertFactory < Test::Unit::TestCase

  #
  # Create the test suite environment: NOP.
  #
  def setup
  end

  #
  # Destroy the test suite environment: NOP.
  #
  def teardown
  end


  #
  # Test the FTP-test may be created
  #
  def test_alert_creation

    #
    # Ensure we can create each of the two alert types we care about
    #
    methods = []
    methods.push('file')
    methods.push('smtp')

    #
    # Mauve + Redis are optional
    #
    redis = true
    mauve = true

    begin
      require 'rubygems'
      require 'redis'
    rescue LoadError => ex
      redis = false
    end

    begin
      require 'mauve/sender'
      require 'mauve/proto'
    rescue LoadError => ex
      mauve = false
    end

    methods.push('redis') if  redis
    methods.push('mauve') if  mauve

    methods.each do |name|

      #
      #  Use the factory to instantiate the correct object.
      #
      obj = Custodian::AlertFactory.create(name, nil)

      #
      # Get the name of the class, and ensure it matches
      # what we expect.
      #
      a_type = obj.get_type
      assert_equal(name, a_type)

      #
      # Ensure that the object implements the raise() + clear()
      # methods we mandate.
      #
      assert(obj.respond_to? 'raise')
      assert(obj.respond_to? 'clear')
    end


    #
    # Creating an alert we don't know about is an error
    #
    assert_raise ArgumentError do
      obj = Custodian::AlertFactory.create('not found', nil)
    end

    #
    # A string is mandatory
    #
    assert_raise ArgumentError do
      obj = Custodian::AlertFactory.create(nil, nil)
    end
    assert_raise ArgumentError do
      obj = Custodian::AlertFactory.create([], nil)
    end

  end

end