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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.protocol.jabber;
import java.util.*;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import org.jivesoftware.smack.util.StringUtils;
/**
* Tests multi user chat functionalities.
*
* @author Symphorien Wanko
* @author Valentin Martinet
*/
public class TestOperationSetMultiUserChat2
extends TestCase
{
/**
* logger for <tt>TestOperationSetMultiUserChat2</tt> class
*/
private static final Logger logger =
Logger.getLogger(TestOperationSetMultiUserChat2.class);
/**
* Room name for each test will be testRoomBaseName + roomID
*/
private static String testRoomBaseName = "lmuctestroom";
private static int roomID = 0;
/**
* Provides constants and some utilities method.
*/
private final JabberSlickFixture fixture = new JabberSlickFixture();
private OperationSetMultiUserChat opSetMUC1;
private OperationSetMultiUserChat opSetMUC2;
private OperationSetMultiUserChat opSetMUC3;
private OperationSetPresence opSetPresence1;
private OperationSetPresence opSetPresence2;
private OperationSetPresence opSetPresence3;
/**
* Initializes the test with the specified <tt>name</tt>.
*
* @param name the name of the test to initialize.
*/
public TestOperationSetMultiUserChat2(String name)
{
super(name);
}
/**
* JUnit setup method.
* @throws Exception in case anything goes wrong.
*/
@Override
protected void setUp() throws Exception
{
super.setUp();
fixture.setUp();
Map<String, OperationSet> supportedOperationSets1 =
fixture.provider1.getSupportedOperationSets();
if (supportedOperationSets1 == null
|| (supportedOperationSets1.size() < 1))
{
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
}
//get the operation set presence here.
opSetMUC1 = (OperationSetMultiUserChat)
supportedOperationSets1.get(
OperationSetMultiUserChat.class.getName());
if (opSetMUC1 == null)
{
throw new NullPointerException(
"No implementation for MUC was found");
}
//we also need the presence op set in order to retrieve contacts.
opSetPresence1 = (OperationSetPresence)
supportedOperationSets1.get(OperationSetPresence.class.getName());
//if the op set is null show that we're not happy.
if (opSetPresence1 == null)
{
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
Map<String, OperationSet> supportedOperationSets2 =
fixture.provider2.getSupportedOperationSets();
if (supportedOperationSets2 == null
|| (supportedOperationSets2.size() < 1))
{
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
}
opSetMUC2 = (OperationSetMultiUserChat)
supportedOperationSets2.get(
OperationSetMultiUserChat.class.getName());
if (opSetMUC2 == null)
{
throw new NullPointerException(
"No implementation for MUC was found");
}
opSetPresence2 = (OperationSetPresence)
supportedOperationSets2.get(OperationSetPresence.class.getName());
//if the op set is null show that we're not happy.
if (opSetPresence2 == null)
{
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
Map<String, OperationSet> supportedOperationSets3 =
fixture.provider3.getSupportedOperationSets();
if (supportedOperationSets3 == null
|| (supportedOperationSets3.size() < 1))
{
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
}
opSetMUC3 = (OperationSetMultiUserChat)
supportedOperationSets3.get(
OperationSetMultiUserChat.class.getName());
if (opSetMUC3 == null)
{
throw new NullPointerException(
"No implementation for MUC was found");
}
opSetPresence3 = (OperationSetPresence)
supportedOperationSets3.get(OperationSetPresence.class.getName());
//if the op set is null show that we're not happy.
if (opSetPresence3 == null)
{
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
}
/**
* JUnit teardown method.
* @throws Exception in case anything goes wrong.
*/
@Override
protected void tearDown() throws Exception
{
fixture.tearDown();
super.tearDown();
}
/**
* Create the list to be sure that contacts exchanging messages
* exists in each other lists
* @throws Exception
*/
public void prepareContactList()
throws Exception
{
fixture.clearProvidersLists();
Object o = new Object();
synchronized (o)
{
o.wait(2000);
}
try
{
opSetPresence1.subscribe(fixture.userID2);
}
catch (OperationFailedException ex)
{
// the contact already exist its OK
}
try
{
opSetPresence1.subscribe(fixture.userID3);
}
catch (OperationFailedException ex)
{
// the contact already exist its OK
}
try
{
opSetPresence2.subscribe(fixture.userID1);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
try
{
opSetPresence2.subscribe(fixture.userID3);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
try
{
opSetPresence3.subscribe(fixture.userID1);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
try
{
opSetPresence3.subscribe(fixture.userID2);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
logger.info("will wait till the list prepare is completed");
synchronized (o)
{
o.wait(4000);
}
}
/**
* utiliy method to know if a given nickname is on a
* <tt>ChatRoomMember</tt> list
*
* @param name the name we are looking for
* @param memberList the list where we search
*
* @return true if the name is found, false otherwise
*/
private boolean nameIsOnMemberList(
String name, List<ChatRoomMember> memberList)
{
for (ChatRoomMember member : memberList)
{
if (member.getName().equals(name))
{
return true;
}
}
return false;
}
/**
*
* @return Test a testsuite containing all tests to execute.
*/
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTest(
new TestOperationSetMultiUserChat2("testCreateChatRoom"));
suite.addTest(
new TestOperationSetMultiUserChat2("testJoinRoom"));
suite.addTest(
new TestOperationSetMultiUserChat2("testGetJoinedChatRoom"));
suite.addTest(
new TestOperationSetMultiUserChat2("testFindRoom"));
suite.addTest(
new TestOperationSetMultiUserChat2("testInviteReject"));
suite.addTest(
new TestOperationSetMultiUserChat2("testInviteJoin"));
suite.addTest(
new TestOperationSetMultiUserChat2("testLeave"));
//@todo the following two must be tested, they regulary fail, so we are
//disabling them until fixed.
// suite.addTest(
// new TestOperationSetMultiUserChat2("testNickName"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testRoomSubject"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testConferenceChat"));
suite.addTest(
new TestOperationSetMultiUserChat2("testMemberBan"));
suite.addTest(
new TestOperationSetMultiUserChat2("testMemberKick"));
/*
* Unit tests who belong to users role functionalities are orderly added
* below. They are added in a specific order which match a predefined
* scenario. It's not recommended to change this order, some tests may
* then fail.
*
* Please note:
* - when the room is created, participants are considered (by default)
* as members (not guests).
* - in this test suite, the room will use three participants.
*
* Scenario:
* - testInitialParticipantsRoles: verify participants role in the newly
* created room.
* - testRevokeMembership: administrator/owner of the room revokes
* membership to a participant of the room.
* - testGrantMembership: administrator/owner of the room grants
* membership to the participant of the room who just loses it in the
* previous test.
* - testGrantModerator: administrator/owner of the room grants
* moderator rights to a participant of the room.
* - testRevokeVoice: the new moderator of the room (previous test) will
* revoke voice right to the remaining guest, who will become a silent
* member (the room currently includes the administrator/owner, the
* moderator from the previous test, and it remains a participant).
* - testGrantVoice: moderator will grant voice the user he previously
* revokes voice right.
* - testRevokeModerator: moderator of the room will have his rights
* revoked by the owner/admin of the room.
* - testGrantAdmin: owner/admin of the room grants administrator rights
* to the revoked-moderator (previous test).
* - testGrantOwnership: owner/admin of the room grants the new admin as
* co-owner of the room.
* - testRevokeOwnership: owner/admin of the room revokes ownership to
* his co-owner (granted in previous test).
* - testRevokeAdmin: after having been ownership-revoked, the
* considered member is supposed to be an administrator: here his
* administrative rights are revoked by owner/admin of the room.
*
*/
suite.addTest(
new TestOperationSetMultiUserChat2("testInitialParticipantsRoles"));
//suite.addTest(
// new TestOperationSetMultiUserChat2("testRevokeMembership"));
//suite.addTest(
// new TestOperationSetMultiUserChat2("testGrantMembership"));
suite.addTest(new TestOperationSetMultiUserChat2("testGrantModerator"));
suite.addTest(new TestOperationSetMultiUserChat2("testRevokeVoice"));
suite.addTest(new TestOperationSetMultiUserChat2("testGrantVoice"));
suite.addTest(
new TestOperationSetMultiUserChat2("testRevokeModerator"));
// suite.addTest(new TestOperationSetMultiUserChat2("testGrantAdmin"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testGrantOwnership"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testRevokeOwnership"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testRevokeAdmin"));
return suite;
}
/**
* <tt>testCreateChatRoom</tt> creates a room using
* <tt>OperationSetMultiUserChat#createRoom()</tt>.
* We then look if the room is on the list returned by
* <tt>OperationSetMultiUserChat#getExistingChatRooms()</tt>
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testCreateChatRoom()
throws OperationNotSupportedException,
OperationFailedException
{
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
assertNotNull("createChatRoom returned null", opSet1Room);
/*
Room listing has been disabled on testing server,
so skip checks
// and check if it exists on the server
List<String> existingRooms = opSetMUC1.getExistingChatRooms();
for (String roomName : existingRooms)
{
if (roomName.equals(opSet1Room.getName()))
{
return; // ok the created room is listed on server
}
}
fail("the new created room is not listed on server");
*/
}
/**
* <tt>testJoinRoom</tt> looks if <tt>someRoom.isJoined</tt> will returns
* true for an user after he joins a room with <tt>someRoom.join()</tt>
*
* @throws OperationFailedException
* @throws OperationNotSupportedException
*/
public void testJoinRoom()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
MUCEventCollector opSet1Collector =
new MUCEventCollector(opSetMUC1, MUCEventCollector.EVENT_PRESENCE);
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
opSet1Collector.waitForEvent(10000);
assertEquals("user1 didn't get an event since he joined"
, 1, opSet1Collector.collectedEvents.size());
LocalUserChatRoomPresenceChangeEvent changeEvent =
(LocalUserChatRoomPresenceChangeEvent)
opSet1Collector.collectedEvents.get(0);
assertEquals("the event user1 received after he joined is no " +
"LOCAL_USER_JOINED"
, LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED
, changeEvent.getEventType());
assertTrue(
"we are not in the room we just joined", opSet1Room.isJoined());
assertTrue("user is not listed in the room with his nickname",
nameIsOnMemberList(
opSet1Room.getUserNickname(), opSet1Room.getMembers()));
}
/**
* After a user joins a room, we look if the room is present on the list
* returned by
* <tt>OperationSetMultiUserChat#getCurrentlyJoinedChatRooms</tt>.
*
*/
public void testGetJoinedChatRoom()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
assertTrue(
"we are not in the room we just joined", opSet1Room.isJoined());
// is the joined room list up to date ?
List<ChatRoom> joinedRooms = opSetMUC1.getCurrentlyJoinedChatRooms();
for (ChatRoom room : joinedRooms)
{
if (room.getName().equals(opSet1Room.getName()))
{
return; // ok opSet1Room is on the joined rooms list
}
}
fail("the joined room list does not contains a joined room");
}
/**
* <tt>testFindRoom</tt> will looks for an unexisting room and an existing
* one to see if results are what we expect.
*/
public void testFindRoom()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
ChatRoom foundRoom = null;
/*
//findRoom always returns ChatRoom instance. If it doesn't exists in
//the cache it creates an instance of ChatRoom.
try
{
foundRoom = opSetMUC1.findRoom("WhoCreatedThatRoom");
}
catch (Exception ex)
{
//ok, no one created a room named "WhoCreatedThatRoom"
}
assertNull("wasnt expecting to find the room named " +
"'WhoCreatedThatRoom' on server", foundRoom);
*/
// to find the existing room created with opSetMUC1,
// we will use opSetMUC2 to be sure the room will not be retrieved from
// opSetMUC1 cache
try
{
foundRoom = opSetMUC2.findRoom(testRoomName);
}
catch (Exception ex)
{
logger.warn(ex);
}
assertNotNull("failed to find an existing room on server", foundRoom);
assertEquals(
"the room found is not exactly the one we were looking for"
, opSet1Room.getName(), foundRoom.getName());
}
/**
* user1 send to user2 an invitation which will be rejected.
*/
public void testInviteReject()
throws OperationFailedException,
OperationNotSupportedException
{
MUCEventCollector opSet1Collector =
new MUCEventCollector(opSetMUC1, MUCEventCollector.EVENT_INVITE);
MUCEventCollector opSet2Collector =
new MUCEventCollector(opSetMUC2, MUCEventCollector.EVENT_INVITE);
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
// an invitation user2 must reject
opSet1Room.invite(fixture.userID2, "testInviteReject");
opSet2Collector.waitForEvent(10000);
//now we look if user2 received an event
assertEquals(
"The invitation sent from user1 to user2 has not been received "
, 1, opSet2Collector.collectedEvents.size());
// does the invitation comes from user1 with the correct reason
ChatRoomInvitationReceivedEvent invitationReceivedEvent =
(ChatRoomInvitationReceivedEvent)
opSet2Collector.collectedEvents.get(0);
ChatRoomInvitation invitation = invitationReceivedEvent.getInvitation();
assertEquals("The inviter is not the expected user",
StringUtils.parseBareAddress(fixture.userID1),
StringUtils.parseBareAddress(invitation.getInviter()));
assertEquals("The invitation reason received differs from the one sent"
, "testInviteReject", invitation.getReason());
//user2 reject the invitation as planned
opSetMUC2.rejectInvitation(invitation, invitation.getReason());
opSet1Collector.waitForEvent(10000);
//is user1 aware his invitation has been declined
assertEquals(
"no response received from the invitation sent to user 2"
, 1, opSet1Collector.collectedEvents.size());
//who declined the invitation and why
ChatRoomInvitationRejectedEvent invitationRejectedEvent =
(ChatRoomInvitationRejectedEvent)
opSet1Collector.collectedEvents.get(0);
assertEquals("the invitation has been declined by an unexpected user",
StringUtils.parseBareAddress(fixture.userID2),
StringUtils.parseBareAddress(invitationRejectedEvent.getInvitee()));
assertEquals("the invitation is not declined for the expected reason",
"testInviteReject", invitationRejectedEvent.getReason());
}
/**
* <tt>testInviteJoin</tt> reproduces the following scenario : user1
* invite user2. user2 retrieves the room where he is invited then,
* he joins it.
*/
public void testInviteJoin()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
MUCEventCollector opSet1RoomCollector =
new MUCEventCollector(
opSet1Room, MUCEventCollector.EVENT_PRESENCE);
MUCEventCollector opSet2Collector =
new MUCEventCollector(opSetMUC2, MUCEventCollector.EVENT_INVITE);
opSet1Room.invite(fixture.userID2, "testInviteAccept");
opSet2Collector.waitForEvent(10000);
//make sure the invitation has been received
assertEquals("the invitation has not been received"
, 1, opSet2Collector.collectedEvents.size());
// does the invitation comes from user1 with the correct reason
ChatRoomInvitationReceivedEvent invitationReceivedEvent =
(ChatRoomInvitationReceivedEvent)
opSet2Collector.collectedEvents.get(0);
ChatRoomInvitation invitation = invitationReceivedEvent.getInvitation();
assertEquals("The inviter is not the expected user",
StringUtils.parseBareAddress(fixture.userID1),
StringUtils.parseBareAddress(invitation.getInviter()));
assertEquals("The invitation reason received differs from the one sent"
, "testInviteAccept", invitation.getReason());
//user accept the invitation
ChatRoom opSet2Room = invitation.getTargetChatRoom();
MUCEventCollector opSet2RoomCollector =
new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PRESENCE);
opSet2Collector =
new MUCEventCollector(opSetMUC2, MUCEventCollector.EVENT_PRESENCE);
opSet2Room.join();
opSet2Collector.waitForEvent(10000); // listening for user2 own join
opSet2RoomCollector.waitForEvent(10000); // listening for user1 join
opSet1RoomCollector.waitForEvent(10000); // listening for user2 join
// we know check if both member received events
assertEquals("a room member has not been notified that someone " +
"joined the room"
, 1, opSet1RoomCollector.collectedEvents.size());
assertEquals("a room member has not been notified that someone " +
"joined the room"
, 1, opSet2RoomCollector.collectedEvents.size());
ChatRoomMemberPresenceChangeEvent memberEvent =
(ChatRoomMemberPresenceChangeEvent)
opSet1RoomCollector.collectedEvents.get(0);
assertEquals("user received an event of the wrong type "
, ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED
, memberEvent.getEventType());
assertEquals("the user who joined is not the one who was invited"
, fixture.userID2
, memberEvent.getChatRoomMember().getContactAddress());
assertEquals("there is not exactly two members in the room"
, 2, opSet1Room.getMembersCount());
// is user2 notified of its own join
assertEquals("user hasn't been notified of its own join"
, 1, opSet2Collector.collectedEvents.size());
LocalUserChatRoomPresenceChangeEvent localEvent =
(LocalUserChatRoomPresenceChangeEvent)
opSet2Collector.collectedEvents.get(0);
assertEquals("the event user2 received is not LOCAL_USER_JOINED"
, LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED
, localEvent.getEventType());
// both sides should report the same members number.
// here we use opSet2Room.getMembers().size() rather than
// opSet2Room.getMembersCount() because the last method will not
// be always accurate for a newly joined jabber room (stated in
// the smack lib)
assertEquals("the same room reports different members count " +
"from one side to other"
, opSet1Room.getMembers().size()
, opSet2Room.getMembers().size());
//user2 must be on room members list now
assertTrue("user is not listed in the room with his nickname",
nameIsOnMemberList(
opSet2Room.getUserNickname(), opSet2Room.getMembers()));
//and he must be listed on both sides
assertTrue("user is not listed in the room with his nickname ,from " +
"peer side",
nameIsOnMemberList(
opSet2Room.getUserNickname(), opSet1Room.getMembers()));
}
/**
* In <tt>testJoinLeave</tt>, we join a room then leave it and see if the
* reported <tt>ChatRoom</tt> members are reflecting our actions.
*/
public void testLeave()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
// first be sure to be outside the room
if (opSet2Room.isJoined())
opSet2Room.leave();
assertFalse("user is in a room he left or didnt joined"
, opSet2Room.isJoined());
MUCEventCollector opSet1RoomCollector =
new MUCEventCollector(opSet1Room, MUCEventCollector.EVENT_PRESENCE);
MUCEventCollector opSet2RoomCollector =
new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PRESENCE);
opSet2Room.join();
opSet2RoomCollector.waitForEvent(10000);
opSet1RoomCollector.waitForEvent(10000);
// does users received events since a member joined
assertEquals("a room member has not been notified that someone else " +
"joined the room"
, 1, opSet1RoomCollector.collectedEvents.size());
assertTrue("user failed to join a room", opSet2Room.isJoined());
// checking if the user is listed with the right nickname
assertTrue("user nickname not found in the room after join "
, nameIsOnMemberList(
opSet2Room.getUserNickname(), opSet2Room.getMembers()));
//and we check on the other side
assertTrue("user nickname not found in the room after join, " +
"from peer side"
, nameIsOnMemberList(
opSet2Room.getUserNickname(), opSet1Room.getMembers()));
opSet1RoomCollector.collectedEvents.clear();
// leaving
opSet2Room.leave();
opSet1RoomCollector.waitForEvent(10000);
assertFalse("an user is reported present in a room he left"
, opSet2Room.isJoined());
// the nickname shouldnt be listed anymore
assertFalse("user nickname is still on the room list after he left"
, nameIsOnMemberList(opSet2Room.getUserNickname()
, opSet2Room.getMembers()));
// and the other side
// does user1 received notifcation since user2 left
assertEquals("an user joined and left and a room member missed events "
, 1, opSet1RoomCollector.collectedEvents.size());
ChatRoomMemberPresenceChangeEvent memberEvent =
(ChatRoomMemberPresenceChangeEvent)
opSet1RoomCollector.collectedEvents.get(0);
assertEquals("user received an event of the wrong type "
, ChatRoomMemberPresenceChangeEvent.MEMBER_LEFT
, memberEvent.getEventType());
assertEquals("the user who left is not the expected one"
, fixture.userID2
, memberEvent.getChatRoomMember().getContactAddress());
assertFalse("user nickname is still on the room list after he left, " +
"from the peer side"
, nameIsOnMemberList(opSet2Room.getUserNickname()
, opSet1Room.getMembers()));
}
/**
* In <tt>testNickName</tt>, user nicknames will be changed
* and we will check if changes are well reflected on both user
* sides.
*/
public void testNickName()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
String user1FirstNick = opSet1Room.getUserNickname();
String user1SecondNick = "user1nickchange";
ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
opSet2Room.join();
// checking the nickname from the peer side
assertTrue("user nickname not found by peer "
, nameIsOnMemberList(user1FirstNick, opSet2Room.getMembers()));
MUCEventCollector opSet2RoomCollector =
new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PROPERTY);
// change the nickname
opSet1Room.setUserNickname(user1SecondNick);
assertEquals("failed to change user nickname"
, user1SecondNick, opSet1Room.getUserNickname());
//user should be listed with his new nick name
assertTrue(
"user nickname not found on member list after modification"
, nameIsOnMemberList(user1SecondNick, opSet1Room.getMembers()));
// user2 have to wait for the event
opSet2RoomCollector.waitForEvent(10000);
assertEquals("no event received since a member changed his nick"
, 1, opSet2RoomCollector.collectedEvents.size());
ChatRoomMemberPropertyChangeEvent changeEvent =
(ChatRoomMemberPropertyChangeEvent)
opSet2RoomCollector.collectedEvents.get(0);
assertEquals("the change event doesnt comes from the expected member"
, fixture.userID1
, changeEvent.getSourceChatRoomMember().getContactAddress());
assertTrue("user nickname not found on member list after modification, " +
"from peer side",
nameIsOnMemberList(user1SecondNick, opSet2Room.getMembers()));
//previous nickname should not rest on the list after change
assertFalse(
"both old and new nick are listed in a room after nick change"
, nameIsOnMemberList(user1FirstNick, opSet1Room.getMembers()));
assertFalse(
"both old and new nick are listed in a room after nick change, " +
"from the peer side",
nameIsOnMemberList(user1FirstNick, opSet2Room.getMembers()));
// trying to steal a nickname
try
{
opSet2Room.setUserNickname(user1SecondNick);
}
catch (OperationFailedException ex)
{
// stealing nickname is not allowed by the room
}
if (opSet1Room.getUserNickname().equals(opSet2Room.getUserNickname()))
{
fail(
"different users are holding the same nick in the same room");
}
}
/**
* <tt>testRoomSubject</tt> test changing the room subject.
*/
public void testRoomSubject()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
String oldSubject;
String newSubjet = "bingo";
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
opSet2Room.join();
MUCEventCollector opSet2RoomCollector =
new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PROPERTY);
MUCEventCollector opSet1RoomCollector =
new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PROPERTY);
oldSubject = opSet1Room.getSubject();
opSet1Room.setSubject(newSubjet);
opSet1RoomCollector.waitForEvent(20000);
opSet2RoomCollector.waitForEvent(20000);
assertEquals("user1 didnt received an event for room subject change"
, 1, opSet1RoomCollector.collectedEvents.size());
assertEquals("user2 didnt received an event for room subject change"
, 1, opSet2RoomCollector.collectedEvents.size());
assertEquals("the room subject is not up to date "
, newSubjet, opSet1Room.getSubject());
assertEquals("the room subject is not up to date " +
"from peer side"
, newSubjet, opSet2Room.getSubject());
ChatRoomPropertyChangeEvent changeEvent =
(ChatRoomPropertyChangeEvent)
opSet1RoomCollector.collectedEvents.get(0);
assertEquals("the old subject provided by the change event " +
"is not the good one"
, oldSubject, changeEvent.getOldValue());
assertEquals("the new subject provided by the change event " +
"is not the good one"
, newSubjet, changeEvent.getNewValue());
ChatRoomPropertyChangeEvent peerEvent =
(ChatRoomPropertyChangeEvent)
opSet2RoomCollector.collectedEvents.get(0);
assertEquals("both sides didn't received similar change event ",
changeEvent.getOldValue(), peerEvent.getOldValue());
assertEquals("both sides didn't received similar change event ",
changeEvent.getNewValue(), peerEvent.getNewValue());
}
/**
* Here we test conference messaging : sending, receiving messages and
* corresponding events.
*/
public void testConferenceChat()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
logger.info("--- Start testConferenceChat room:" + testRoomName);
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
opSet2Room.join();
// building and checking the message
String message1 = "lorem ipsum first";
Message opSet1Message = opSet1Room.createMessage(message1);
assertEquals("created message content differ from the one provided "
,message1, opSet1Message.getContent());
MUCEventCollector opSet1RoomCollector = new MUCEventCollector(
opSet1Room, MUCEventCollector.EVENT_MESSAGE, true);
MUCEventCollector opSet2RoomCollector = new MUCEventCollector(
opSet2Room, MUCEventCollector.EVENT_MESSAGE, true);
// ship it
opSet1Room.sendMessage(opSet1Message);
opSet1RoomCollector.waitForEvent(10000);
opSet2RoomCollector.waitForEvent(10000);
// does every member received the message
assertEquals("user1 didn't received an event for message delivery "
, 1, opSet1RoomCollector.collectedEvents.size());
assertEquals("user2 didn't received the message"
, 1, opSet2RoomCollector.collectedEvents.size());
ChatRoomMessageDeliveredEvent deliveryEvent =
(ChatRoomMessageDeliveredEvent)
opSet1RoomCollector.collectedEvents.get(0);
assertEquals("message type is not CONVERSATION_MESSAGE_DELIVERED"
, ChatRoomMessageDeliveredEvent.CONVERSATION_MESSAGE_DELIVERED
, deliveryEvent.getEventType());
assertSame("the message has been delivered to another room instance"
, opSet1Room, deliveryEvent.getSourceChatRoom());
assertEquals(
"delivered message differ from sent message"
, message1, deliveryEvent.getMessage().getContent());
// what happened on user2 side
ChatRoomMessageReceivedEvent messageEvent =
(ChatRoomMessageReceivedEvent)
opSet2RoomCollector.collectedEvents.get(0);
assertEquals("message type is not CONVERSATION_MESSAGE_RECEIVED"
, ChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED
, messageEvent.getEventType());
assertSame("the message comes from another room instance"
, opSet2Room, messageEvent.getSourceChatRoom());
ChatRoomMember member = messageEvent.getSourceChatRoomMember();
assertEquals("message comes from an unexpected user"
, opSet1Room.getUserNickname(), member.getName());
assertEquals(
"received message differ from sent message"
, message1, messageEvent.getMessage().getContent());
logger.info("--- End testConferenceChat room:" + testRoomName);
}
/**
* In <tt>testMemberBan</tt>, a member joins, then he is banned
* and try to join again
*/
public void testMemberBan()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
logger.info("--- Start testMemberBan room:" + testRoomName);
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
MUCEventCollector opSet1RoomCollector =
new MUCEventCollector(
opSet1Room, MUCEventCollector.EVENT_PRESENCE);
ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
opSet2Room.join();
opSet1RoomCollector.waitForEvent(10000);
assertTrue("user2 not on member list after join"
, nameIsOnMemberList(fixture.userID2, opSet1Room.getMembers()));
List<ChatRoomMember> members = opSet1Room.getMembers();
ChatRoomMember memberToBan = null;
for (ChatRoomMember member : members)
if (member.getContactAddress().equals(fixture.userID2))
{
memberToBan = member;
break;
}
if (memberToBan == null)
throw new IllegalStateException("member to ban not found");
opSet1RoomCollector =
new MUCEventCollector(
opSet1Room, MUCEventCollector.EVENT_ROLE);
assertTrue("user2 not in a room he joined "
, opSet2Room.isJoined());
MUCEventCollector opSet2RoomCollector =
new MUCEventCollector(
opSet2Room, MUCEventCollector.EVENT_PRESENCE);
opSet1Room.banParticipant(memberToBan, "testMemberBan");
// when an user is kicked or banned, the smack lib deliver corresponding
// events to remaining room members but nothing to the kicked or banned
// user. altough, if we dont wait some amount of time, the banned user
// could still been reported as joined on his side.
opSet2RoomCollector.waitForEvent(2000);
assertFalse("user2 still in a room after been banned"
, opSet2Room.isJoined());
opSet1RoomCollector.waitForEvent(10000);
assertEquals("user1 didnt received an event for user2 ban"
, 1, opSet1RoomCollector.collectedEvents.size());
assertFalse("user2 still on member list after ban"
, nameIsOnMemberList(fixture.userID2, opSet1Room.getMembers()));
try
{
opSet2Room.join();
}
catch (Exception ex)
{
// user2 has not been only kicked but banned so
// he must not be able to join
}
assertFalse("user2 just joined a room where he is banned"
, opSet2Room.isJoined());
logger.info("--- End testMemberBan room:" + testRoomName);
}
/**
* In <tt>testMemberKick</tt>, a member joins, then he is banned
* and try to join again
*/
public void testMemberKick()
throws OperationFailedException,
OperationNotSupportedException
{
String testRoomName = testRoomBaseName + roomID++;
logger.info("--- Start testMemberKick room:" + testRoomName);
// we create the test room
ChatRoom opSet1Room =
opSetMUC1.createChatRoom(testRoomName, null);
opSet1Room.join();
MUCEventCollector opSet1RoomCollector =
new MUCEventCollector(
opSet1Room, MUCEventCollector.EVENT_PRESENCE);
ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
opSet2Room.join();
opSet1RoomCollector.waitForEvent(10000);
assertTrue("user2 not on member list after join"
, nameIsOnMemberList(fixture.userID2, opSet1Room.getMembers()));
List<ChatRoomMember> members = opSet1Room.getMembers();
ChatRoomMember memberToKick = null;
for (ChatRoomMember member : members)
if (member.getContactAddress().equals(fixture.userID2))
{
memberToKick = member;
break;
}
if (memberToKick == null)
throw new IllegalStateException("member to kick not found");
opSet1RoomCollector =
new MUCEventCollector(
opSet1Room, MUCEventCollector.EVENT_PRESENCE);
assertTrue("user2 not in a room he joined "
, opSet2Room.isJoined());
MUCEventCollector opSet2RoomCollector =
new MUCEventCollector(
opSet2Room, MUCEventCollector.EVENT_PRESENCE);
opSet1Room.kickParticipant(memberToKick, "testMemberKick");
// when an user is kicked or banned, the smack lib deliver corresponding
// events to remaining room members but nothing to the kicked or banned
// user. altough, if we dont wait some amount of time, the banned user
// could stils been reported as joined on his side.
opSet2RoomCollector.waitForEvent(2000);
assertFalse("user2 still in a room after been kicked"
, opSet2Room.isJoined());
opSet1RoomCollector.waitForEvent(10000);
assertEquals("user1 didnt received an event for user2 kick"
, 1, opSet1RoomCollector.collectedEvents.size());
ChatRoomMemberPresenceChangeEvent changeEvent =
(ChatRoomMemberPresenceChangeEvent)
opSet1RoomCollector.collectedEvents.get(0);
assertEquals("the event received by user1 is not "
, ChatRoomMemberPresenceChangeEvent.MEMBER_KICKED
, changeEvent.getEventType());
assertEquals("the kicked member is not the one expected"
, memberToKick.getContactAddress()
, changeEvent.getChatRoomMember().getContactAddress());
assertFalse("user2 still on member list after kick"
, nameIsOnMemberList(fixture.userID2, opSet1Room.getMembers()));
// contrary to a ban, an user can join after been kicked
opSet2Room.join();
assertTrue("user2 can't join after been kicked "
, opSet2Room.isJoined());
opSet1RoomCollector.waitForEvent(10000);
assertTrue("user2 not on list when joining after a kick"
, nameIsOnMemberList(fixture.userID2, opSet1Room.getMembers()));
logger.info("--- End testMemberKick room:" + testRoomName);
}
/**
* Tests participant roles when the room just has been created.
* The member who has created the room should have OWNER role.
* Others participants who are invited to the room should be MEMBER.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testInitialParticipantsRoles()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testInitialParticipantsRoles room:" + roomName);
// We create the test room
ChatRoom roomUser1 = opSetMUC1.createChatRoom(roomName, null);
roomUser1.join();
MUCEventCollector roomUser1Collector =
new MUCEventCollector(roomUser1, MUCEventCollector.EVENT_PRESENCE);
roomUser1Collector.waitForEvent(10000); // wait for user1
// User1 who just created the room is supposed to be the owner:
assertEquals("Unexpected role for user1",
roomUser1.getUserRole(), ChatRoomMemberRole.OWNER);
assertEquals("Unexpected role for user1", roomUser1.getUserRole(),
getRole(fixture.userID1, roomUser1.getMembers(),
roomUser1.getName(), true));
// Both of our peers join the room:
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("Room can't be retrieved on user2's side", roomUser2);
roomUser2.join();
roomUser1Collector.waitForEvent(10000); // wait for user2
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("Room can't be retrieved on user3's side", roomUser2);
roomUser3.join();
roomUser1Collector.waitForEvent(10000); // wait for user3
assertTrue("User2 not on member list after having join the room"
, nameIsOnMemberList(fixture.userID2, roomUser1.getMembers()));
assertTrue("User3 not on member list after having join the room"
, nameIsOnMemberList(fixture.userID3, roomUser1.getMembers()));
List<ChatRoomMember> members = roomUser1.getMembers();
// Three members are supposed to be in the room:
assertEquals("Unexpected members count", 3, members.size());
// We are sure two of these members are our peers (checked before the
// last assertion), now we make sure they are both members:
// (Note that the first element of the list refers to the owner)
assertEquals("The current implementation requires that room's new " +
"comers must have MEMBER role",
ChatRoomMemberRole.MEMBER, getRole(fixture.userID2, members,
roomName, true));
assertEquals("The current implementation requires that room's new " +
"comers must have the MEMBER role",
ChatRoomMemberRole.MEMBER, getRole(fixture.userID3, members,
roomName, true));
logger.info("--- End testInitialParticipantsRoles room:" + roomName);
}
/**
* Search the user in the list by address and return its role.
* @param userID
* @param members
* @param roomName
* @param printDebugInfo
* @return
*/
private ChatRoomMemberRole getRole(String userID,
List<ChatRoomMember> members,
String roomName,
boolean printDebugInfo)
{
if(printDebugInfo)
logger.info("Search in mems of " + roomName + " for " + userID);
ChatRoomMemberRole roleFound = null;
for(int i = 0; i < members.size(); i++)
{
ChatRoomMember mem = members.get(i);
if(mem.getContactAddress().equals(userID))
roleFound = mem.getRole();
if(printDebugInfo)
logger.info("m[" + i + "] "
+ mem.getContactAddress() + " r:" + mem.getRole());
}
if(printDebugInfo)
logger.info("found role: " + roleFound);
return roleFound;
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant membership's role to one
* of our peers (user2).
* Membership means a long-life affiliation to the room, rather than being a
* guest.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantMembership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testGrantMembership room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants user2 member rights:
roomUser1.grantMembership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.GUEST, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MEMBER, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.GUEST, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MEMBER, roleEventUser3.getNewRole());
logger.info("--- End testGrantMembership room:" + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant moderator role to one
* of our peers (user2).
* A moderator is allowed to kick users, grant and revoke voice,
* invite other users, modify room's subject plus all the participants
* privileges.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantModerator()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testGrantModerator room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants user2 moderator rights:
roomUser1.grantModerator(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MODERATOR, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MODERATOR, roleEventUser3.getNewRole());
logger.info("--- End testGrantModerator room:" + roomName);
}
/**
* User2 which is currently moderator in the room for our scenario will
* revoke voice to user3, thanks to his moderator privileges.
*
* We will first check that user3 has become a silent member before making
* sure that he can't send messages through the room.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeVoice()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("---= Start test for RevokeVoice =--- room: " + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("The room can't be retrieved on user2's side", roomUser2);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser2Col = new MUCEventCollector(
roomUser2, MUCEventCollector.EVENT_ROLE);
// User2 (moderator role) revokes voice right to user2 (guest):
roomUser2.revokeVoice(fixture.userID3);
roomUser1Col.waitForEvent(10000);
roomUser2Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user2's side",
1, roomUser2Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser2 =
(ChatRoomMemberRoleChangeEvent) roomUser2Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID3,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User3's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.SILENT_MEMBER, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser2.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID3,
roleEventUser2.getSourceMember().getContactAddress());
assertEquals("User3's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser2.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.SILENT_MEMBER, roleEventUser2.getNewRole());
logger.info("---= End test for RevokeVoice =--- room: " + roomName);
}
/**
* User2 which is currently moderator in the room for our scenario will
* grant voice to user3 (thanks to his moderator privileges) after having
* revoked him it in the previous test of the suite.
*
* We will first check that user3 has become a guest before making
* sure that he can again send messages through the room.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantVoice()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("---= Start test for GrantVoice =--- room: " + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("The room can't be retrieved on user2's side", roomUser2);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser2Col = new MUCEventCollector(
roomUser2, MUCEventCollector.EVENT_ROLE);
// User2 of the room grants voice right to user2:
roomUser2.grantVoice(fixture.userID3);
roomUser1Col.waitForEvent(10000);
roomUser2Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser2Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser2 =
(ChatRoomMemberRoleChangeEvent) roomUser2Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID3,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User3's previous role does not match",
ChatRoomMemberRole.SILENT_MEMBER, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MEMBER, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser2.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID3,
roleEventUser2.getSourceMember().getContactAddress());
assertEquals("User3's previous role does not match",
ChatRoomMemberRole.SILENT_MEMBER, roleEventUser2.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MEMBER, roleEventUser2.getNewRole());
logger.info("---= End test for GrantVoice =--- room: " + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant administrator role to one
* of our peers (user2).
* An administrator is allowed to perform administrative functions such as
* banning users and edit moderator list.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantAdmin()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testGrantAdmin room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser2);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants administrator rights to user2:
roomUser1.grantAdmin(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser3.getNewRole());
logger.info("--- End testGrantAdmin room:" + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant ownership privileges to
* one of our peers (user2).
* An owner is allowed to change defining room features as well as perform
* all administrative functions.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantOwnership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testGrantOwnership room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants ownership privileges to user2:
roomUser1.grantOwnership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.OWNER, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.OWNER, roleEventUser3.getNewRole());
logger.info("--- End testGrantOwnership room:" + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke membership's role to one
* of our peers (user2).
* The considered participant is then supposed to be a guest.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeMembership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testRevokeMembership room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeMembership(fixture.userID2);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MEMBER, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.GUEST, roleEventUser3.getNewRole());
logger.info("--- End testRevokeMembership room:" + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke moderator role to user2.
* The considered participant is then supposed to be a member.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeModerator()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testRevokeModerator room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeModerator(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MODERATOR, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MEMBER, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.MODERATOR, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MEMBER, roleEventUser3.getNewRole());
logger.info("--- End testRevokeModerator room:" + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke administrator role to
* user2.
* The considered participant is then supposed to be a moderator.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeAdmin()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testRevokeAdmin room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeAdmin(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MODERATOR, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.MODERATOR, roleEventUser3.getNewRole());
logger.info("--- End testRevokeAdmin room:" + roomName);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke ownership rights to
* user2.
* The considered participant is then supposed to be an admin.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeOwnership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
logger.info("--- Start testRevokeOwnership room:" + roomName);
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeOwnership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser1.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.OWNER, roleEventUser1.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser1.getNewRole());
assertEquals("Collected event does not belong to the right chatroom",
roomName, StringUtils.parseName(
roleEventUser3.getSourceChatRoom().getName()));
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser3.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
ChatRoomMemberRole.OWNER, roleEventUser3.getPreviousRole());
assertEquals("Unexpected new role",
ChatRoomMemberRole.ADMINISTRATOR, roleEventUser3.getNewRole());
logger.info("--- End testRevokeOwnership room:" + roomName);
}
/**
* Utility class used to collect events received during tests.
*/
class MUCEventCollector
implements ChatRoomInvitationRejectionListener,
ChatRoomInvitationListener,
LocalUserChatRoomPresenceListener,
ChatRoomMemberPresenceListener,
ChatRoomMessageListener,
ChatRoomMemberPropertyChangeListener,
ChatRoomPropertyChangeListener,
ChatRoomMemberRoleListener,
ChatRoomLocalUserRoleListener
{
private final ArrayList<EventObject> collectedEvents
= new ArrayList<EventObject>();
private int waitCount = 0;
@SuppressWarnings("unused")
private final OperationSetMultiUserChat opSet;
@SuppressWarnings("unused")
private final ChatRoom room;
private static final int EVENT_INVITE = 1;
private static final int EVENT_PRESENCE = 2;
private static final int EVENT_MESSAGE = 3;
private static final int EVENT_PROPERTY = 4;
private static final int EVENT_ROLE = 5;
/**
* Should we skip system messages in chat rooms.
*/
private boolean skipSystemMsgs = false;
/**
* Creates an event collector to listen for specific events from
* the given opSet
*
* @param opSet the <tt>OperationSetMultiUserChat> from which we will
* receive events.
* @param eventType indicates the kind of events we are looking for
*/
public MUCEventCollector(
OperationSetMultiUserChat opSet, int eventType)
{
this.opSet = opSet;
room = null;
switch (eventType)
{
case EVENT_INVITE:
opSet.addInvitationListener(this);
opSet.addInvitationRejectionListener(this);
break;
case EVENT_PRESENCE:
opSet.addPresenceListener(this);
break;
default:
throw new IllegalArgumentException(
"invalid event category " + eventType);
}
}
/**
* @param room the room we are listening to.
* @param eventType indicates the kind of events we are looking for
*/
public MUCEventCollector(ChatRoom room, int eventType)
{
this(room, eventType, false);
}
/**
* @param room the room we are listening to.
* @param eventType indicates the kind of events we are looking for
* @param skipSystemMsgs should we skip system messages in chat rooms.
*/
public MUCEventCollector(
ChatRoom room, int eventType, boolean skipSystemMsgs)
{
this.room = room;
this.skipSystemMsgs = skipSystemMsgs;
opSet = null;
switch (eventType)
{
case EVENT_PRESENCE:
room.addMemberPresenceListener(this);
break;
case EVENT_MESSAGE:
room.addMessageListener(this);
break;
case EVENT_PROPERTY:
room.addMemberPropertyChangeListener(this);
room.addPropertyChangeListener(this);
break;
case EVENT_ROLE:
room.addMemberRoleListener(this);
room.addLocalUserRoleListener(this);
break;
default:
throw new IllegalArgumentException(
"invalid event category " + eventType);
}
}
/**
* Blocks until at least one event is received or until waitFor
* miliseconds pass (whichever happens first).
*
* @param waitFor the number of miliseconds that we should be waiting
* for an event before simply bailing out.
*/
public void waitForEvent(long waitFor)
{
logger.trace("Waiting for a MUC Event");
synchronized (this)
{
if (collectedEvents.size() > waitCount)
{
waitCount++;
logger.trace("Event already received. " + collectedEvents);
return;
}
try
{
wait(waitFor);
if (collectedEvents.size() > waitCount)
{
logger.trace("Received a MUC event.");
}
else
{
logger.trace(
"MUC event missed after " + waitFor + "ms.");
}
waitCount++;
}
catch (InterruptedException ex)
{
logger.debug(
"Interrupted while waiting for a MUC event", ex);
}
}
}
/**
* utility method to collect an event
* @param evt the event to collect
*/
private void collectEvent(EventObject evt)
{
synchronized (this)
{
logger.debug(
"Collected evt(" + collectedEvents.size() + ")= " + evt);
collectedEvents.add(evt);
notifyAll();
}
}
public void invitationRejected(
ChatRoomInvitationRejectedEvent evt)
{
collectEvent(evt);
}
public void invitationReceived(
ChatRoomInvitationReceivedEvent evt)
{
collectEvent(evt);
}
public void localUserPresenceChanged(
LocalUserChatRoomPresenceChangeEvent evt)
{
collectEvent(evt);
}
public void memberPresenceChanged(
ChatRoomMemberPresenceChangeEvent evt)
{
collectEvent(evt);
}
public void messageReceived(
ChatRoomMessageReceivedEvent evt)
{
if(skipSystemMsgs && evt.getEventType()
== ChatRoomMessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED)
return;
else
collectEvent(evt);
}
public void messageDelivered(
ChatRoomMessageDeliveredEvent evt)
{
collectEvent(evt);
}
public void messageDeliveryFailed(
ChatRoomMessageDeliveryFailedEvent evt)
{
collectEvent(evt);
}
public void chatRoomPropertyChanged(
ChatRoomMemberPropertyChangeEvent evt)
{
collectEvent(evt);
}
public void chatRoomPropertyChanged(
ChatRoomPropertyChangeEvent evt)
{
collectEvent(evt);
}
public void chatRoomPropertyChangeFailed(
ChatRoomPropertyChangeFailedEvent evt)
{
collectEvent(evt);
}
public void memberRoleChanged(
ChatRoomMemberRoleChangeEvent evt)
{
collectEvent(evt);
}
public void localUserRoleChanged(
ChatRoomLocalUserRoleChangeEvent evt)
{
collectEvent(evt);
}
}
}
|