Class | SiteTest
In: | test/unit/site_test.rb
Parent: | Test::Unit::TestCase

Copyright (c) 2006 Logica

### Methods

setup teardown test_new_baseline_process test_new_wiki test_new_wiki test_update_wiki test_upload test_wikifiable_files

### Public Instance methods

setup()

[Source]

        # File test/unit/site_test.rb, line 21
    21:   def setup
    22:     logger.debug "Test Case: #{name}"
    23:     @george = users(:george)
    24:     @oup_20060721 = create_oup_20060721
    25:     @emails = ActionMailer::Base::deliveries
    26:     @emails.clear
    27:   end

teardown()

[Source]

        # File test/unit/site_test.rb, line 29
    29:   def teardown
    30:     [ENV['EPFWIKI_SITES_PATH'], ENV['EPFWIKI_WIKIS_PATH']].each do |p|
    31:       FileUtils.rm_r(p) if File.exists?(p)
    32:       File.makedirs(p)
    33:     end
    34:   end

test_new_baseline_process()

Shows:

1. To create a new BaselineProcess we have to specifiy: title, folder, baseline, user
2. We cannot create a BaselineProcess from non-existing folder
3. We can create a BaselineProcess
4. We cannot use a folder twice (create two or more sites from the same folder)
5. We can scan the content

[Source]

        # File test/unit/site_test.rb, line 42
    42:   def test_new_baseline_process
    43:     BaselineProcess.destroy_all
    44:     # 1.
    45:     site = BaselineProcess.new
    46:     assert !site.save
    47:     assert_equal "Title can't be blank, Folder can't be blank, Folder does not seem to contain a valid site, no index.htm or index.html was found, User can't be blank", site.errors.full_messages.join(", ")
    48:     # 2.
    49:     site_count = Site.count
    50:     site = BaselineProcess.new(:folder => 'nonexistingfolder', :title => 'OUP_20060721', :user_id => @george.id)
    51:     assert !site.save
    52:     assert_equal 'Folder doesn\'t exist, Folder does not seem to contain a valid site, no index.htm or index.html was found', site.errors.full_messages.join(', ')
    53:     assert_equal site_count, Site.count
    54:     # 3.
    55:     site = BaselineProcess.new(:folder => 'oup_20060721', :title => 'oup_20060721', :user_id => @george.id)
    56:     assert site.save
    57:     assert_equal '', site.errors.full_messages.join(', ')
    58:     assert_equal site_count + 1, Site.count
    59:     site = Site.find(site.id)
    60:     # 4.
    61:     site = BaselineProcess.new(:folder => 'oup_20060721', :title => 'oup_20060721', :user_id => @george.id)
    62:     assert !site.save
    63:     assert_equal 'Folder was already used to create a baseline process', site.errors.full_messages.join(', ')
    64:     assert_equal site_count + 1, Site.count
    65:     # 5.
    66:     sites = BaselineProcess.find_2scan
    67:     assert_equal 1, sites.size
    68:     site = sites[0]
    69:     assert_equal ['oup_20060721', 'oup_20060721'], [site.title, site.folder]
    70:     assert site.content_scanned_on.nil?
    71:     site.scan4content
    72:     assert_not_nil site.content_scanned_on
    73:     assert_equal 617, site.pages.size
    74:     #site.versions[0..3].each do |v|
    75:     #  assert_equal [true, 0, false, false, false, false], [v.base_version?, v.version, v.rel_path.nil?, v.wiki_id.nil?, v.user_id.nil?, v.page_id.nil?]
    76:     #end
    77:     site.pages[0..3].each do |p|
    78:       assert_equal [false, false, 'BaselineProcessPage', 'EPFC', 'N.A.', false, false, false, false,false,false], [p.rel_path.nil?, p.presentation_name.nil?, p.type, p.tool,
    79:         p.status, p.uma_type.nil?, p.filename.nil?, p.uma_name.nil?, p.body_tag.nil?, p.treebrowser_tag.nil?, p.copyright_tag.nil?]
    80:     end
    81:   end

test_new_wiki()

Shows:

