imip-agent

Annotated tests/test_resource_invitation_constraints_quota.sh

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