1 #!/bin/sh 2 3 THIS_DIR=`dirname $0` 4 5 TEMPLATES="$THIS_DIR/templates" 6 PERSON_SCRIPT="$THIS_DIR/../imip_person.py" 7 RESOURCE_SCRIPT="$THIS_DIR/../imip_resource.py" 8 SHOWMAIL="$THIS_DIR/../tools/showmail.py" 9 STORE=/tmp/store 10 STATIC=/tmp/static 11 PREFS=/tmp/prefs 12 ARGS="-S $STORE -P $STATIC -p $PREFS -d" 13 USER="mailto:resource-room-sauna@example.com" 14 SENDER="mailto:paul.boddie@example.com" 15 RIVALSENDER="mailto:vincent.vole@example.com" 16 FBFILE="$STORE/$USER/freebusy" 17 FBOTHERFILE="$STORE/$USER/freebusy-other/$SENDER" 18 FBOFFERFILE="$STORE/$USER/freebusy-offers" 19 FBSENDERFILE="$STORE/$SENDER/freebusy" 20 FBSENDEROTHERFILE="$STORE/$SENDER/freebusy-other/$USER" 21 FBSENDERREQUESTS="$STORE/$SENDER/requests" 22 FBRIVALSENDERFILE="$STORE/$RIVALSENDER/freebusy" 23 TAB=`printf '\t'` 24 25 OUTGOING_SCRIPT="$THIS_DIR/../imip_person_outgoing.py" 26 27 ERROR=err.tmp 28 29 rm -rf $STORE 30 rm -rf $STATIC 31 rm -rf $PREFS 32 rm -f $ERROR 33 rm -f out*.tmp 34 35 mkdir -p "$PREFS/$USER" 36 echo 'Europe/Oslo' > "$PREFS/$USER/TZID" 37 echo 'share' > "$PREFS/$USER/freebusy_sharing" 38 echo 'schedule_next_available_in_freebusy' > "$PREFS/$USER/scheduling_function" 39 echo 'PT60S' > "$PREFS/$USER/freebusy_offers" 40 41 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-sauna-all.txt" 2>> $ERROR \ 42 | "$SHOWMAIL" \ 43 > out0.tmp 44 45 grep -q 'METHOD:REPLY' out0.tmp \ 46 && ! grep -q '^FREEBUSY' out0.tmp \ 47 && echo "Success" \ 48 || echo "Failed" 49 50 # Let the rival sender book the resource. 51 52 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-sauna-busy.txt" 2>> $ERROR 53 54 [ `grep "event19@example.com" "$FBRIVALSENDERFILE" | wc -l` = '5' ] \ 55 && grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBRIVALSENDERFILE" \ 56 && echo "Success" \ 57 || echo "Failed" 58 59 # Present the request to the resource. 60 61 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-sauna-busy.txt" 2>> $ERROR \ 62 | tee out1r.tmp \ 63 | "$SHOWMAIL" \ 64 > out1.tmp 65 66 grep -q 'METHOD:REPLY' out1.tmp \ 67 && grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T160000' out1.tmp \ 68 && echo "Success" \ 69 || echo "Failed" 70 71 [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \ 72 && grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \ 73 && echo "Success" \ 74 || echo "Failed" 75 76 # Present the response to the rival sender. 77 78 "$PERSON_SCRIPT" $ARGS < out1r.tmp 2>> $ERROR \ 79 | tee out2r.tmp \ 80 | "$SHOWMAIL" \ 81 > out2.tmp 82 83 # Publish some conflicting periods as busy. 84 85 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-publish-conflicts.txt" 2>> $ERROR \ 86 | "$SHOWMAIL" \ 87 > out3.tmp 88 89 grep -q "^20141126T160000Z${TAB}20141126T170000Z" "$FBOTHERFILE" \ 90 && grep -q "^20141126T180000Z${TAB}20141126T190000Z" "$FBOTHERFILE" \ 91 && echo "Success" \ 92 || echo "Failed" 93 94 # Attempt to schedule an event with the resource. 95 96 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-sauna-good.txt" 2>> $ERROR 97 98 grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBSENDERFILE" \ 99 && echo "Success" \ 100 || echo "Failed" 101 102 # Present the request to the resource. This should cause the event to be 103 # proposed not just after the requested period, but also after the busy periods 104 # published to the resource. 105 106 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-sauna-good.txt" 2>> $ERROR \ 107 | tee out6r.tmp \ 108 | "$SHOWMAIL" \ 109 > out6.tmp 110 111 grep -q 'METHOD:COUNTER' out6.tmp \ 112 && ! grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out6.tmp \ 113 && echo "Success" \ 114 || echo "Failed" 115 116 ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \ 117 && ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ 118 && ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \ 119 && ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \ 120 && ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \ 121 && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBOFFERFILE" \ 122 && echo "Success" \ 123 || echo "Failed" 124 125 # Present the response to the organiser. 126 127 "$PERSON_SCRIPT" $ARGS < out6r.tmp 2>> $ERROR \ 128 | tee out7r.tmp \ 129 | "$SHOWMAIL" \ 130 > out7.tmp 131 132 grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBSENDERFILE" \ 133 && ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBSENDERFILE" \ 134 && echo "Success" \ 135 || echo "Failed" 136 137 [ -e "$STORE/$SENDER/counters/objects/event13@example.com/$USER" ] \ 138 && echo "Success" \ 139 || echo "Failed" 140 141 grep -q 'event13@example.com' "$FBSENDERREQUESTS" \ 142 && echo "Success" \ 143 || echo "Failed" 144 145 # Reschedule the event by accepting the counter-proposal. 146 147 sed 's/COUNTER/REQUEST/' < out6.tmp \ 148 | sed 's/^From: calendar/To: resource-room-sauna/' \ 149 | sed 's/^To: paul.boddie/From: paul.boddie/' \ 150 > out8.tmp 151 152 "$OUTGOING_SCRIPT" $ARGS < out8.tmp 2>> $ERROR 153 154 ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBSENDERFILE" \ 155 && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBSENDERFILE" \ 156 && echo "Success" \ 157 || echo "Failed" 158 159 ! [ -e "$STORE/$SENDER/counters/objects/event13@example.com/$USER" ] \ 160 && echo "Success" \ 161 || echo "Failed" 162 163 ! grep -q 'event13@example.com' "$FBSENDERREQUESTS" \ 164 && echo "Success" \ 165 || echo "Failed" 166 167 "$RESOURCE_SCRIPT" $ARGS < out8.tmp 2>> $ERROR \ 168 | "$SHOWMAIL" \ 169 > out9.tmp 170 171 grep -q 'METHOD:REPLY' out9.tmp \ 172 && grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T210000' out9.tmp \ 173 && echo "Success" \ 174 || echo "Failed" 175 176 ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \ 177 && ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ 178 && ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \ 179 && ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \ 180 && ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \ 181 && ! grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBOFFERFILE" \ 182 && echo "Success" \ 183 || echo "Failed" 184 185 [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \ 186 && [ `grep "event13@example.com" "$FBFILE" | wc -l` = '1' ] \ 187 && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \ 188 && echo "Success" \ 189 || echo "Failed" 190 191 # Test updating the event to see if the resource can handle this. 192 193 "$RESOURCE_SCRIPT" $ARGS < out8.tmp 2>> $ERROR \ 194 | "$SHOWMAIL" \ 195 > out10.tmp 196 197 grep -q 'METHOD:REPLY' out10.tmp \ 198 && grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T210000' out10.tmp \ 199 && echo "Success" \ 200 || echo "Failed" 201 202 ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \ 203 && ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ 204 && ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \ 205 && ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \ 206 && ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \ 207 && ! grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBOFFERFILE" \ 208 && echo "Success" \ 209 || echo "Failed" 210 211 [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \ 212 && [ `grep "event13@example.com" "$FBFILE" | wc -l` = '1' ] \ 213 && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \ 214 && echo "Success" \ 215 || echo "Failed" 216 217 # Test scheduling again with a different period. This should disregard the 218 # existing event periods when computing availability in order to be able to 219 # offer them again. Otherwise, an offer would be made for even later periods. 220 221 sed 's/20141126T160000/20141126T161500/' < "$TEMPLATES/event-request-sauna-good.txt" \ 222 | tee out11.tmp \ 223 | "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ 224 | "$SHOWMAIL" \ 225 > out12.tmp 226 227 grep -q 'METHOD:COUNTER' out12.tmp \ 228 && grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T210000' out12.tmp \ 229 && echo "Success" \ 230 || echo "Failed" 231 232 # Note that the duration is different now. 233 234 ! grep -q "^20141126T150000Z${TAB}20141126T154500Z" "$FBOFFERFILE" \ 235 && ! grep -q "^20141126T160000Z${TAB}20141126T164500Z" "$FBOFFERFILE" \ 236 && ! grep -q "^20141126T170000Z${TAB}20141126T174500Z" "$FBOFFERFILE" \ 237 && ! grep -q "^20141126T180000Z${TAB}20141126T184500Z" "$FBOFFERFILE" \ 238 && ! grep -q "^20141126T190000Z${TAB}20141126T194500Z" "$FBOFFERFILE" \ 239 && grep -q "^20141126T200000Z${TAB}20141126T203000Z" "$FBOFFERFILE" \ 240 && echo "Success" \ 241 || echo "Failed" 242 243 [ `grep "event19@example.com" "$FBFILE" | wc -l` = '5' ] \ 244 && [ `grep "event13@example.com" "$FBFILE" | wc -l` = '1' ] \ 245 && grep -q "^20141126T200000Z${TAB}20141126T204500Z" "$FBFILE" \ 246 && echo "Success" \ 247 || echo "Failed"