1. We cannot Wikify a BaselineProcess TODO?
2. We can update content in a Wiki site
3. The Wikify operation will cause content of baseline process to be scanned (because it was not scanned yet)

4.

1. TODO: test if content was wikified correctly

[Source]

         # File test/unit/site_test.rb, line 156
    156:   def test_new_wiki
    157:     @oup_20060728 = create_oup_20060728
    158:     @oup_wiki = create_oup_wiki(@oup_20060721)
    159:     @oup_wiki.reload # zou niet nodig moeten zijn maar is dat wel????
    160:     assert_equal @oup_20060721, @oup_wiki.baseline_process # Is nil, weer zo'n probleem dat niet kan maar toch 0ptreedt, ik wordt hier echt kriegel van
    161:     # 1
    162:     #assert_raise(RuntimeError) {@oup_20060721.wikify}
    163:     # 2
    164:     #@oup_wiki.baseline_process = @oup_20060728
    165:     assert_equal 'Ready', @oup_wiki.status
    166:     cnt = Update.count
    167:     update = Update.create(:baseline_process_id => @oup_20060728.id, :wiki_id => @oup_wiki.id, :user_id => @george.id )
    168:     assert_equal cnt+1, Update.count
    169:     #assert @oup_wiki.save
    170:     @oup_wiki.reload # NOTE: @oup_wiki.updates is cached so status will wrong without reload
    171:     assert_equal 'Scheduled', @oup_wiki.status
    172:     updates = Update.find_todo
    173:     assert_equal 1, updates.size
    174:     assert_equal @oup_wiki, updates[0].wiki
    175:     update.do_update
    176:     update.reload
    177:     assert_equal 'Ready', update.wiki.status
    178:     @oup_wiki.reload
    179:     assert_equal [], Update.find_todo
    180:     assert_equal 1, Wiki.find(:all).size
    181:     @oup_20060721.reload
    182:     assert_not_nil @oup_20060721
    183:     assert_equal 'oup_20060721',@oup_20060721.title
    184:     #assert_equal @oup_wiki.baseline, @oup_20060728.baseline
    185:     assert_equal 617, @oup_wiki.pages.size
    186:     # 3
    187:     assert_equal @oup_wiki.pages.size, @oup_20060728.pages.size
    188:     # 4
    189:     assert_equal [1234, [["Updated", 617]], [["N.A.", 1234]]],[@oup_wiki.versions.size, WikiPage.count(:group => 'status'), BaselineProcessPage.count(:group => 'status')]
    190:     status = WikiPage.count(:group => 'status')
    191:     types = WikiPage.count(:group => 'uma_type')
    192:     assert_equal [["Updated", 617]], status
    193:     assert_equal [["Activity", 140],
    194:  ["Artifact", 23],
    195:  ["CapabilityPattern", 35],
    196:  ["Checklist", 10],
    197:  ["Concept", 48],
    198:  ["CustomCategory", 4],
    199:  ["DeliveryProcess", 5],
    200:  ["Discipline", 6],
    201:  ["DisciplineGrouping", 1],
    202:  ["Domain", 6],
    203:  ["Guideline", 45],
    204:  ["Milestone", 4],
    205:  ["Roadmap", 1],
    206:  ["Role", 7],
    207:  ["RoleDescriptor", 33],
    208:  ["RoleSet", 1],
    209:  ["Summary", 114],
    210:  ["SupportingMaterial", 4],
    211:  ["Task", 23],
    212:  ["TaskDescriptor", 25],
    213:  ["Template", 8],
    214:  ["TermDefinition", 7],
    215:  ["WorkProductDescriptor", 59],
    216:  ["WorkProductType", 8]], types
    217:   end

test_new_wiki()

Shows:

1. To create a Wiki we need to specifiy a folder, title and user
2. We create a Wiki
3. We try to schedule an Update of the Wiki but we mix things up
4. We schedule an Update of the Wiki with a BaselineProcess
5. The Wiki folder should be unique
6. We cannot wikify a BaselineProcess
7. We can Wikify a Wiki

