imip-agent

Annotated tests/test_resource_invitation_constraints_quota.sh

1047:c06cdeae95a3
2016-02-08 Paul Boddie Added a test of booking two resources sharing a quota at the same time.
paul@1039 1
#!/bin/sh
paul@1039 2
paul@1039 3
. "`dirname \"$0\"`/common.sh"
paul@1039 4
paul@1039 5
USER1="mailto:resource-car-porsche911@example.com"
paul@1039 6
USER2="mailto:resource-car-fiat500@example.com"
paul@1039 7
SENDER="mailto:paul.boddie@example.com"
paul@1039 8
FBFILE1="$STORE/$USER1/freebusy"
paul@1039 9
FBFILE2="$STORE/$USER2/freebusy"
paul@1039 10
FBSENDERFILE="$STORE/$SENDER/freebusy"
paul@1039 11
QUOTA=cars
paul@1039 12
JOURNALFILE="$JOURNAL/$QUOTA/journal/$SENDER"
paul@1039 13
paul@1039 14
mkdir -p "$PREFS/$USER1"
paul@1039 15
echo 'Europe/Oslo' > "$PREFS/$USER1/TZID"
paul@1039 16
echo 'share' > "$PREFS/$USER1/freebusy_sharing"
paul@1039 17
cat > "$PREFS/$USER1/scheduling_function" <<EOF
paul@1039 18
schedule_in_freebusy
paul@1039 19
check_quota $QUOTA
paul@1039 20
EOF
paul@1039 21
cat > "$PREFS/$USER1/confirmation_function" <<EOF
paul@1039 22
add_to_quota $QUOTA
paul@1039 23
EOF
paul@1039 24
cat > "$PREFS/$USER1/retraction_function" <<EOF
paul@1039 25
remove_from_quota $QUOTA
paul@1039 26
EOF
paul@1039 27
paul@1039 28
mkdir -p "$PREFS/$USER2"
paul@1039 29
echo 'Europe/Oslo' > "$PREFS/$USER2/TZID"
paul@1039 30
echo 'share' > "$PREFS/$USER2/freebusy_sharing"
paul@1039 31
cat > "$PREFS/$USER2/scheduling_function" <<EOF
paul@1039 32
schedule_in_freebusy
paul@1039 33
check_quota $QUOTA
paul@1039 34
EOF
paul@1039 35
cat > "$PREFS/$USER2/confirmation_function" <<EOF
paul@1039 36
add_to_quota $QUOTA
paul@1039 37
EOF
paul@1039 38
cat > "$PREFS/$USER2/retraction_function" <<EOF
paul@1039 39
remove_from_quota $QUOTA
paul@1039 40
EOF
paul@1039 41
paul@1039 42
mkdir -p "$JOURNAL/$QUOTA"
paul@1046 43
echo '* PT1H' > "$JOURNAL/$QUOTA/limits"
paul@1039 44
paul@1039 45
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car.txt" 2>> $ERROR \
paul@1039 46
| "$SHOWMAIL" \
paul@1039 47
> out0.tmp
paul@1039 48
paul@1039 49
   grep -q 'METHOD:REPLY' out0.tmp \
paul@1039 50
&& ! grep -q '^FREEBUSY' out0.tmp \
paul@1039 51
&& echo "Success" \
paul@1039 52
|| echo "Failed"
paul@1039 53
paul@1039 54
# Attempt to schedule an event.
paul@1039 55
paul@1039 56
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR
paul@1039 57
paul@1039 58
   grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
paul@1039 59
&& echo "Success" \
paul@1039 60
|| echo "Failed"
paul@1039 61
paul@1039 62
# Present the request to the resource.
paul@1039 63
paul@1039 64
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR \
paul@1039 65
| tee out1r.tmp \
paul@1039 66
| "$SHOWMAIL" \
paul@1039 67
> out1.tmp
paul@1039 68
paul@1039 69
   grep -q 'METHOD:REPLY' out1.tmp \
paul@1039 70
&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out1.tmp \
paul@1039 71
&& echo "Success" \
paul@1039 72
|| echo "Failed"
paul@1039 73
paul@1039 74
   [ -e "$FBFILE1" ] \
paul@1039 75
&& grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE1" \
paul@1039 76
&& echo "Success" \
paul@1039 77
|| echo "Failed"
paul@1039 78
paul@1039 79
# Check the quota (event is confirmed).
paul@1039 80
paul@1039 81
   [ -e "$JOURNALFILE" ] \
