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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = test_Journal.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
# by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') if __FILE__ == $0
require 'test/unit'
require 'taskjuggler/Project'
class TaskJuggler
class TestJournal < Test::Unit::TestCase
class PTNMockup
attr_reader :index
def initialize(index)
@index = index
end
def ptn
self
end
end
def setup
@p = TaskJuggler::Project.new('hello', 'Hello World', '1.0')
@p['start'] = tm('2009-11-01')
@p['end'] = tm('2009-12-31')
@j = @p['journal']
end
def teardown
end
def test_add
# First some simple add tests.
@j.addEntry(e = JournalEntry.new(@j, tm('2009-11-29'), "E1",
PTNMockup.new(1)))
assert_equal(1, @j.entries.count)
# Make sure we don't add the same entry twice.
@j.addEntry(e)
assert_equal(1, @j.entries.count)
@j.addEntry(JournalEntry.new(@j, tm('2009-11-30'), "E2",
PTNMockup.new(2)))
@j.addEntry(JournalEntry.new(@j, tm('2009-12-01'), "E3",
PTNMockup.new(3)))
assert_equal(3, @j.entries.count)
end
def test_sort
# Add a bunch of entries and see if the sorting by date works properly.
@j.addEntry(JournalEntry.new(@j, tm('2009-12-10'), "E4",
PTNMockup.new(4)))
@j.addEntry(JournalEntry.new(@j, tm('2009-12-03'), "E2",
PTNMockup.new(2)))
@j.addEntry(JournalEntry.new(@j, tm('2009-12-06'), "E3",
PTNMockup.new(3)))
@j.addEntry(JournalEntry.new(@j, tm('2009-11-29'), "E0",
PTNMockup.new(0)))
@j.addEntry(JournalEntry.new(@j, tm('2009-12-01'), "E1",
PTNMockup.new(1)))
@j.addEntry(JournalEntry.new(@j, tm('2009-12-24'), "E5",
PTNMockup.new(5)))
pList = []
@j.entries.each { |e| pList << e.property }
pList.each do |i|
assert_equal(pList.index(i), i.index)
end
end
def test_sortSameDate
# Add a bunch of entries and see if the sorting by date works properly.
@j.addEntry(e = JournalEntry.new(@j, tm('2009-12-10'), "A2",
PTNMockup.new(0)))
e.alertLevel = 2
@j.addEntry(e = JournalEntry.new(@j, tm('2009-12-10'), "A0",
PTNMockup.new(0)))
e.alertLevel = 0
@j.addEntry(e = JournalEntry.new(@j, tm('2009-12-10'), "A1",
PTNMockup.new(0)))
e.alertLevel = 1
@j.addEntry(e = JournalEntry.new(@j, tm('2009-12-10'), "A3",
PTNMockup.new(0)))
e.alertLevel = 3
i = 0
@j.entries.each do |entry|
assert_equal(i, entry.alertLevel)
i += 1
end
end
def test_currentEntries
createTaskTree
q = Query.new
q.scenarioIdx = 0
# Set a 0 alert for a task
a1 = addAlert('2009-11-29', 0, t = task('p1.m1.l1'))
ce = @j.currentEntriesR(tm('2009-12-05'), t, 0, nil, q)
assert_equal(1, ce.count)
assert_equal(a1, ce[0])
# Add a later alert for the same task
a2 = addAlert('2009-11-30', 0, t = task('p1.m1.l1'))
ce = @j.currentEntriesR(tm('2009-12-05'), t, 0, nil, q)
assert_equal(1, ce.count)
assert_equal(a2, ce[0])
# Add another alert to the sister task and check parent
a3 = addAlert('2009-11-30', 0, t = task('p1.m1.l2'))
ce = @j.currentEntriesR(tm('2009-12-05'), task('p1.m1'), 0, nil, q)
assert_equal(2, ce.count)
assert_equal(a2, ce[0])
assert_equal(a3, ce[1])
# Check root task
ce = @j.currentEntriesR(tm('2009-12-05'), task('p1'), 0, nil, q)
assert_equal(2, ce.count)
assert_equal(a2, ce[0])
assert_equal(a3, ce[1])
# Add old override alert to p1.m1
addAlert('2009-11-29', 0, t = task('p1.m1'))
ce = @j.currentEntriesR(tm('2009-12-05'), task('p1'), 0, nil, q)
assert_equal(2, ce.count)
assert_equal(a2, ce[0])
assert_equal(a3, ce[1])
# Add new override alert to p1.m1
a4 = addAlert('2009-12-01', 0, t = task('p1.m1'))
ce = @j.currentEntriesR(tm('2009-12-05'), task('p1'), 0, nil, q)
assert_equal(1, ce.count)
assert_equal(a4, ce[0])
end
def test_alertSimple
createTaskTree
q = Query.new
q.scenarioIdx = 0
# Set a 0 alert for a task
addAlert('2009-11-29', 0, t = task('p1.m1.l1'))
assert_equal(0, @j.alertLevel(tm('2009-12-01'), t, q))
# Now add a later 1 alert
addAlert('2009-12-01', 1, t)
assert_equal(1, @j.alertLevel(tm('2009-12-02'), t, q))
# Set a 2 alert for p1.m1.l2
addAlert('2009-11-29', 2, task('p1.m1.l2'))
assert_equal(2, @j.alertLevel(tm('2009-12-01'), task('p1'), q))
# Overide p1.m1 with 0 alert
addAlert('2009-12-01', 0, task('p1.m1'))
assert_equal(0, @j.alertLevel(tm('2009-12-01'), task('p1'), q))
end
private
def tm(s)
TjTime.new(s)
end
def addAlert(date, level, property)
raise "No property" unless property
@j.addEntry(e = JournalEntry.new(@j, tm(date),
"Set #{property.fullId} " +
"to level #{level}i at #{date}",
property))
e.alertLevel = level
e
end
def createTaskTree
p1 = newTask(nil, 'p1')
m1 = newTask(p1, 'm1')
newTask(p1, 'm2')
newTask(m1, 'l1')
newTask(m1, 'l2')
newTask(nil, 'p2')
end
def newTask(parent, id)
Task.new(@p, id, 'Task #{id}', parent)
end
def task(id)
@p.task(id) || ( raise "Unknown task id #{id}" )
end
end
end
|