[Source]

         # File test/unit/site_test.rb, line 100
    100:   def test_new_wiki
    101:     # 1.
    102:     sites_count, update_count = Site.count, Update.count
    103:     wiki = Wiki.new#(:folder => 'openup', :title => 'OpenUP Wiki', :user_id => @george.id)
    104:     assert !wiki.save
    105:     assert_equal "Title can't be blank, Folder can't be blank, User can't be blank", wiki.errors.full_messages.join(', ')
    106:     assert_equal [sites_count, update_count], [Site.count, Update.count]
    107:     # 2.
    108:     wiki = Wiki.new(:folder => 'openup', :title => 'OpenUP Wiki', :user_id => @george.id)
    109:     assert wiki.save
    110:     assert_equal "", wiki.errors.full_messages.join(', ')
    111:     wiki.reload
    112:     assert_equal sites_count+1, Site.count
    113:     # 3
    114:     update = Update.new(:baseline_process_id => wiki.id, :wiki_id => @oup_20060721.id, :user_id => @george.id)
    115:     assert !update.save
    116:     assert_equal "Baseline process is not a BaselineProcess, Wiki is not a Wiki", update.errors.full_messages.join(', ')
    117:     assert_equal 'Pending', wiki.status
    118:     # 4
    119:     update = Update.new(:baseline_process_id => @oup_20060721.id, :wiki_id => wiki.id, :user_id => @george.id)
    120:     assert update.save
    121:     assert_equal 'Pending', wiki.status
    122:     assert_equal 1, @emails.size
    123:     assert_equal "SCHEDULED creation new Wiki #{update.wiki.title} using Baseline Process #{update.baseline_process.title}", @emails[0].subject
    124:     @emails.clear
    125:     # 5.
    126:     wiki = Wiki.new(:folder => 'openup', :title => 'OpenUP Wiki', :user_id => @george.id)
    127:     assert !wiki.save
    128:     assert_equal 'Folder already exists', wiki.errors.full_messages.join(', ')
    129:     # 6
    130:     assert_raise(NoMethodError) {@oup_20060721.wikify}
    131:     # 7
    132:     assert_equal 1, Update.find_todo.size
    133:     update = Update.find_todo[0]
    134:     w, bp = update.wiki, update.baseline_process
    135:     assert_equal ['Ready', 617], [bp.status, bp.pages.size]
    136:     update.baseline_process.scan4content
    137:     assert_equal ['Ready', 617], [bp.status, bp.pages.size]
    138:     assert_equal ['Pending', 0], [w.status, w.pages.size]
    139:     update.do_update
    140:     assert_equal 0, Update.find_todo.size
    141:     assert_equal ['Ready', 617], [w.status, w.pages.size]
    142:     assert_equal w.pages.size + bp.pages.size, Page.count
    143:     assert_equal 2, @emails.size
    144:     assert_equal "STARTED creating New Wiki #{update.wiki.title} using Baseline Process #{update.baseline_process.title}", @emails[0].subject
    145:     assert_equal "FINISHED creating new Wiki #{update.wiki.title} using Baseline Process #{update.baseline_process.title}", @emails[0].subject
    146:     assert_equal update.user.email, @emails.to[0]
    147:     assert_equal User.find_central_admin, @emails.cc[0]
    148:   end

test_update_wiki()

Shows:

1. Can‘t update a BaselineProcess (site_type != ‘W’)
2. Can update a wiki with a current or previous BaselineProcess
3. Can update or cancel a pending wiki
4. We can do the actual update
5. Update with Templates baseline
6. We can also update with a previous baseline process