paul@1039 82
&& grep -q "event21@example.com" "$JOURNALFILE" \
paul@1039 83
&& echo "Success" \
paul@1039 84
|| echo "Failed"
paul@1039 85
paul@1039 86
# Attempt to schedule another event.
paul@1039 87
paul@1039 88
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR
paul@1039 89
paul@1039 90
   grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBSENDERFILE" \
paul@1039 91
&& echo "Success" \
paul@1039 92
|| echo "Failed"
paul@1039 93
paul@1039 94
# Present the request to the resource.
paul@1039 95
paul@1039 96
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \
paul@1039 97
| tee out2r.tmp \
paul@1039 98
| "$SHOWMAIL" \
paul@1039 99
> out2.tmp
paul@1039 100
paul@1039 101
   grep -q 'METHOD:REPLY' out2.tmp \
paul@1039 102
&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out2.tmp \
paul@1039 103
&& echo "Success" \
paul@1039 104
|| echo "Failed"
paul@1039 105
paul@1039 106
   ! [ -e "$FBFILE2" ] \
paul@1039 107
|| ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBFILE2" \
paul@1039 108
&& echo "Success" \
paul@1039 109
|| echo "Failed"
paul@1039 110
paul@1039 111
# Check the quota (event is not confirmed).
paul@1039 112
paul@1039 113
   [ -e "$JOURNALFILE" ] \
paul@1039 114
&& grep -q "event21@example.com" "$JOURNALFILE" \
paul@1039 115
&& ! grep -q "event22@example.com" "$JOURNALFILE" \
paul@1039 116
&& echo "Success" \
paul@1039 117
|| echo "Failed"
paul@1039 118
paul@1039 119
# Increase the quota.
paul@1039 120
paul@1046 121
echo '* PT2H' > "$JOURNAL/$QUOTA/limits"
paul@1039 122
paul@1039 123
# Attempt to schedule the event again.
paul@1039 124
paul@1039 125
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR
paul@1039 126
paul@1039 127
   grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBSENDERFILE" \
paul@1039 128
&& echo "Success" \
paul@1039 129
|| echo "Failed"
paul@1039 130
paul@1039 131
# Present the request to the resource.
paul@1039 132
paul@1039 133
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \
paul@1039 134
| tee out3r.tmp \
paul@1039 135
| "$SHOWMAIL" \
paul@1039 136
> out3.tmp
paul@1039 137
paul@1039 138
   grep -q 'METHOD:REPLY' out3.tmp \
paul@1039 139
&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out3.tmp \
paul@1039 140
&& echo "Success" \
paul@1039 141
|| echo "Failed"
paul@1039 142
paul@1039 143
   [ -e "$FBFILE2" ] \
paul@1039 144
&& grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBFILE2" \
paul@1039 145
&& echo "Success" \
paul@1039 146
|| echo "Failed"
paul@1039 147
paul@1039 148
# Check the quota (event is confirmed).
paul@1039 149
paul@1039 150
   [ -e "$JOURNALFILE" ] \
paul@1039 151
&& grep -q "event21@example.com" "$JOURNALFILE" \
paul@1039 152
&& grep -q "event22@example.com" "$JOURNALFILE" \
paul@1039 153
&& echo "Success" \
paul@1039 154
|| echo "Failed"
paul@1039 155
paul@1039 156
# Cancel the first event.
paul@1039 157
paul@1039 158
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-cancel-car.txt" 2>> $ERROR
paul@1039 159
paul@1039 160
   ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
paul@1039 161
&& echo "Success" \
paul@1039 162
|| echo "Failed"
paul@1039 163
paul@1039 164
# Present the request to the resource.
paul@1039 165
paul@1039 166
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-cancel-car.txt" 2>> $ERROR \
paul@1039 167
| tee out4r.tmp \
paul@1039 168
| "$SHOWMAIL" \
paul@1039 169
> out4.tmp
paul@1039 170
paul@1039 171
   ! grep -q 'METHOD:REPLY' out4.tmp \
paul@1039 172
&& echo "Success" \
paul@1039 173
|| echo "Failed"
paul@1039 174
paul@1039 175
   ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE1" \
paul@1039 176
&& echo "Success" \
paul@1039 177
|| echo "Failed"
paul@1039 178
paul@1039 179
# Check the quota (event is retracted).
paul@1039 180
paul@1039 181
   [ -e "$JOURNALFILE" ] \