[Source]

         # File test/unit/site_test.rb, line 226
    226:   def test_update_wiki
    227:     @oup_20060728 = create_oup_20060728
    228:     @oup_20060825 = create_oup_20060825
    229:     @oup_wiki = create_oup_wiki(@oup_20060721)
    230:     # 2
    231:     update = Update.new(:baseline_process_id => @oup_20060728.id, :wiki_id => @oup_20060721.id, :user_id => @george.id)
    232:     assert !update.save
    233:     assert_equal 'Wiki is not a Wiki', update.errors.full_messages.join(', ')
    234:     @oup_wiki.reload
    235:     assert_equal 'Ready', @oup_wiki.status
    236:     # 3
    237:     @oup_20060721.reload
    238:     #@oup_wiki = create_oup_wiki(@oup_20060721)
    239:     update = Update.new(:baseline_process_id => @oup_20060721.id, :wiki_id => @oup_wiki.id, :user_id => @george.id)
    240:     assert update.save
    241:     @oup_wiki.reload
    242:     assert_equal 'Scheduled', @oup_wiki.status
    243:     # 4
    244:     update.baseline_process = @oup_20060825
    245:     assert update.save
    246:     @oup_wiki.reload
    247:     assert_equal 'Scheduled', @oup_wiki.status
    248:     assert_equal @oup_20060721, @oup_wiki.baseline_process
    249:     assert_equal 'Scheduled', @oup_wiki.status
    250:     update.destroy
    251:     #assert @oup_wiki.save
    252:     @oup_wiki.reload
    253:     assert_equal 'Ready', @oup_wiki.status
    254:     # 5
    255:     update = Update.new(:baseline_process_id => @oup_20060728.id, :wiki_id => @oup_wiki.id, :user_id => @george.id)
    256:     assert update.save
    257:     @oup_wiki.reload
    258:     assert_equal 'Scheduled', @oup_wiki.status
    259:     assert_equal 617, @oup_20060728.pages.size
    260:     update.do_update
    261:     @oup_wiki.reload
    262:     @oup_20060728.reload
    263:     assert_equal @oup_wiki.baseline_process,@oup_20060728
    264:     assert_equal 617, @oup_wiki.pages.size
    265:     @oup_20060728.reload
    266:     assert_equal 617, @oup_20060728.pages.size # content scan triggered by update
    267:     status = WikiPage.count(:group => 'status')
    268:     assert_equal [["Updated", 617]], status
    269:     # 6
    270:     tpb_bl = create_templates_baseline
    271:     assert_equal 'Ready', @oup_wiki.status
    272:     update = Update.new(:baseline_process_id => tpb_bl.id, :wiki_id => @oup_wiki.id, :user_id => @george.id)
    273:     assert update.save
    274:     @oup_wiki.reload
    275:     assert_equal 'Scheduled', @oup_wiki.status
    276:     status = WikiPage.count(:group => 'status')
    277:     assert_equal [["Updated", 617]], status
    278:     update.do_update
    279:     @oup_wiki.reload
    280:     assert_equal 'Ready', @oup_wiki.status
    281:     assert_equal tpb_bl, @oup_wiki.baseline_process
    282:     assert_equal [["New", 26], ["RemovedOrMoved", 617]], WikiPage.count(:group => 'status', :conditions => ['site_id=?',@oup_wiki.id])
    283:     # 7
    284:     update = Update.new(:baseline_process_id => @oup_20060728.id, :wiki_id => @oup_wiki.id, :user_id => @george.id)
    285:     assert update.save
    286:     @oup_wiki.reload
    287:     assert_equal 'Scheduled', @oup_wiki.status
    288:     update.do_update
    289:     @oup_wiki.reload
    290:     assert_equal 'Ready', @oup_wiki.status
    291:     assert_equal @oup_wiki.baseline_process, @oup_20060728
    292:     assert_equal [["RemovedOrMoved", 26], ["Updated", 617]], WikiPage.count(:group => 'status', :conditions => ['site_id=?',@oup_wiki.id])
    293:   end

test_upload()

Shows:

1. we cannot unzip same content twice

[Source]

        # File test/unit/site_test.rb, line 85
    85:   def test_upload
    86:     # 1
    87:     assert_raise(RuntimeError){@oup_20060721.unzip_upload}
    88:     names = ['OpenUP_Basic_published-0.9-W-20070316']
    89:     assert_equal 'openup_basic_published09w20070316', valid_filename(names[0])
    90:   end

test_wikifiable_files()

[Source]

         # File test/unit/site_test.rb, line 295
    295:   def test_wikifiable_files
    296:     wikifiable_files = @oup_20060721.files_wikifiable
    297:     assert_equal 617, wikifiable_files.size
    298:     assert_equal 617, wikifiable_files.size
    299:   end

[Validate]