paul@1039 182
&& [ `grep "event21@example.com" "$JOURNALFILE" | wc -l` = '2' ] \
paul@1039 183
&& grep -q "event22@example.com" "$JOURNALFILE" \
paul@1039 184
&& echo "Success" \
paul@1039 185
|| echo "Failed"
paul@1039 186
paul@1039 187
# Add collective scheduling tests.
paul@1039 188
paul@1039 189
cat > "$PREFS/$USER1/scheduling_function" <<EOF
paul@1039 190
schedule_in_freebusy
paul@1039 191
schedule_across_quota $QUOTA
paul@1039 192
check_quota $QUOTA
paul@1039 193
EOF
paul@1039 194
cat > "$PREFS/$USER1/confirmation_function" <<EOF
paul@1039 195
add_to_quota_freebusy $QUOTA
paul@1039 196
add_to_quota $QUOTA
paul@1039 197
EOF
paul@1039 198
cat > "$PREFS/$USER1/retraction_function" <<EOF
paul@1039 199
remove_from_quota_freebusy $QUOTA
paul@1039 200
remove_from_quota $QUOTA
paul@1039 201
EOF
paul@1039 202
paul@1039 203
cat > "$PREFS/$USER2/scheduling_function" <<EOF
paul@1039 204
schedule_in_freebusy
paul@1039 205
schedule_across_quota $QUOTA
paul@1039 206
check_quota $QUOTA
paul@1039 207
EOF
paul@1039 208
cat > "$PREFS/$USER2/confirmation_function" <<EOF
paul@1039 209
add_to_quota_freebusy $QUOTA
paul@1039 210
add_to_quota $QUOTA
paul@1039 211
EOF
paul@1039 212
cat > "$PREFS/$USER2/retraction_function" <<EOF
paul@1039 213
remove_from_quota_freebusy $QUOTA
paul@1039 214
remove_from_quota $QUOTA
paul@1039 215
EOF
paul@1039 216
paul@1039 217
# Remind the resource about the second event.
paul@1039 218
paul@1039 219
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \
paul@1039 220
| tee out5r.tmp \
paul@1039 221
| "$SHOWMAIL" \
paul@1039 222
> out5.tmp
paul@1039 223
paul@1039 224
   grep -q 'METHOD:REPLY' out5.tmp \
paul@1039 225
&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out5.tmp \
paul@1039 226
&& echo "Success" \
paul@1039 227
|| echo "Failed"
paul@1039 228
paul@1039 229
   [ -e "$FBFILE2" ] \
paul@1039 230
&& grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBFILE2" \
paul@1039 231
&& echo "Success" \
paul@1039 232
|| echo "Failed"
paul@1039 233
paul@1039 234
# Check the quota (event is still confirmed).
paul@1039 235
paul@1039 236
   [ -e "$JOURNALFILE" ] \
paul@1039 237
&& [ `grep "event21@example.com" "$JOURNALFILE" | wc -l` = '2' ] \
paul@1039 238
&& [ `grep "event22@example.com" "$JOURNALFILE" | wc -l` = '1' ] \
paul@1039 239
&& echo "Success" \
paul@1039 240
|| echo "Failed"
paul@1039 241
paul@1039 242
# Attempt to schedule the first event.
paul@1039 243
paul@1039 244
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR
paul@1039 245
paul@1039 246
   grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
paul@1039 247
&& echo "Success" \
paul@1039 248
|| echo "Failed"
paul@1039 249
paul@1039 250
# Present the request to the resource.
paul@1039 251
paul@1039 252
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR \
paul@1039 253
| tee out6r.tmp \
paul@1039 254
| "$SHOWMAIL" \
paul@1039 255
> out6.tmp
paul@1039 256
paul@1039 257
   grep -q 'METHOD:REPLY' out6.tmp \
paul@1039 258
&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out6.tmp \
paul@1039 259
&& echo "Success" \
paul@1039 260
|| echo "Failed"
paul@1039 261
paul@1039 262
   ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE1" \
paul@1039 263
&& echo "Success" \
paul@1039 264
|| echo "Failed"
paul@1039 265
paul@1039 266
# Check the quota (event is still retracted and not newly confirmed).
paul@1039 267
paul@1039 268
   [ -e "$JOURNALFILE" ] \
paul@1039 269
&& [ `grep "event21@example.com" "$JOURNALFILE" | wc -l` = '2' ] \
paul@1039 270
&& [ `grep "event22@example.com" "$JOURNALFILE" | wc -l` = '1' ] \
paul@1039 271
&& echo "Success" \
paul@1039 272
|| echo "Failed"
paul@1039 273
paul@1039 274
# Attempt to schedule the first event moved earlier.
paul@1039 275
paul@1039 276
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-moved.txt" 2>> $ERROR
paul@1039 277
paul@1039 278
   ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \
paul@1039 279
&& grep -q "^20141126T143000Z${TAB}20141126T153000Z" "$FBSENDERFILE" \
paul@1039 280
&& echo "Success" \
paul@1039 281
|| echo "Failed"
paul@1039 282
paul@1039 283
# Present the request to the resource.
paul@1039 284
paul@1039 285
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-moved.txt" 2>> $ERROR \
paul@1039 286
| tee out7r.tmp \
paul@1039 287
| "$SHOWMAIL" \
paul@1039 288
> out7.tmp
paul@1039 289
paul@1039 290
   grep -q 'METHOD:REPLY' out7.tmp \
paul@1039 291
&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out7.tmp \
paul@1039 292
&& echo "Success" \
paul@1039 293
|| echo "Failed"
paul@1039 294
paul@1039 295
   grep -q "^20141126T143000Z${TAB}20141126T153000Z" "$FBFILE1" \
paul@1039 296
&& echo "Success" \
paul@1039 297
|| echo "Failed"
paul@1039 298
paul@1039 299
# Check the quota (event is newly confirmed).
paul@1039 300
paul@1039 301
   [ -e "$JOURNALFILE" ] \
paul@1039 302
&& [ `grep "event21@example.com" "$JOURNALFILE" | wc -l` = '3' ] \
paul@1039 303
&& [ `grep "event22@example.com" "$JOURNALFILE" | wc -l` = '1' ] \
paul@1039 304
&& echo "Success" \
paul@1039 305
|| echo "Failed"
paul@1047 306
paul@1047 307
# Increase the quota.
paul@1047 308
paul@1047 309
echo '* PT3H' > "$JOURNAL/$QUOTA/limits"
paul@1047 310
paul@1047 311
# Attempt to schedule an event involving both resources.
paul@1047 312
paul@1047 313
"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars.txt" 2>> $ERROR
paul@1047 314
paul@1047 315
   grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBSENDERFILE" \
paul@1047 316
&& echo "Success" \
paul@1047 317
|| echo "Failed"
paul@1047 318
paul@1047 319
# Present the request to both resources.
paul@1047 320
paul@1047 321
  "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars.txt" 2>> $ERROR \
paul@1047 322
| tee out8r.tmp \
paul@1047 323
| "$SHOWMAIL" \
paul@1047 324
> out8.tmp
paul@1047 325
paul@1047 326
# Since the email module used by showmail.py cannot stop after reading a single
paul@1047 327
# message, the second message is obtained.
paul@1047 328
paul@1047 329
  grep -n '^From ' out8r.tmp \
paul@1047 330
| tail -n 1 \
paul@1047 331
| cut -d ':' -f 1 \
paul@1047 332
| xargs -I{} tail -n +'{}' out8r.tmp \
paul@1047 333
| "$SHOWMAIL" \
paul@1047 334
>> out8.tmp
paul@1047 335
paul@1047 336
   grep -q 'METHOD:REPLY' out8.tmp \
paul@1047 337
&& grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out8.tmp \
paul@1047 338
&& grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out8.tmp \
paul@1047 339
&& echo "Success" \
paul@1047 340
|| echo "Failed"
paul@1047 341
paul@1047 342
   ( grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE1" \
paul@1047 343
     && ! grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE2" ) \
paul@1047 344
|| ( ! grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE1" \
paul@1047 345
     && grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE2" ) \
paul@1047 346
&& echo "Success" \
paul@1047 347
|| echo "Failed"
paul@1047 348
paul@1047 349
# Check the quota (event is confirmed, but only for one resource).
paul@1047 350
paul@1047 351
   [ -e "$JOURNALFILE" ] \
paul@1047 352
&& grep -q "event23@example.com" "$JOURNALFILE" \
paul@1047 353
&& echo "Success" \
paul@1047 354
|| echo "Failed"