View Javadoc
1   /*
2    * Copyright (C) 2003-2011 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  
18  package org.exoplatform.social.core.storage;
19  
20  import java.io.InputStream;
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.exoplatform.social.core.identity.model.Identity;
25  import org.exoplatform.social.core.identity.model.Profile;
26  import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
27  import org.exoplatform.social.core.identity.provider.SpaceIdentityProvider;
28  import org.exoplatform.social.core.model.AvatarAttachment;
29  import org.exoplatform.social.core.service.LinkProvider;
30  import org.exoplatform.social.core.space.SpaceFilter;
31  import org.exoplatform.social.core.space.impl.DefaultSpaceApplicationHandler;
32  import org.exoplatform.social.core.space.model.Space;
33  import org.exoplatform.social.core.storage.api.IdentityStorage;
34  import org.exoplatform.social.core.storage.api.SpaceStorage;
35  import org.exoplatform.social.core.storage.impl.StorageUtils;
36  import org.exoplatform.social.core.test.AbstractCoreTest;
37  import org.exoplatform.social.core.test.MaxQueryNumber;
38  import org.exoplatform.social.core.test.QueryNumberTest;
39  
40  /**
41   * Unit Tests for {@link org.exoplatform.social.core.storage.api.SpaceStorage}
42   *
43   * @since Nov 3, 2010
44   */
45  @QueryNumberTest
46  public class SpaceStorageTest extends AbstractCoreTest {
47  
48    private List<Space>  tearDownSpaceList;
49    private List<Identity>  tearDownIdentityList;
50  
51    private SpaceStorage spaceStorage;
52    private IdentityStorage identityStorage;
53  
54    private Identity root;
55    private Identity john;
56    private Identity demo;
57    private Identity tom;
58    private Identity raul;
59    private Identity ghost;
60    private Identity dragon;
61    private Identity register1;
62    private Identity mary;
63    private Identity jame;
64    private Identity paul;
65    private Identity hacker;
66    private Identity newStranger;
67  
68    @Override
69    protected void setUp() throws Exception {
70      super.setUp();
71      spaceStorage = this.getContainer().getComponentInstanceOfType(SpaceStorage.class);
72      identityStorage = this.getContainer().getComponentInstanceOfType(IdentityStorage.class);
73  
74      tearDownSpaceList = new ArrayList<>();
75  
76      root = new Identity("organization", "root");
77      john = new Identity("organization", "john");
78      demo = new Identity("organization", "demo");
79      tom = new Identity("organization", "tom");
80      raul = new Identity("organization", "raul");
81      ghost = new Identity("organization", "ghost");
82      dragon = new Identity("organization", "dragon");
83      register1 = new Identity("organization", "register1");
84      mary = new Identity("organization", "mary");
85      jame = new Identity("organization", "jame");
86      paul = new Identity("organization", "paul");
87      hacker = new Identity("organization", "hacker");
88      newStranger = new Identity("organization", "newStranger");
89  
90      tearDownIdentityList = new ArrayList<>();
91      tearDownIdentityList.add(demo);
92      tearDownIdentityList.add(tom);
93      tearDownIdentityList.add(raul);
94      tearDownIdentityList.add(ghost);
95      tearDownIdentityList.add(dragon);
96      tearDownIdentityList.add(register1);
97      tearDownIdentityList.add(mary);
98      tearDownIdentityList.add(jame);
99      tearDownIdentityList.add(paul);
100     tearDownIdentityList.add(hacker);
101     tearDownIdentityList.add(newStranger);
102 
103     deleteAllIdentities();
104 
105     identityStorage.saveIdentity(demo);
106     identityStorage.saveIdentity(tom);
107     identityStorage.saveIdentity(raul);
108     identityStorage.saveIdentity(ghost);
109     identityStorage.saveIdentity(dragon);
110     identityStorage.saveIdentity(register1);
111     identityStorage.saveIdentity(mary);
112     identityStorage.saveIdentity(jame);
113     identityStorage.saveIdentity(paul);
114     identityStorage.saveIdentity(hacker);
115     identityStorage.saveIdentity(newStranger);
116   }
117 
118   /**
119    * Cleans up.
120    */
121   @Override
122   protected void tearDown() throws Exception {
123     deleteAllIdentities();
124     super.tearDown();
125   }
126 
127   protected void deleteAllIdentities() {
128     for (Identity id : tearDownIdentityList) {
129       try {
130         if(identityStorage.findIdentity(OrganizationIdentityProvider.NAME, id.getRemoteId()) != null) {
131           identityStorage.deleteIdentity(id);
132         }
133       } catch (SpaceStorageException e) {
134         // It is expected on some entries
135       }
136     }
137   }
138 
139   /**
140    * Gets an instance of Space.
141    *
142    * @param number
143    * @return an instance of space
144    */
145   private Space getSpaceInstance(int number) {
146     Space space = new Space();
147     space.setApp("app1,app2");
148     space.setDisplayName("my space " + number);
149     space.setPrettyName(space.getDisplayName());
150     space.setRegistration(Space.OPEN);
151     space.setDescription("add new space " + number);
152     space.setType(DefaultSpaceApplicationHandler.NAME);
153     space.setVisibility(Space.PUBLIC);
154     space.setPriority(Space.INTERMEDIATE_PRIORITY);
155     space.setGroupId("/spaces/space" + number);
156     String[] managers = new String[] {"demo", "tom"};
157     String[] members = new String[] {"raul", "ghost", "dragon"};
158     String[] invitedUsers = new String[] {"register1", "mary"};
159     String[] pendingUsers = new String[] {"jame", "paul", "hacker"};
160     space.setInvitedUsers(invitedUsers);
161     space.setPendingUsers(pendingUsers);
162     space.setManagers(managers);
163     space.setMembers(members);
164     space.setUrl(space.getPrettyName());
165     tearDownSpaceList.add(space);
166     return space;
167   }
168   
169   /**
170    * Gets an instance of Space.
171    *
172    * @param number
173    * @return an instance of space
174    */
175   private Space getSpaceInstance(int number, String visible, String registration, String manager, String...members) {
176     Space space = new Space();
177     space.setApp("app");
178     space.setDisplayName("my space " + number);
179     space.setPrettyName(space.getDisplayName());
180     space.setRegistration(registration);
181     space.setDescription("add new space " + number);
182     space.setType(DefaultSpaceApplicationHandler.NAME);
183     space.setVisibility(visible);
184     space.setPriority(Space.INTERMEDIATE_PRIORITY);
185     space.setGroupId("/spaces/space" + number);
186     String[] managers = new String[] {manager};
187     String[] invitedUsers = new String[] {};
188     String[] pendingUsers = new String[] {};
189     space.setInvitedUsers(invitedUsers);
190     space.setPendingUsers(pendingUsers);
191     space.setManagers(managers);
192     space.setMembers(members);
193     space.setUrl(space.getPrettyName());
194     tearDownSpaceList.add(space);
195     return space;
196   }
197   
198   /**
199    * Gets an instance of Space.
200    *
201    * @param number
202    * @return an instance of space
203    */
204   private Space getSpaceInstanceInvitedMember(int number, String visible, String registration, String[] invitedMember, String manager, String...members) {
205     Space space = new Space();
206     space.setApp("app");
207     space.setDisplayName("my space " + number);
208     space.setPrettyName(space.getDisplayName());
209     space.setRegistration(registration);
210     space.setDescription("add new space " + number);
211     space.setType(DefaultSpaceApplicationHandler.NAME);
212     space.setVisibility(visible);
213     space.setPriority(Space.INTERMEDIATE_PRIORITY);
214     space.setGroupId("/spaces/space" + number);
215     space.setUrl(space.getPrettyName());
216     String[] managers = new String[] {manager};
217     //String[] invitedUsers = new String[] {invitedMember};
218     String[] pendingUsers = new String[] {};
219     space.setInvitedUsers(invitedMember);
220     space.setPendingUsers(pendingUsers);
221     space.setManagers(managers);
222     space.setMembers(members);
223     tearDownSpaceList.add(space);
224     return space;
225   }
226   
227   private List<Space> getSpaceWithRoot(SpaceFilter filter) {
228     if (filter == null) {
229       return spaceStorage.getAllSpaces();
230     } else {
231       return spaceStorage.getSpacesByFilter(filter, 0, 200);
232     }
233   }
234 
235   /**
236    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAllSpaces()}
237    *
238    * @throws Exception
239    */
240   @MaxQueryNumber(1032)
241   public void testGetAllSpaces() throws Exception {
242     int totalSpaces = 10;
243     for (int i = 1; i <= totalSpaces; i++) {
244       Space space = this.getSpaceInstance(i);
245       spaceStorage.saveSpace(space, true);
246       StorageUtils.persist();
247     }
248     assertEquals("spaceStorage.getAllSpaces().size() must return: " + totalSpaces,
249             totalSpaces, spaceStorage.getAllSpaces().size());
250   }
251 
252   /**
253    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getSpaces(long, long)}
254    *
255    * @throws Exception
256    * @since 1.2.0-GA
257    */
258   @MaxQueryNumber(1032)
259   public void testGetSpaces() throws Exception {
260     int totalSpaces = 10;
261     for (int i = 1; i <= totalSpaces; i++) {
262       Space space = this.getSpaceInstance(i);
263       spaceStorage.saveSpace(space, true);
264       StorageUtils.persist();
265     }
266     int offset = 0;
267     int limit = 10;
268     List<Space> spaceListAccess = spaceStorage.getSpaces(offset, limit);
269     assertNotNull("spaceListAccess must not be  null", spaceListAccess);
270     assertEquals("spaceListAccess.size() must be: " + totalSpaces, totalSpaces, spaceListAccess.size());
271 
272     spaceListAccess = spaceStorage.getSpaces(offset, 5);
273     assertNotNull("spaceListAccess must not be  null", spaceListAccess);
274     assertEquals("spaceListAccess.size() must be: " + 5, 5, spaceListAccess.size());
275 
276     spaceListAccess = spaceStorage.getSpaces(offset, 20);
277     assertNotNull("spaceListAccess must not be  null", spaceListAccess);
278     assertEquals("spaceListAccess.size() must be: " + totalSpaces, totalSpaces, spaceListAccess.size());
279   }
280 
281   /**
282    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAllSpacesCount()}
283    *
284    * @throws Exception
285    * @since 1.2.0-GA
286    */
287   @MaxQueryNumber(1006)
288   public void testGetAllSpacesCount() throws Exception {
289     int totalSpaces = 10;
290     for (int i = 1; i <= totalSpaces; i++) {
291       Space space = this.getSpaceInstance(i);
292       spaceStorage.saveSpace(space, true);
293       StorageUtils.persist();
294     }
295     int spacesCount = spaceStorage.getAllSpacesCount();
296     assertEquals("spacesCount must be: ", totalSpaces, spacesCount);
297   }
298 
299   /**
300    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getSpacesByFilter(org.exoplatform.social.core.space.SpaceFilter, long, long)}
301    *
302    * @throws Exception
303    * @since 1.2.0-GA
304    */
305   @MaxQueryNumber(1032)
306   public void testGetSpacesByFilter() throws Exception {
307     int totalSpaces = 10;
308     for (int i = 1; i <= totalSpaces; i++) {
309       Space space = this.getSpaceInstance(i);
310       spaceStorage.saveSpace(space, true);
311       StorageUtils.persist();
312     }
313     List<Space> foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter("add"), 0, 10);
314     assertNotNull("foundSpaces must not be null", foundSpaces);
315     assertEquals("foundSpaces.size() must return: " + totalSpaces, totalSpaces, foundSpaces.size());
316 
317     foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter("my"), 0, 10);
318     assertNotNull("foundSpaces must not be null", foundSpaces);
319     assertEquals("foundSpaces.size() must return: " + totalSpaces, totalSpaces, foundSpaces.size());
320 
321     foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter("my space"), 0, 10);
322     assertNotNull("foundSpaces must not be null", foundSpaces);
323     assertEquals("foundSpaces.size() must return: " + totalSpaces, totalSpaces, foundSpaces.size());
324 
325     foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter("hell gate"), 0, 10);
326     assertNotNull("foundSpaces must not be null", foundSpaces);
327     assertEquals("foundSpaces.size() must return: " + 0, 0, foundSpaces.size());
328 
329     foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter('m'), 0, 10);
330     assertNotNull("foundSpaces must not be null", foundSpaces);
331     assertEquals("foundSpaces.size() must return: " + totalSpaces, totalSpaces, foundSpaces.size());
332 
333     foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter('M'), 0, 10);
334     assertNotNull("foundSpaces must not be null", foundSpaces);
335     assertEquals("foundSpaces.size() must return: " + totalSpaces, totalSpaces, foundSpaces.size());
336 
337     foundSpaces = spaceStorage.getSpacesByFilter(new SpaceFilter('k'), 0, 10);
338     assertNotNull("foundSpaces must not be null", foundSpaces);
339     assertEquals("foundSpaces.size() must return: " + 0, 0, foundSpaces.size());
340   }
341 
342   /**
343    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAllSpacesByFilterCount(org.exoplatform.social.core.space.SpaceFilter)}
344    *
345    * @throws Exception
346    * @since 1.2.0-GA
347    */
348   @MaxQueryNumber(1006)
349   public void testGetAllSpacesByFilterCount() throws Exception {
350     int totalSpaces = 10;
351     for (int i = 1; i <= totalSpaces; i++) {
352       Space space = this.getSpaceInstance(i);
353       spaceStorage.saveSpace(space, true);
354       StorageUtils.persist();
355     }
356     int count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter("add"));
357     assertEquals("count must be: " + totalSpaces, totalSpaces, count);
358 
359     count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter("my"));
360     assertEquals("count must be: " + totalSpaces, totalSpaces, count);
361 
362     count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter("my space"));
363     assertEquals("count must be: " + totalSpaces, totalSpaces, count);
364 
365     count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter("hell gate"));
366     assertEquals("count must be: " + 0, 0, count);
367 
368     count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter('m'));
369     assertEquals("count must be: " + totalSpaces, totalSpaces, count);
370 
371     count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter('M'));
372     assertEquals("count must be: " + totalSpaces, totalSpaces, count);
373 
374     count = spaceStorage.getAllSpacesByFilterCount(new SpaceFilter('k'));
375     assertEquals("count must be: " + 0, 0, count);
376   }
377 
378   /**
379    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAccessibleSpaces(String)}
380    *
381    * @throws Exception
382    * @since 1.2.0-GA
383    */
384   @MaxQueryNumber(1032)
385   public void testGetAccessibleSpaces() throws Exception {
386     int countSpace = 10;
387     Space []listSpace = new Space[10];
388     for (int i = 0; i < countSpace; i ++) {
389       listSpace[i] = this.getSpaceInstance(i);
390       spaceStorage.saveSpace(listSpace[i], true);
391       StorageUtils.persist();
392     }
393     List<Space> accessibleSpaces = spaceStorage.getAccessibleSpaces("demo");
394     assertNotNull("accessibleSpaces must not be  null", accessibleSpaces);
395     assertEquals("accessibleSpaces.size() must return: " + countSpace, countSpace, accessibleSpaces.size());
396   }
397 
398   /**
399    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAccessibleSpacesByFilter(String, org.exoplatform.social.core.space.SpaceFilter, long, long)}
400    *
401    * @throws Exception
402    * @since 1.2.0-GA
403    */
404   @MaxQueryNumber(2026)
405   public void testGetAccessibleSpacesByFilter() throws Exception {
406     int countSpace = 20;
407     Space []listSpace = new Space[countSpace];
408     for (int i = 0; i < countSpace; i ++) {
409       listSpace[i] = this.getSpaceInstance(i);
410       spaceStorage.saveSpace(listSpace[i], true);
411       StorageUtils.persist();
412     }
413     List<Space> accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("demo", new SpaceFilter("my space"), 0, 10);
414     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
415     assertEquals("accessibleSpacesByFilter.size() must return: ", 10, accessibleSpacesByFilter.size());
416 
417     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("tom", new SpaceFilter("my space"), 0, 10);
418     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
419     assertEquals("accessibleSpacesByFilter.size() must return: ", 10, accessibleSpacesByFilter.size());
420 
421     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("ghost", new SpaceFilter("my space"), 0, 10);
422     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
423     assertEquals("accessibleSpacesByFilter.size() must return: ", 10, accessibleSpacesByFilter.size());
424 
425     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("demo", new SpaceFilter("add new"), 0, 10);
426     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
427     assertEquals("accessibleSpacesByFilter.size() must return: ", 10, accessibleSpacesByFilter.size());
428 
429     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("demo", new SpaceFilter('m'), 0, 10);
430     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
431     assertEquals("accessibleSpacesByFilter.size() must return: ", 10, accessibleSpacesByFilter.size());
432 
433     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("demo", new SpaceFilter('M'), 0, 10);
434     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
435     assertEquals("accessibleSpacesByFilter.size() must return: ", 10, accessibleSpacesByFilter.size());
436 
437     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("demo", new SpaceFilter('K'), 0, 10);
438     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
439     assertEquals("accessibleSpacesByFilter.size() must return: ", 0, accessibleSpacesByFilter.size());
440 
441     accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("newperson", new SpaceFilter("my space"), 0, 10);
442     assertNotNull("accessibleSpacesByFilter must not be null", accessibleSpacesByFilter);
443     assertEquals("accessibleSpacesByFilter.size() must return: ", 0, accessibleSpacesByFilter.size());
444   }
445   
446   @MaxQueryNumber(800)
447   public void testGetAccessibleSpacesByFilterApp() throws Exception {
448     Space space = this.getSpaceInstance(1);
449     spaceStorage.saveSpace(space, true);
450     StorageUtils.persist();
451     
452     SpaceFilter filter = new SpaceFilter("my space");
453     filter.setAppId("app1,app2");
454     
455     List<Space> accessibleSpacesByFilter = spaceStorage.getAccessibleSpacesByFilter("demo", filter, 0, 10);
456     assertEquals(1, accessibleSpacesByFilter.size());
457   }
458 
459   /**
460    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAccessibleSpacesByFilterCount(String, org.exoplatform.social.core.space.SpaceFilter)}
461    *
462    * @throws Exception
463    * @since 1.2.0-GA
464    */
465   @MaxQueryNumber(2026)
466   public void testGetAccessibleSpacesByFilterCount() throws Exception {
467     int countSpace = 20;
468     Space []listSpace = new Space[countSpace];
469     for (int i = 0; i < countSpace; i ++) {
470       listSpace[i] = this.getSpaceInstance(i);
471       spaceStorage.saveSpace(listSpace[i], true);
472       StorageUtils.persist();
473     }
474     int accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("demo", new SpaceFilter("my space"));
475     assertEquals("accessibleSpacesByFilterCount must be: ", countSpace, accessibleSpacesByFilterCount);
476 
477     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("tom", new SpaceFilter("my space"));
478     assertEquals("accessibleSpacesByFilterCount must be: ", countSpace, accessibleSpacesByFilterCount);
479 
480     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("tom", new SpaceFilter('m'));
481     assertEquals("accessibleSpacesByFilterCount must be: ", countSpace, accessibleSpacesByFilterCount);
482 
483     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("tom", new SpaceFilter('M'));
484     assertEquals("accessibleSpacesByFilterCount must be: ", countSpace, accessibleSpacesByFilterCount);
485 
486     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("tom", new SpaceFilter('k'));
487     assertEquals("accessibleSpacesByFilterCount must be: ", 0, accessibleSpacesByFilterCount);
488 
489     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("ghost", new SpaceFilter("my space"));
490     assertEquals("accessibleSpacesByFilterCount must be: ", countSpace, accessibleSpacesByFilterCount);
491 
492     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("demo", new SpaceFilter("add new"));
493     assertEquals("accessibleSpacesByFilterCount must be: ", countSpace, accessibleSpacesByFilterCount);
494 
495     accessibleSpacesByFilterCount = spaceStorage.getAccessibleSpacesByFilterCount("newperson", new SpaceFilter("my space"));
496     assertEquals("accessibleSpacesByFilterCount must be: ", 0, accessibleSpacesByFilterCount);
497   }
498 
499   /**
500    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAccessibleSpacesCount(String)}
501    *
502    * @throws Exception
503    * @since 1.2.0-GA
504    */
505   @MaxQueryNumber(1006)
506   public void testgetAccessibleSpacesCount() throws Exception {
507     int countSpace = 10;
508     Space []listSpace = new Space[10];
509     for (int i = 0; i < countSpace; i ++) {
510       listSpace[i] = this.getSpaceInstance(i);
511       spaceStorage.saveSpace(listSpace[i], true);
512       StorageUtils.persist();
513     }
514     int accessibleSpacesCount = spaceStorage.getAccessibleSpacesCount("demo");
515     assertEquals("accessibleSpacesCount mus be: " + countSpace, countSpace, accessibleSpacesCount);
516 
517     accessibleSpacesCount = spaceStorage.getAccessibleSpacesCount("dragon");
518     assertEquals("accessibleSpacesCount must be: " + countSpace, countSpace, accessibleSpacesCount);
519 
520     accessibleSpacesCount = spaceStorage.getAccessibleSpacesCount("nobody");
521     assertEquals("accessibleSpacesCount must be: 0", 0, accessibleSpacesCount);
522   }
523 
524   /**
525    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getAccessibleSpaces(String, long, long)}
526    *
527    * @throws Exception
528    * @since 1.2.0-GA
529    */
530   @MaxQueryNumber(1032)
531   public void testGetAccessibleSpacesWithOffset() throws Exception {
532     int countSpace = 10;
533     Space []listSpace = new Space[10];
534     for (int i = 0; i < countSpace; i ++) {
535       listSpace[i] = this.getSpaceInstance(i);
536       spaceStorage.saveSpace(listSpace[i], true);
537       StorageUtils.persist();
538     }
539     List<Space> accessibleSpaces = spaceStorage.getAccessibleSpaces("demo", 0, 5);
540     assertNotNull("accessibleSpaces must not be  null", accessibleSpaces);
541     assertEquals("accessibleSpaces.size() must return: " + 5, 5, accessibleSpaces.size());
542   }
543 
544   /**
545    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getEditableSpaces(String)}
546    *
547    * @throws Exception
548    * @since 1.2.0-GA
549    */
550   @MaxQueryNumber(1032)
551   public void testGetEditableSpaces () throws Exception {
552     int countSpace = 10;
553     Space []listSpace = new Space[10];
554     for (int i = 0; i < countSpace; i ++) {
555       listSpace[i] = this.getSpaceInstance(i);
556       spaceStorage.saveSpace(listSpace[i], true);
557       StorageUtils.persist();
558     }
559     List<Space> editableSpaces = spaceStorage.getEditableSpaces("demo");
560     assertNotNull("editableSpaces must not be  null", editableSpaces);
561     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
562 
563     editableSpaces = spaceStorage.getEditableSpaces("top");
564     assertNotNull("editableSpaces must not be  null", editableSpaces);
565     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
566 
567     editableSpaces = spaceStorage.getEditableSpaces("dragon");
568     assertNotNull("editableSpaces must not be  null", editableSpaces);
569     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
570   }
571 
572   /**
573    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getEditableSpacesByFilter(String, org.exoplatform.social.core.space.SpaceFilter, long, long)}
574    *
575    * @throws Exception
576    * @since 1.2.0-GA
577    */
578   @MaxQueryNumber(1032)
579   public void testGetEditableSpacesByFilter() throws Exception {
580     int countSpace = 10;
581     Space []listSpace = new Space[10];
582     for (int i = 0; i < countSpace; i ++) {
583       listSpace[i] = this.getSpaceInstance(i);
584       spaceStorage.saveSpace(listSpace[i], true);
585       StorageUtils.persist();
586     }
587     List<Space> editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter("add new"), 0 , 10);
588     assertNotNull("editableSpaces must not be  null", editableSpaces);
589     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
590 
591     editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter("m"), 0 , 10);
592     assertNotNull("editableSpaces must not be  null", editableSpaces);
593     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
594 
595     editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter("M"), 0 , 10);
596     assertNotNull("editableSpaces must not be  null", editableSpaces);
597     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
598 
599     editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter('m'), 0 , 10);
600     assertNotNull("editableSpaces must not be  null", editableSpaces);
601     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
602 
603     editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter('M'), 0 , 10);
604     assertNotNull("editableSpaces must not be  null", editableSpaces);
605     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
606 
607     editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter('K'), 0 , 10);
608     assertNotNull("editableSpaces must not be  null", editableSpaces);
609     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
610 
611     editableSpaces = spaceStorage.getEditableSpacesByFilter("demo", new SpaceFilter("add new"), 0 , 10);
612     assertNotNull("editableSpaces must not be  null", editableSpaces);
613     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
614 
615     editableSpaces = spaceStorage.getEditableSpacesByFilter("top", new SpaceFilter("my space"), 0, 10);
616     assertNotNull("editableSpaces must not be  null", editableSpaces);
617     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
618 
619     editableSpaces = spaceStorage.getEditableSpacesByFilter("dragon", new SpaceFilter("m"), 0, 10);
620     assertNotNull("editableSpaces must not be  null", editableSpaces);
621     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
622 
623     editableSpaces = spaceStorage.getEditableSpacesByFilter("dragon", new SpaceFilter('m'), 0, 10);
624     assertNotNull("editableSpaces must not be  null", editableSpaces);
625     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
626 
627     editableSpaces = spaceStorage.getEditableSpacesByFilter("dragon", new SpaceFilter('M'), 0, 10);
628     assertNotNull("editableSpaces must not be  null", editableSpaces);
629     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
630 
631     editableSpaces = spaceStorage.getEditableSpacesByFilter("dragon", new SpaceFilter('k'), 0, 10);
632     assertNotNull("editableSpaces must not be  null", editableSpaces);
633     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
634   }
635 
636   /**
637    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getEditableSpacesByFilterCount(String, org.exoplatform.social.core.space.SpaceFilter)}
638    *
639    * @throws Exception
640    * @since 1.2.0-GA
641    */
642   @MaxQueryNumber(1006)
643   public void testGetEditableSpacesByFilterCount() throws Exception {
644     int countSpace = 10;
645     Space []listSpace = new Space[10];
646     for (int i = 0; i < countSpace; i ++) {
647       listSpace[i] = this.getSpaceInstance(i);
648       spaceStorage.saveSpace(listSpace[i], true);
649       StorageUtils.persist();
650     }
651     int editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("demo", new SpaceFilter("add new"));
652     assertEquals("editableSpacesCount must be: " + countSpace, countSpace, editableSpacesCount);
653 
654     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("demo", new SpaceFilter("m"));
655     assertEquals("editableSpacesCount must be: " + countSpace, countSpace, editableSpacesCount);
656 
657     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("demo", new SpaceFilter("M"));
658     assertEquals("editableSpacesCount must be: " + countSpace, countSpace, editableSpacesCount);
659 
660     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("demo", new SpaceFilter('m'));
661     assertEquals("editableSpacesCount must be: " + countSpace, countSpace, editableSpacesCount);
662 
663     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("demo", new SpaceFilter('M'));
664     assertEquals("editableSpacesCount must be: " + countSpace, countSpace, editableSpacesCount);
665 
666     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("demo", new SpaceFilter('K'));
667     assertEquals("editableSpacesCount must be: " + 0, 0, editableSpacesCount);
668 
669     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("tom", new SpaceFilter("add new"));
670     assertEquals("editableSpacesCount must be: " + countSpace, countSpace, editableSpacesCount);
671 
672     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("top", new SpaceFilter("my space"));
673     assertEquals("editableSpacesCount must be: " + 0, 0, editableSpacesCount);
674 
675     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("dragon", new SpaceFilter("m"));
676     assertEquals("editableSpacesCount must be: " + 0, 0, editableSpacesCount);
677 
678     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("dragon", new SpaceFilter('m'));
679     assertEquals("editableSpacesCount must be: " + 0, 0, editableSpacesCount);
680 
681     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("dragon", new SpaceFilter('M'));
682     assertEquals("editableSpacesCount must be: " + 0, 0, editableSpacesCount);
683 
684     editableSpacesCount = spaceStorage.getEditableSpacesByFilterCount("dragon", new SpaceFilter('k'));
685     assertEquals("editableSpacesCount must be: " + 0, 0, editableSpacesCount);
686   }
687 
688   /**
689    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getEditableSpaces(String, long, long)}
690    *
691    * @throws Exception
692    * @since 1.2.0-GA
693    */
694   @MaxQueryNumber(1032)
695   public void testGetEditableSpacesWithListAccess() throws Exception {
696     int countSpace = 10;
697     Space []listSpace = new Space[10];
698     for (int i = 0; i < countSpace; i ++) {
699       listSpace[i] = this.getSpaceInstance(i);
700       spaceStorage.saveSpace(listSpace[i], true);
701       StorageUtils.persist();
702     }
703     List<Space> editableSpaces = spaceStorage.getEditableSpaces("demo", 0, countSpace);
704     assertNotNull("editableSpaces must not be  null", editableSpaces);
705     assertEquals("editableSpaces.size() must return: " + countSpace, countSpace, editableSpaces.size());
706 
707     editableSpaces = spaceStorage.getEditableSpaces("top", 0, countSpace);
708     assertNotNull("editableSpaces must not be  null", editableSpaces);
709     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
710 
711     editableSpaces = spaceStorage.getEditableSpaces("dragon", 0, 5);
712     assertNotNull("editableSpaces must not be  null", editableSpaces);
713     assertEquals("editableSpaces.size() must return: " + 0, 0, editableSpaces.size());
714   }
715 
716   /**
717    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getInvitedSpaces(String)}
718    *
719    * @throws Exception
720    * @since 1.2.0-GA
721    */
722   @MaxQueryNumber(1032)
723   public void testGetInvitedSpaces() throws Exception {
724     int countSpace = 10;
725     Space []listSpace = new Space[10];
726     for (int i = 0; i < countSpace; i ++) {
727       listSpace[i] = this.getSpaceInstance(i);
728       spaceStorage.saveSpace(listSpace[i], true);
729       StorageUtils.persist();
730     }
731     List<Space> invitedSpaces = spaceStorage.getInvitedSpaces("register1");
732     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
733     assertEquals("invitedSpaces.size() must return: " + countSpace, countSpace, invitedSpaces.size());
734 
735     invitedSpaces = spaceStorage.getInvitedSpaces("register");
736     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
737     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
738 
739     invitedSpaces = spaceStorage.getInvitedSpaces("mary");
740     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
741     assertEquals("invitedSpaces.size() must return: " + countSpace, countSpace, invitedSpaces.size());
742 
743     invitedSpaces = spaceStorage.getInvitedSpaces("demo");
744     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
745     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
746   }
747 
748   /**
749    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getInvitedSpacesByFilter(String, org.exoplatform.social.core.space.SpaceFilter, long, long)}
750    *
751    * @throws Exception
752    * @since 1.2.0-GA
753    */
754   @MaxQueryNumber(1032)
755   public void testGetInvitedSpacesByFilter() throws Exception {
756     int countSpace = 10;
757     Space []listSpace = new Space[10];
758     for (int i = 0; i < countSpace; i ++) {
759       listSpace[i] = this.getSpaceInstance(i);
760       spaceStorage.saveSpace(listSpace[i], true);
761       StorageUtils.persist();
762     }
763     List<Space> invitedSpaces = spaceStorage.getInvitedSpacesByFilter("register1", new SpaceFilter("add new"), 0, 10);
764     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
765     assertEquals("invitedSpaces.size() must return: " + countSpace, countSpace, invitedSpaces.size());
766 
767     invitedSpaces = spaceStorage.getInvitedSpacesByFilter("register1", new SpaceFilter('m'), 0, 10);
768     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
769     assertEquals("invitedSpaces.size() must return: " + countSpace, countSpace, invitedSpaces.size());
770 
771     invitedSpaces = spaceStorage.getInvitedSpacesByFilter("register1", new SpaceFilter('M'), 0, 10);
772     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
773     assertEquals("invitedSpaces.size() must return: " + countSpace, countSpace, invitedSpaces.size());
774 
775     invitedSpaces = spaceStorage.getInvitedSpacesByFilter("register1", new SpaceFilter('k'), 0, 10);
776     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
777     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
778 
779     invitedSpaces = spaceStorage.getInvitedSpacesByFilter("register", new SpaceFilter("my space "), 0, 10);
780     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
781     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
782 
783     invitedSpaces = spaceStorage.getInvitedSpacesByFilter("mary", new SpaceFilter("add"), 0, 10);
784     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
785     assertEquals("invitedSpaces.size() must return: " + countSpace, countSpace, invitedSpaces.size());
786 
787     invitedSpaces = spaceStorage.getInvitedSpacesByFilter("demo", new SpaceFilter("my"), 0, 10);
788     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
789     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
790   }
791 
792   /**
793    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getInvitedSpacesByFilterCount(String, org.exoplatform.social.core.space.SpaceFilter)}
794    *
795    * @throws Exception
796    * @since 1.2.0-GA
797    */
798   @MaxQueryNumber(1006)
799   public void testGetInvitedSpacesByFilterCount() throws Exception {
800     int countSpace = 10;
801     Space []listSpace = new Space[10];
802     for (int i = 0; i < countSpace; i ++) {
803       listSpace[i] = this.getSpaceInstance(i);
804       spaceStorage.saveSpace(listSpace[i], true);
805       StorageUtils.persist();
806     }
807     int invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("register1", new SpaceFilter("add new"));
808     assertEquals("invitedSpacesCount must be: " + countSpace, countSpace, invitedSpacesCount);
809 
810     invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("register1", new SpaceFilter('m'));
811     assertEquals("invitedSpacesCount must be: " + countSpace, countSpace, invitedSpacesCount);
812 
813     invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("register1", new SpaceFilter('M'));
814     assertEquals("invitedSpacesCount must be: " + countSpace, countSpace, invitedSpacesCount);
815 
816     invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("register1", new SpaceFilter('k'));
817     assertEquals("invitedSpacesCount must be: " + 0, 0, invitedSpacesCount);
818 
819     invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("register", new SpaceFilter("my space "));
820     assertEquals("invitedSpacesCount must be: " + 0, 0, invitedSpacesCount);
821 
822     invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("mary", new SpaceFilter("add"));
823     assertEquals("invitedSpacesCount must be: " + countSpace, countSpace, invitedSpacesCount);
824 
825     invitedSpacesCount = spaceStorage.getInvitedSpacesByFilterCount("demo", new SpaceFilter("my"));
826     assertEquals("invitedSpacesCount must be: " + 0, 0, invitedSpacesCount);
827   }
828 
829   /**
830    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getInvitedSpaces(String, long, long)}
831    *
832    * @throws Exception
833    * @since 1.2.0-GA
834    */
835   @MaxQueryNumber(1032)
836   public void testGetInvitedSpacesWithOffset() throws Exception {
837     int countSpace = 10;
838     Space []listSpace = new Space[10];
839     for (int i = 0; i < countSpace; i ++) {
840       listSpace[i] = this.getSpaceInstance(i);
841       spaceStorage.saveSpace(listSpace[i], true);
842       StorageUtils.persist();
843     }
844     List<Space> invitedSpaces = spaceStorage.getInvitedSpaces("register1", 0, 5);
845     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
846     assertEquals("invitedSpaces.size() must return: " + 5, 5, invitedSpaces.size());
847 
848     invitedSpaces = spaceStorage.getInvitedSpaces("register", 0, 5);
849     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
850     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
851 
852     invitedSpaces = spaceStorage.getInvitedSpaces("mary", 0, 5);
853     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
854     assertEquals("invitedSpaces.size() must return: " + 5, 5, invitedSpaces.size());
855 
856     invitedSpaces = spaceStorage.getInvitedSpaces("demo", 0, 5);
857     assertNotNull("invitedSpaces must not be  null", invitedSpaces);
858     assertEquals("invitedSpaces.size() must return: " + 0, 0, invitedSpaces.size());
859   }
860 
861   /**
862    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getInvitedSpacesCount(String)}
863    *
864    * @throws Exception
865    * @since 1.2.0-GA
866    */
867   @MaxQueryNumber(1032)
868   public void testGetInvitedSpacesCount() throws Exception {
869     int countSpace = 10;
870     Space []listSpace = new Space[10];
871     for (int i = 0; i < countSpace; i ++) {
872       listSpace[i] = this.getSpaceInstance(i);
873       spaceStorage.saveSpace(listSpace[i], true);
874       StorageUtils.persist();
875     }
876     int invitedSpacesCount = spaceStorage.getInvitedSpacesCount("register1");
877     assertEquals("invitedSpacesCount must be: " + countSpace, countSpace, invitedSpacesCount);
878 
879     invitedSpacesCount = spaceStorage.getInvitedSpacesCount("mary");
880     assertEquals("invitedSpacesCount must be: " + countSpace, countSpace, invitedSpacesCount);
881 
882     invitedSpacesCount = spaceStorage.getInvitedSpacesCount("nobody");
883     assertEquals("invitedSpacesCount must be: 0", 0, invitedSpacesCount);
884   }
885 
886   /**
887    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPendingSpaces(String)}
888    *
889    * @throws Exception
890    * @since 1.2.0-GA
891    */
892   @MaxQueryNumber(1032)
893   public void testGetPendingSpaces() throws Exception {
894     int countSpace = 10;
895     Space []listSpace = new Space[10];
896     for (int i = 0; i < countSpace; i ++) {
897       listSpace[i] = this.getSpaceInstance(i);
898       spaceStorage.saveSpace(listSpace[i], true);
899       StorageUtils.persist();
900     }
901     List<Space> pendingSpaces = spaceStorage.getPendingSpaces("hacker");
902     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
903     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
904 
905     pendingSpaces = spaceStorage.getPendingSpaces("hack");
906     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
907     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
908 
909     pendingSpaces = spaceStorage.getPendingSpaces("paul");
910     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
911     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
912 
913     pendingSpaces = spaceStorage.getPendingSpaces("jame");
914     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
915     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
916 
917     pendingSpaces = spaceStorage.getPendingSpaces("victory");
918     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
919     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
920   }
921 
922   /**
923    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPendingSpacesByFilter(String, org.exoplatform.social.core.space.SpaceFilter, long, long)}
924    *
925    * @throws Exception
926    * @since 1.2.0-GA
927    */
928   @MaxQueryNumber(1032)
929   public void testGetPendingSpacesByFilter() throws Exception {
930     int countSpace = 10;
931     Space []listSpace = new Space[10];
932     for (int i = 0; i < countSpace; i ++) {
933       listSpace[i] = this.getSpaceInstance(i);
934       spaceStorage.saveSpace(listSpace[i], true);
935       StorageUtils.persist();
936     }
937     List<Space> pendingSpaces = spaceStorage.getPendingSpacesByFilter("hacker", new SpaceFilter("add new"), 0, 10);
938     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
939     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
940 
941     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hacker", new SpaceFilter('m'), 0, 10);
942     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
943     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
944 
945     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hacker", new SpaceFilter('M'), 0, 10);
946     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
947     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
948 
949     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hacker", new SpaceFilter('k'), 0, 10);
950     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
951     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
952 
953     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hack", new SpaceFilter("my space"), 0, 10);
954     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
955     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
956 
957     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hack", new SpaceFilter('m'), 0, 10);
958     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
959     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
960 
961     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hack", new SpaceFilter('M'), 0, 10);
962     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
963     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
964 
965     pendingSpaces = spaceStorage.getPendingSpacesByFilter("hack", new SpaceFilter('K'), 0, 10);
966     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
967     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
968 
969     pendingSpaces = spaceStorage.getPendingSpacesByFilter("paul", new SpaceFilter("add"), 0, 10);
970     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
971     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
972 
973     pendingSpaces = spaceStorage.getPendingSpacesByFilter("jame", new SpaceFilter("my"), 0, 10);
974     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
975     assertEquals("pendingSpaces.size() must return: " + countSpace, countSpace, pendingSpaces.size());
976 
977     pendingSpaces = spaceStorage.getPendingSpacesByFilter("victory", new SpaceFilter("my space "), 0, 10);
978     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
979     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
980   }
981 
982   /**
983    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPendingSpacesByFilterCount(String, org.exoplatform.social.core.space.SpaceFilter)}
984    *
985    * @throws Exception
986    * @since 1.2.0-GA
987    */
988   @MaxQueryNumber(1032)
989   public void testGetPendingSpacesByFilterCount() throws Exception {
990     int countSpace = 10;
991     Space []listSpace = new Space[10];
992     for (int i = 0; i < countSpace; i ++) {
993       listSpace[i] = this.getSpaceInstance(i);
994       spaceStorage.saveSpace(listSpace[i], true);
995       StorageUtils.persist();
996     }
997     int pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hacker", new SpaceFilter("add new"));
998     assertEquals("pendingSpacesCount must be: " + countSpace, countSpace, pendingSpacesCount);
999 
1000     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hacker", new SpaceFilter('m'));
1001     assertEquals("pendingSpacesCount must be: " + countSpace, countSpace, pendingSpacesCount);
1002 
1003     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hacker", new SpaceFilter('M'));
1004     assertEquals("pendingSpacesCount must be: " + countSpace, countSpace, pendingSpacesCount);
1005 
1006     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hacker", new SpaceFilter('k'));
1007     assertEquals("pendingSpacesCount must be: " + 0, 0, pendingSpacesCount);
1008 
1009     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hack", new SpaceFilter("my space"));
1010     assertEquals("pendingSpacesCount must be: " + 0, 0, pendingSpacesCount);
1011 
1012     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hack", new SpaceFilter('m'));
1013     assertEquals("pendingSpacesCount must be: " + 0, 0, pendingSpacesCount);
1014 
1015     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hack", new SpaceFilter('M'));
1016     assertEquals("pendingSpacesCount must be: " + 0, 0, pendingSpacesCount);
1017 
1018     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("hack", new SpaceFilter('K'));
1019     assertEquals("pendingSpacesCount must be: " + 0, 0, pendingSpacesCount);
1020 
1021     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("paul", new SpaceFilter("add"));
1022     assertEquals("pendingSpacesCount must be: " + countSpace, countSpace, pendingSpacesCount);
1023 
1024     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("jame", new SpaceFilter("my"));
1025     assertEquals("pendingSpacesCount must be: " + countSpace, countSpace, pendingSpacesCount);
1026 
1027     pendingSpacesCount = spaceStorage.getPendingSpacesByFilterCount("victory", new SpaceFilter("my space "));
1028     assertEquals("pendingSpacesCount must be: " + 0, 0, pendingSpacesCount);
1029   }
1030 
1031   /**
1032    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPendingSpaces(String, long, long)}
1033    *
1034    * @throws Exception
1035    * @since 1.2.0-GA
1036    */
1037   @MaxQueryNumber(1032)
1038   public void testGetPendingSpacesWithOffset() throws Exception {
1039     int countSpace = 10;
1040     Space []listSpace = new Space[10];
1041     for (int i = 0; i < countSpace; i ++) {
1042       listSpace[i] = this.getSpaceInstance(i);
1043       spaceStorage.saveSpace(listSpace[i], true);
1044       StorageUtils.persist();
1045     }
1046     List<Space> pendingSpaces = spaceStorage.getPendingSpaces("hacker", 0, 5);
1047     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
1048     assertEquals("pendingSpaces.size() must return: " + 5, 5, pendingSpaces.size());
1049 
1050     pendingSpaces = spaceStorage.getPendingSpaces("paul", 0, 5);
1051     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
1052     assertEquals("pendingSpaces.size() must return: " + 5, 5, pendingSpaces.size());
1053 
1054     pendingSpaces = spaceStorage.getPendingSpaces("jame", 0, 5);
1055     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
1056     assertEquals("pendingSpaces.size() must return: " + 5, 5, pendingSpaces.size());
1057 
1058     pendingSpaces = spaceStorage.getPendingSpaces("victory", 0, 5);
1059     assertNotNull("pendingSpaces must not be  null", pendingSpaces);
1060     assertEquals("pendingSpaces.size() must return: " + 0, 0, pendingSpaces.size());
1061   }
1062 
1063   /**
1064    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPendingSpacesCount(String)}
1065    *
1066    * @throws Exception
1067    * @since 1.2.0-GA
1068    */
1069   @MaxQueryNumber(1032)
1070   public void testGetPendingSpacesCount() throws Exception {
1071     int countSpace = 10;
1072     Space []listSpace = new Space[10];
1073     for (int i = 0; i < countSpace; i ++) {
1074       listSpace[i] = this.getSpaceInstance(i);
1075       spaceStorage.saveSpace(listSpace[i], true);
1076       StorageUtils.persist();
1077     }
1078     int pendingSpaceCount = spaceStorage.getPendingSpacesCount("jame");
1079     assertEquals("pendingSpaceCount must be: " + countSpace, countSpace, pendingSpaceCount);
1080 
1081     pendingSpaceCount = spaceStorage.getPendingSpacesCount("paul");
1082     assertEquals("pendingSpaceCount must be: " + countSpace, countSpace, pendingSpaceCount);
1083 
1084     pendingSpaceCount = spaceStorage.getPendingSpacesCount("hacker");
1085     assertEquals("pendingSpaceCount must be: " + countSpace, countSpace, pendingSpaceCount);
1086 
1087     pendingSpaceCount = spaceStorage.getPendingSpacesCount("nobody");
1088     assertEquals("pendingSpaceCount must be: 0", 0, pendingSpaceCount);
1089   }
1090 
1091   /**
1092    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPublicSpaces(String)}
1093    *
1094    * @throws Exception
1095    * @since 1.2.0-GA
1096    */
1097   @MaxQueryNumber(1006)
1098   public void testGetPublicSpaces() throws Exception {
1099     int countSpace = 10;
1100     Space []listSpace = new Space[10];
1101     for (int i = 0; i < countSpace; i ++) {
1102       listSpace[i] = this.getSpaceInstance(i);
1103       spaceStorage.saveSpace(listSpace[i], true);
1104       StorageUtils.persist();
1105     }
1106     List<Space> publicSpaces = spaceStorage.getPublicSpaces("mary");
1107     assertNotNull("publicSpaces must not be  null", publicSpaces);
1108     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1109 
1110     publicSpaces = spaceStorage.getPublicSpaces("demo");
1111     assertNotNull("publicSpaces must not be  null", publicSpaces);
1112     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1113   }
1114 
1115   /**
1116    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPublicSpacesByFilter(String, org.exoplatform.social.core.space.SpaceFilter, long, long)}
1117    *
1118    * @throws Exception
1119    * @since 1.2.0-GA
1120    */
1121   @MaxQueryNumber(1032)
1122   public void testGetPublicSpacesByFilter() throws Exception {
1123     int countSpace = 10;
1124     Space []listSpace = new Space[10];
1125     for (int i = 0; i < countSpace; i ++) {
1126       listSpace[i] = this.getSpaceInstance(i);
1127       spaceStorage.saveSpace(listSpace[i], true);
1128       StorageUtils.persist();
1129     }
1130     List<Space> publicSpaces = spaceStorage.getPublicSpacesByFilter(mary.getRemoteId(), new SpaceFilter("add new"), 0, 10);
1131     assertNotNull("publicSpaces must not be  null", publicSpaces);
1132     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1133 
1134     publicSpaces = spaceStorage.getPublicSpacesByFilter(mary.getRemoteId(), new SpaceFilter("my space"), 0, 10);
1135     assertNotNull("publicSpaces must not be  null", publicSpaces);
1136     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1137 
1138     publicSpaces = spaceStorage.getPublicSpacesByFilter(mary.getRemoteId(), new SpaceFilter('m'), 0, 10);
1139     assertNotNull("publicSpaces must not be  null", publicSpaces);
1140     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1141 
1142     publicSpaces = spaceStorage.getPublicSpacesByFilter(mary.getRemoteId(), new SpaceFilter('M'), 0, 10);
1143     assertNotNull("publicSpaces must not be  null", publicSpaces);
1144     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1145 
1146     publicSpaces = spaceStorage.getPublicSpacesByFilter(demo.getRemoteId(), new SpaceFilter("my space"), 0, 10);
1147     assertNotNull("publicSpaces must not be  null", publicSpaces);
1148     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1149 
1150     publicSpaces = spaceStorage.getPublicSpacesByFilter(newStranger.getRemoteId(), new SpaceFilter('m'), 0, 10);
1151     assertNotNull("publicSpaces must not be  null", publicSpaces);
1152     assertEquals("publicSpaces.size() must return: " + 10, 10, publicSpaces.size());
1153 
1154     publicSpaces = spaceStorage.getPublicSpacesByFilter(newStranger.getRemoteId(), new SpaceFilter('M'), 0, 10);
1155     assertNotNull("publicSpaces must not be  null", publicSpaces);
1156     assertEquals("publicSpaces.size() must return: " + 10, 10, publicSpaces.size());
1157 
1158     publicSpaces = spaceStorage.getPublicSpacesByFilter(newStranger.getRemoteId(), new SpaceFilter("add new "), 0, 10);
1159     assertNotNull("publicSpaces must not be  null", publicSpaces);
1160     assertEquals("publicSpaces.size() must return: " + 10, 10, publicSpaces.size());
1161 
1162     publicSpaces = spaceStorage.getPublicSpacesByFilter(newStranger.getRemoteId(), new SpaceFilter("my space "), 0, 10);
1163     assertNotNull("publicSpaces must not be  null", publicSpaces);
1164     assertEquals("publicSpaces.size() must return: " + 10, 10, publicSpaces.size());
1165   }
1166 
1167   /**
1168    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPublicSpacesByFilterCount(String, org.exoplatform.social.core.space.SpaceFilter)}
1169    *
1170    * @throws Exception
1171    * @since 1.2.0-GA
1172    */
1173   @MaxQueryNumber(1032)
1174   public void testGetPublicSpacesByFilterCount() throws Exception {
1175     int countSpace = 10;
1176     Space []listSpace = new Space[10];
1177     for (int i = 0; i < countSpace; i ++) {
1178       listSpace[i] = this.getSpaceInstance(i);
1179       spaceStorage.saveSpace(listSpace[i], true);
1180       StorageUtils.persist();
1181     }
1182     int publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("mary", new SpaceFilter("add new"));
1183     assertEquals("publicSpacesByFilterCount must be: " + 0, 0, publicSpacesByFilterCount);
1184 
1185     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("mary", new SpaceFilter("my space"));
1186     assertEquals("publicSpacesByFilterCount must be: " + 0, 0, publicSpacesByFilterCount);
1187 
1188     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("mary", new SpaceFilter('m'));
1189     assertEquals("publicSpacesByFilterCount must be: " + 0, 0, publicSpacesByFilterCount);
1190 
1191     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("mary", new SpaceFilter('M'));
1192     assertEquals("publicSpacesByFilterCount must be: " + 0, 0, publicSpacesByFilterCount);
1193 
1194     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("mary", new SpaceFilter("my space"));
1195     assertEquals("publicSpacesByFilterCount must be: " + 0, 0, publicSpacesByFilterCount);
1196 
1197     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("newstranger", new SpaceFilter('m'));
1198     assertEquals("publicSpacesByFilterCount must be: " + 10, 10, publicSpacesByFilterCount);
1199 
1200     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("newstranger", new SpaceFilter('M'));
1201     assertEquals("publicSpacesByFilterCount must be: " + 10, 10, publicSpacesByFilterCount);
1202 
1203     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("newstranger", new SpaceFilter("add new "));
1204     assertEquals("publicSpacesByFilterCount must be: " + 10, 10, publicSpacesByFilterCount);
1205 
1206     publicSpacesByFilterCount = spaceStorage.getPublicSpacesByFilterCount("newstranger", new SpaceFilter("my space "));
1207     assertEquals("publicSpacesByFilterCount must be: " + 10, 10, publicSpacesByFilterCount);
1208   }
1209 
1210   /**
1211    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPublicSpaces(String, long, long)}
1212    *
1213    * @throws Exception
1214    * @since 1.2.0-GA
1215    */
1216   @MaxQueryNumber(1032)
1217   public void testGetPublicSpacesWithOffset() throws Exception {
1218     int countSpace = 10;
1219     Space []listSpace = new Space[10];
1220     for (int i = 0; i < countSpace; i ++) {
1221       listSpace[i] = this.getSpaceInstance(i);
1222       spaceStorage.saveSpace(listSpace[i], true);
1223       StorageUtils.persist();
1224     }
1225     List<Space> publicSpaces = spaceStorage.getPublicSpaces("mary", 0, 5);
1226     assertNotNull("publicSpaces must not be  null", publicSpaces);
1227     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1228 
1229     publicSpaces = spaceStorage.getPublicSpaces("demo", 0, 5);
1230     assertNotNull("publicSpaces must not be  null", publicSpaces);
1231     assertEquals("publicSpaces.size() must return: " + 0, 0, publicSpaces.size());
1232 
1233     publicSpaces = spaceStorage.getPublicSpaces("headshot", 0, 5);
1234     assertNotNull("publicSpaces must not be  null", publicSpaces);
1235     assertEquals("publicSpaces.size() must return: " + 5, 5, publicSpaces.size());
1236 
1237     publicSpaces = spaceStorage.getPublicSpaces("hellgate", 0, countSpace);
1238     assertNotNull("publicSpaces must not be  null", publicSpaces);
1239     assertEquals("publicSpaces.size() must return: " + countSpace, countSpace, publicSpaces.size());
1240   }
1241 
1242   /**
1243    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getPublicSpacesCount(String)}
1244    *
1245    * @since 1.20.-GA
1246    * @throws Exception
1247    */
1248   @MaxQueryNumber(1006)
1249   public void testGetPublicSpacesCount() throws Exception {
1250     int countSpace = 10;
1251     Space []listSpace = new Space[10];
1252     for (int i = 0; i < countSpace; i ++) {
1253       listSpace[i] = this.getSpaceInstance(i);
1254       spaceStorage.saveSpace(listSpace[i], true);
1255       StorageUtils.persist();
1256     }
1257     int publicSpacesCount = spaceStorage.getPublicSpacesCount("jame");
1258     assertEquals("publicSpacesCount must be: 0", 0, publicSpacesCount);
1259 
1260     publicSpacesCount = spaceStorage.getPublicSpacesCount("paul");
1261     assertEquals("publicSpacesCount must be: 0", 0, publicSpacesCount);
1262 
1263     publicSpacesCount = spaceStorage.getPublicSpacesCount("hacker");
1264     assertEquals("publicSpacesCount must be: 0", 0, publicSpacesCount);
1265 
1266     publicSpacesCount = spaceStorage.getPublicSpacesCount("nobody");
1267     assertEquals("publicSpacesCount must be: " + countSpace, countSpace, publicSpacesCount);
1268   }
1269 
1270   /**
1271    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getMemberSpaces(String)}
1272    *
1273    * @throws Exception
1274    * @since 1.2.0-GA
1275    */
1276   @MaxQueryNumber(1032)
1277   public void testGetMemberSpaces() throws Exception {
1278     int countSpace = 10;
1279     Space []listSpace = new Space[10];
1280     for (int i = 0; i < countSpace; i ++) {
1281       listSpace[i] = this.getSpaceInstance(i);
1282       spaceStorage.saveSpace(listSpace[i], true);
1283       StorageUtils.persist();
1284     }
1285 
1286     List<Space> memberSpaces = spaceStorage.getMemberSpaces("raul");
1287     assertNotNull("memberSpaces must not be  null", memberSpaces);
1288     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1289 
1290     memberSpaces = spaceStorage.getMemberSpaces("ghost");
1291     assertNotNull("memberSpaces must not be  null", memberSpaces);
1292     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1293 
1294     memberSpaces = spaceStorage.getMemberSpaces("dragon");
1295     assertNotNull("memberSpaces must not be  null", memberSpaces);
1296     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1297 
1298     memberSpaces = spaceStorage.getMemberSpaces("demo");
1299     assertNotNull("memberSpaces must not be  null", memberSpaces);
1300     assertEquals("memberSpaces.size() must return: 0", 0, memberSpaces.size());
1301   }
1302 
1303   /**
1304    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getMemberSpacesByFilter(String, org.exoplatform.social.core.space.SpaceFilter, long, long)}
1305    *
1306    * @throws Exception
1307    * @since 1.2.0-GA
1308    */
1309   @MaxQueryNumber(1032)
1310   public void testGetMemberSpacesByFilter() throws Exception {
1311     int countSpace = 10;
1312     Space []listSpace = new Space[10];
1313     for (int i = 0; i < countSpace; i ++) {
1314       listSpace[i] = this.getSpaceInstance(i);
1315       spaceStorage.saveSpace(listSpace[i], true);
1316       StorageUtils.persist();
1317     }
1318 
1319     List<Space> memberSpaces = spaceStorage.getMemberSpacesByFilter("raul", new SpaceFilter("my space"), 0, 10);
1320     assertNotNull("memberSpaces must not be  null", memberSpaces);
1321     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1322 
1323     memberSpaces = spaceStorage.getMemberSpacesByFilter("ghost", new SpaceFilter("add new"), 0, 10);
1324     assertNotNull("memberSpaces must not be  null", memberSpaces);
1325     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1326 
1327     memberSpaces = spaceStorage.getMemberSpacesByFilter("ghost", new SpaceFilter("space"), 0, 10);
1328     assertNotNull("memberSpaces must not be  null", memberSpaces);
1329     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1330 
1331     memberSpaces = spaceStorage.getMemberSpacesByFilter("ghost", new SpaceFilter("new"), 0, 10);
1332     assertNotNull("memberSpaces must not be  null", memberSpaces);
1333     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1334 
1335     memberSpaces = spaceStorage.getMemberSpacesByFilter("ghost", new SpaceFilter('m'), 0, 10);
1336     assertNotNull("memberSpaces must not be  null", memberSpaces);
1337     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1338 
1339     memberSpaces = spaceStorage.getMemberSpacesByFilter("ghost", new SpaceFilter('M'), 0, 10);
1340     assertNotNull("memberSpaces must not be  null", memberSpaces);
1341     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1342 
1343     memberSpaces = spaceStorage.getMemberSpacesByFilter("ghost", new SpaceFilter('K'), 0, 10);
1344     assertNotNull("memberSpaces must not be  null", memberSpaces);
1345     assertEquals("memberSpaces.size() must return: " + 0, 0, memberSpaces.size());
1346 
1347     memberSpaces = spaceStorage.getMemberSpacesByFilter("dragon", new SpaceFilter("add"), 0, 10);
1348     assertNotNull("memberSpaces must not be  null", memberSpaces);
1349     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1350 
1351     memberSpaces = spaceStorage.getMemberSpacesByFilter("demo", new SpaceFilter("space"), 0, 10);
1352     assertNotNull("memberSpaces must not be  null", memberSpaces);
1353     assertEquals("memberSpaces.size() must return: 0", 0, memberSpaces.size());
1354   }
1355 
1356   /**
1357    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getMemberSpacesByFilterCount(String, org.exoplatform.social.core.space.SpaceFilter)}
1358    *
1359    * @throws Exception
1360    * @since 1.2.0-GA
1361    */
1362   @MaxQueryNumber(1032)
1363   public void testGetMemberSpacesByFilterCount() throws Exception {
1364     int countSpace = 10;
1365     Space []listSpace = new Space[10];
1366     for (int i = 0; i < countSpace; i ++) {
1367       listSpace[i] = this.getSpaceInstance(i);
1368       spaceStorage.saveSpace(listSpace[i], true);
1369       StorageUtils.persist();
1370     }
1371 
1372     int memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("raul", new SpaceFilter("my space"));
1373     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1374 
1375     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("ghost", new SpaceFilter("add new"));
1376     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1377 
1378     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("ghost", new SpaceFilter("space"));
1379     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1380 
1381     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("ghost", new SpaceFilter("new"));
1382     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1383 
1384     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("ghost", new SpaceFilter('m'));
1385     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1386 
1387     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("ghost", new SpaceFilter('M'));
1388     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1389 
1390     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("ghost", new SpaceFilter('K'));
1391     assertEquals("memberSpacesCount must be: " + 0, 0, memberSpacesCount);
1392 
1393     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("dragon", new SpaceFilter("add"));
1394     assertEquals("memberSpacesCount must be: " + countSpace, countSpace, memberSpacesCount);
1395 
1396     memberSpacesCount = spaceStorage.getMemberSpacesByFilterCount("demo", new SpaceFilter("space"));
1397     assertEquals("memberSpacesCount must be: 0", 0, memberSpacesCount);
1398   }
1399 
1400   /**
1401    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getMemberSpaces(String, long, long)}
1402    *
1403    * @throws Exception
1404    * @since 1.2.0-GA
1405    */
1406   @MaxQueryNumber(1032)
1407   public void testGetMemberSpacesWithListAccess() throws Exception {
1408     int countSpace = 10;
1409     for (int i = 0; i < countSpace; i++) {
1410       Space space = this.getSpaceInstance(i);
1411       spaceStorage.saveSpace(space, true);
1412       StorageUtils.persist();
1413     }
1414 
1415     List<Space> memberSpaces = spaceStorage.getMemberSpaces("raul", 0, 5);
1416     assertNotNull("memberSpaces must not be  null", memberSpaces);
1417     assertEquals("memberSpaces.size() must return: " + 5, 5, memberSpaces.size());
1418 
1419     memberSpaces = spaceStorage.getMemberSpaces("ghost", 0, countSpace);
1420     assertNotNull("memberSpaces must not be  null", memberSpaces);
1421     assertEquals("memberSpaces.size() must return: " + countSpace, countSpace, memberSpaces.size());
1422 
1423     memberSpaces = spaceStorage.getMemberSpaces("dragon", 0, 6);
1424     assertNotNull("memberSpaces must not be  null", memberSpaces);
1425     assertEquals("memberSpaces.size() must return: " + 6, 6, memberSpaces.size());
1426 
1427     memberSpaces = spaceStorage.getMemberSpaces("demo", 0, countSpace);
1428     assertNotNull("memberSpaces must not be  null", memberSpaces);
1429     assertEquals("memberSpaces.size() must return: 0", 0, memberSpaces.size());
1430   }
1431 
1432   /**
1433    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getSpaceById(String)}
1434    *
1435    * @throws Exception
1436    */
1437   @MaxQueryNumber(111)
1438   public void testGetSpaceById() throws Exception {
1439     int number = 1;
1440     Space space = this.getSpaceInstance(number);
1441 
1442     spaceStorage.saveSpace(space, true);
1443     StorageUtils.persist();
1444 
1445     Space savedSpace = spaceStorage.getSpaceById(space.getId());
1446     assertNotNull("savedSpace must not be null", savedSpace);
1447     assertNotNull("savedSpace.getId() must not be null", savedSpace.getId());
1448     assertNotNull("savedSpace.getApp() must not be null", savedSpace.getApp());
1449     assertEquals("space.getId() must return: " + space.getId(), space.getId(), savedSpace.getId());
1450     assertEquals("space.getPrettyName() must return: " + space.getPrettyName(), space.getPrettyName(), savedSpace.getPrettyName());
1451     assertEquals("space.getRegistration() must return: " + space.getRegistration(), space.getRegistration(), savedSpace.getRegistration());
1452     assertEquals("space.getDescription() must return: " + space.getDescription(), space.getDescription(), savedSpace.getDescription());
1453     assertEquals("space.getType() must return: " + space.getType(), space.getType(), savedSpace.getType());
1454     assertEquals("space.getVisibility() must return: " + space.getVisibility(), space.getVisibility(), savedSpace.getVisibility());
1455     assertEquals("space.getPriority() must return: " + space.getPriority(), space.getPriority(), savedSpace.getPriority());
1456   }
1457 
1458   /**
1459    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getSpaceByGroupId(String)}
1460    *
1461    * @throws Exception
1462    */
1463   @MaxQueryNumber(111)
1464   public void testGetSpaceByGroupId() throws Exception {
1465     Space space = getSpaceInstance(1);
1466     spaceStorage.saveSpace(space, true);
1467     StorageUtils.persist();
1468     Space savedSpace = spaceStorage.getSpaceByGroupId(space.getGroupId());
1469 
1470     assertNotNull("savedSpace must not be null", savedSpace);
1471     assertEquals(space.getId(), savedSpace.getId());
1472 
1473 
1474   }
1475 
1476   /**
1477    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getSpaceByUrl(String)}
1478    *
1479    * @throws Exception
1480    */
1481   @MaxQueryNumber(111)
1482   public void testGetSpaceByUrl() throws Exception {
1483     int number = 1;
1484     Space space = this.getSpaceInstance(number);
1485     space.setUrl("http://fake.com.vn");
1486     spaceStorage.saveSpace(space, true);
1487     StorageUtils.persist();
1488 
1489     // get saved space
1490     Space savedSpace = spaceStorage.getSpaceByUrl(space.getUrl());
1491     assertNotNull("savedSpace must not be null", savedSpace);
1492     assertNotNull("savedSpace.getId() must not be null", savedSpace.getId());
1493     assertEquals("space.getId() must return: " + space.getId(), space.getId(), savedSpace.getId());
1494     assertEquals("space.getName() must return: " + space.getName(),
1495                  space.getName(),
1496                  savedSpace.getName());
1497 
1498     //Show that getName() is the same as getPrettyname
1499     assertTrue("savedSpace.getName().equals(savedSpace.getPrettyName()) must return true",
1500             savedSpace.getName().equals(savedSpace.getPrettyName()));
1501 
1502     assertEquals("space.getRegistration() must return: " + space.getRegistration(),
1503                  space.getRegistration(),
1504                  savedSpace.getRegistration());
1505     assertEquals("space.getDescription() must return: " + space.getDescription(),
1506                  space.getDescription(),
1507                  savedSpace.getDescription());
1508     assertEquals("space.getType() must return: " + space.getType(),
1509                  space.getType(),
1510                  savedSpace.getType());
1511     assertEquals("space.getVisibility() must equal savedSpace.getVisibility() = "
1512         + space.getVisibility(), space.getVisibility(), savedSpace.getVisibility());
1513     assertEquals("space.getPriority() must return: " + space.getPriority(),
1514                  space.getPriority(),
1515                  savedSpace.getPriority());
1516     assertEquals("space.getUrl() must return: " + space.getUrl(),
1517                  space.getUrl(),
1518                  savedSpace.getUrl());
1519   }
1520 
1521   /**
1522    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getSpaceByPrettyName(String)}
1523    *
1524    * @throws Exception
1525    */
1526   @MaxQueryNumber(111)
1527   public void testGetSpaceByPrettyName() throws Exception {
1528     // number for method getSpaceInstance(int number)
1529     int number = 1;
1530     // new space
1531     Space space = this.getSpaceInstance(number);
1532 
1533     // save to space activityStorage
1534     spaceStorage.saveSpace(space, true);
1535     StorageUtils.persist();
1536 
1537     // get space saved by name
1538     Space foundSpaceList = spaceStorage.getSpaceByPrettyName(space.getPrettyName());
1539     assertNotNull("foundSpaceList must not be null", foundSpaceList);
1540     assertNotNull("foundSpaceList.getId() must not be null", foundSpaceList.getId());
1541     assertEquals("space.getId() must return: " + space.getId(),
1542         space.getId(),
1543         foundSpaceList.getId());
1544     assertEquals("space.getPrettyName() must return: " + space.getPrettyName(),
1545                  space.getPrettyName(),
1546                  foundSpaceList.getPrettyName());
1547     assertEquals("space.getRegistration() must return: " + space.getRegistration(),
1548                  space.getRegistration(),
1549                  foundSpaceList.getRegistration());
1550     assertEquals("space.getDescription() must return: " + space.getDescription(),
1551                  space.getDescription(),
1552                  foundSpaceList.getDescription());
1553     assertEquals("space.getType() must return: " + space.getType(),
1554                  space.getType(),
1555                  foundSpaceList.getType());
1556     assertEquals("space.getVisibility() must return: " + space.getVisibility(),
1557                  space.getVisibility(),
1558                  foundSpaceList.getVisibility());
1559     assertEquals("space.getPriority() must return: " + space.getPriority(),
1560                  space.getPriority(),
1561                  foundSpaceList.getPriority());
1562   }
1563 
1564   /**
1565    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#deleteSpace(String)}
1566    *
1567    * @throws Exception
1568    */
1569   @MaxQueryNumber(471)
1570   public void testDeleteSpace() throws Exception {
1571     int number = 1;
1572     Space space = this.getSpaceInstance(number);
1573     spaceStorage.saveSpace(space, true);
1574     StorageUtils.persist();
1575     spaceStorage.deleteSpace(space.getId());
1576   }
1577 
1578   /**
1579    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#saveSpace(org.exoplatform.social.core.space.model.Space, boolean)}
1580    *
1581    * @throws Exception
1582    */
1583   @MaxQueryNumber(171)
1584   public void testSaveSpace() throws Exception {
1585     int number = 1;
1586     Space space = this.getSpaceInstance(number);
1587     spaceStorage.saveSpace(space, true);
1588     assertNotNull("space.getId() must not be null", space.getId());
1589     String newName = "newnamespace";
1590     space.setDisplayName(newName);
1591     space.setPrettyName(space.getDisplayName());
1592     spaceStorage.saveSpace(space, false);
1593     StorageUtils.persist();
1594     assertEquals(newName, spaceStorage.getSpaceById(space.getId()).getName());
1595     assertEquals(newName, space.getName());
1596 
1597     Space got = spaceStorage.getSpaceById(space.getId());
1598     assertEquals(null, got.getAvatarUrl());
1599   }
1600 
1601   /**
1602    * Test {@link SpaceStorage#renameSpace(Space, String)}
1603    *
1604    * @throws Exception
1605    * @since 1.2.8
1606    */
1607   @MaxQueryNumber(560)
1608   public void testRenameSpace() throws Exception {
1609     int number = 1;
1610     Space space = this.getSpaceInstance(number);
1611     spaceStorage.saveSpace(space, true);
1612     assertNotNull("space.getId() must not be null", space.getId());
1613     String newName = "newnamespace";
1614     space.setDisplayName(newName);
1615     space.setPrettyName(space.getDisplayName());
1616     spaceStorage.saveSpace(space, false);
1617     StorageUtils.persist();
1618     assertEquals("spaceStorage.getSpaceById(space.getId()).getName() must return: "
1619         + newName, newName, spaceStorage.getSpaceById(space.getId())
1620                                                                 .getPrettyName());
1621     assertEquals("space.getName() must return: " + newName, newName, space.getPrettyName());
1622 
1623     Space got = spaceStorage.getSpaceById(space.getId());
1624     assertEquals(null, got.getAvatarUrl());
1625     
1626     Identity spaceIdentity = new Identity(SpaceIdentityProvider.NAME, got.getPrettyName());
1627     identityStorage.saveIdentity(spaceIdentity);
1628     tearDownIdentityList.add(spaceIdentity);
1629     
1630     String newDisplayName = "new display name";
1631     spaceStorage.renameSpace(space, newDisplayName);
1632     
1633     got = spaceStorage.getSpaceById(space.getId());
1634     assertEquals(newDisplayName, got.getDisplayName());
1635   }
1636   
1637   /**
1638    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#saveSpace(org.exoplatform.social.core.space.model.Space, boolean)}
1639    *
1640    * @throws Exception
1641    */
1642   @MaxQueryNumber(210)
1643   public void testSaveSpaceAvatar() throws Exception {
1644     int number = 100;
1645     Space space = this.getSpaceInstance(number);
1646     InputStream inputStream = getClass().getResourceAsStream("/eXo-Social.png");
1647     AvatarAttachment avatarAttachment = new AvatarAttachment(null, "avatar", "png", inputStream, null, System.currentTimeMillis());
1648     assertNotNull(avatarAttachment); 
1649     space.setAvatarAttachment(avatarAttachment);
1650     
1651     Identity identity = new Identity(SpaceIdentityProvider.NAME, space.getPrettyName());
1652     Profile profile = new Profile(identity);
1653     identity.setProfile(profile);
1654     profile.setProperty(Profile.AVATAR, avatarAttachment);
1655     identityStorage.saveIdentity(identity);
1656     identityStorage.saveProfile(profile);
1657     
1658     tearDownIdentityList.add(identity);
1659     spaceStorage.saveSpace(space, true);
1660     StorageUtils.persist();
1661 
1662     Space got = spaceStorage.getSpaceByPrettyName(space.getPrettyName());
1663 
1664     assertNotNull(got.getAvatarUrl());
1665     String avatarRandomURL = got.getAvatarUrl();
1666     int indexOfLastupdatedParam = avatarRandomURL.indexOf("/?upd=");
1667     String avatarURL = null;
1668     if(indexOfLastupdatedParam != -1){
1669       avatarURL = avatarRandomURL.substring(0,indexOfLastupdatedParam);
1670     } else {
1671       avatarURL = avatarRandomURL;
1672     }
1673     assertEquals(LinkProvider.escapeJCRSpecialCharacters(
1674             String.format(
1675               "/rest/jcr/repository/portal-test/production/soc:providers/soc:space/soc:%s/soc:profile/soc:avatar",
1676               space.getPrettyName())),
1677               avatarURL);
1678     
1679   }
1680 
1681   /**
1682    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#saveSpace(org.exoplatform.social.core.space.model.Space, boolean)} with isNew is false
1683    *
1684    * @throws Exception
1685    */
1686   @MaxQueryNumber(297)
1687   public void testUpdateSpace() throws Exception {
1688     int number = 1;
1689     Space space = this.getSpaceInstance(number);
1690     InputStream inputStream = getClass().getResourceAsStream("/eXo-Social.png");
1691     AvatarAttachment avatarAttachment = new AvatarAttachment(null, "avatar", "png", inputStream, null, System.currentTimeMillis());
1692     assertNotNull("avatar attachment should not be null", avatarAttachment);
1693     space.setAvatarAttachment(avatarAttachment);
1694     spaceStorage.saveSpace(space, true);
1695     StorageUtils.persist();
1696     
1697     Identity identity = new Identity(SpaceIdentityProvider.NAME, space.getPrettyName());
1698     Profile profile = new Profile(identity);
1699     identity.setProfile(profile);
1700     profile.setProperty(Profile.AVATAR, avatarAttachment);
1701     identityStorage.saveIdentity(identity);
1702     identityStorage.saveProfile(profile);
1703     tearDownIdentityList.add(identity);
1704 
1705     //
1706     Space spaceForUpdate = spaceStorage.getSpaceById(space.getId());
1707     spaceStorage.saveSpace(spaceForUpdate, false);
1708     StorageUtils.persist();
1709 
1710     //
1711     Space got = spaceStorage.getSpaceById(spaceForUpdate.getId());
1712 
1713     assertNotNull("avatar URL should not be null",got.getAvatarUrl());
1714   }
1715   
1716   /**
1717    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getVisibleSpaces(String)}
1718    *
1719    * @throws Exception
1720    * @since 1.2.5-GA
1721    */
1722   @MaxQueryNumber(210)
1723   public void testGetVisibleSpaces() throws Exception {
1724     int countSpace = 10;
1725     Space []listSpace = new Space[10];
1726     
1727     //there are 6 spaces with visible = 'private'
1728     for (int i = 0; i < countSpace; i ++) {
1729     
1730       if (i < 6)
1731          //[0->5] :: there are 6 spaces with visible = 'private'
1732         listSpace[i] = this.getSpaceInstance(i, Space.PRIVATE, Space.OPEN, "demo");
1733       else
1734         //[6->9]:: there are 4 spaces with visible = 'hidden'
1735         listSpace[i] = this.getSpaceInstance(i, Space.HIDDEN, Space.OPEN, "demo");
1736       
1737       spaceStorage.saveSpace(listSpace[i], true);
1738       StorageUtils.persist();
1739     }
1740     
1741     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter = null
1742     {
1743       int countSpace1 = 10;
1744       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", null);
1745       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1746       assertEquals("visibleSpaces() must return: " + countSpace1, countSpace1, visibleAllSpaces.size());
1747     }
1748     
1749     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter configured firstCharacter 'M'
1750     {
1751       int countSpace2 = 10;
1752       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter('M'));
1753       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1754       assertEquals("visibleSpaces() must return: " + countSpace2, countSpace2, visibleAllSpaces.size());
1755     }
1756     
1757     //visible with remoteId = 'demo'  return 0 spaces with SpaceFilter configured firstCharacter 'A'
1758     {
1759       int countSpace3 = 0;
1760       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter('A'));
1761       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1762       assertEquals("visibleSpaces() must return: " + countSpace3, countSpace3, visibleAllSpaces.size());
1763     }
1764     
1765     //visible with remoteId = 'mary'  return 6 spaces with SpaceFilter = null
1766     {
1767       int privateSpace1 = 6;
1768       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", null);
1769       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1770       assertEquals("visibleSpaces() must return: " + privateSpace1, privateSpace1, privateSpaces.size());
1771     }
1772     
1773     //visible with remoteId = 'mary'  return 6 spaces with SpaceFilter configured firstCharacter 'M'
1774     {
1775       int privateSpace2 = 6;
1776       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter('M'));
1777       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1778       assertEquals("visibleSpaces() must return: " + privateSpace2, privateSpace2, privateSpaces.size());
1779     }
1780     
1781     //visible with remoteId = 'mary'  return 0 spaces with SpaceFilter configured firstCharacter 'A'
1782     {
1783       int privateSpace3 = 0;
1784       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter('A'));
1785       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1786       assertEquals("visibleSpaces() must return: " + privateSpace3, privateSpace3, privateSpaces.size());
1787     }
1788   }
1789   
1790   /**
1791    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getVisibleSpaces(String)}
1792    *
1793    * @throws Exception
1794    * @since 1.2.5-GA
1795    */
1796   @MaxQueryNumber(210)
1797   public void testGetVisibleSpacesWithValidate() throws Exception {
1798     int countSpace = 10;
1799     Space []listSpace = new Space[10];
1800     
1801     //there are 6 spaces with visible = 'private'
1802     for (int i = 0; i < countSpace; i ++) {
1803     
1804       if (i < 6)
1805          //[0->5] :: there are 6 spaces with visible = 'private'
1806         listSpace[i] = this.getSpaceInstance(i, Space.PRIVATE, Space.VALIDATION, "demo");
1807       else
1808         //[6->9]:: there are 4 spaces with visible = 'hidden'
1809         listSpace[i] = this.getSpaceInstance(i, Space.HIDDEN, Space.VALIDATION, "demo");
1810       
1811       spaceStorage.saveSpace(listSpace[i], true);
1812       StorageUtils.persist();
1813     }
1814     
1815     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter = null
1816     {
1817       int countSpace1 = 10;
1818       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", null);
1819       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1820       assertEquals("visibleSpaces() must return: " + countSpace1, countSpace1, visibleAllSpaces.size());
1821     }
1822     
1823     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter configured firstCharacter 'M'
1824     {
1825       int countSpace2 = 10;
1826       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter('M'));
1827       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1828       assertEquals("visibleSpaces() must return: " + countSpace2, countSpace2, visibleAllSpaces.size());
1829     }
1830     
1831     //visible with remoteId = 'demo'  return 0 spaces with SpaceFilter configured firstCharacter 'A'
1832     {
1833       int countSpace3 = 0;
1834       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter('A'));
1835       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1836       assertEquals("visibleSpaces() must return: " + countSpace3, countSpace3, visibleAllSpaces.size());
1837     }
1838     
1839     //visible with remoteId = 'mary'  return 6 spaces with SpaceFilter = null
1840     {
1841       int privateSpace1 = 6;
1842       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", null);
1843       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1844       assertEquals("visibleSpaces() must return: " + privateSpace1, privateSpace1, privateSpaces.size());
1845     }
1846     
1847     //visible with remoteId = 'mary'  return 6 spaces with SpaceFilter configured firstCharacter 'M'
1848     {
1849       int privateSpace2 = 6;
1850       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter('M'));
1851       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1852       assertEquals("visibleSpaces() must return: " + privateSpace2, privateSpace2, privateSpaces.size());
1853     }
1854     
1855     //visible with remoteId = 'mary'  return 0 spaces with SpaceFilter configured firstCharacter 'A'
1856     {
1857       int privateSpace3 = 0;
1858       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter('A'));
1859       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1860       assertEquals("visibleSpaces() must return: " + privateSpace3, privateSpace3, privateSpaces.size());
1861     }
1862   }
1863   
1864   /**
1865    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getVisibleSpaces(String)}
1866    *
1867    * @throws Exception
1868    * @since 1.2.5-GA
1869    */
1870   @MaxQueryNumber(210)
1871   public void testGetVisibleSpacesFilterByName() throws Exception {
1872     int countSpace = 10;
1873     Space []listSpace = new Space[10];
1874     
1875     //there are 6 spaces with visible = 'private'
1876     for (int i = 0; i < countSpace; i ++) {
1877     
1878       if (i < 6)
1879          //[0->5] :: there are 6 spaces with visible = 'private'
1880         listSpace[i] = this.getSpaceInstance(i, Space.PRIVATE, Space.OPEN, "demo");
1881       else
1882         //[6->9]:: there are 4 spaces with visible = 'hidden'
1883         listSpace[i] = this.getSpaceInstance(i, Space.HIDDEN, Space.OPEN, "demo");
1884       
1885       spaceStorage.saveSpace(listSpace[i], true);
1886       StorageUtils.persist();
1887     }
1888     
1889     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter = null
1890     {
1891       int countSpace1 = 10;
1892       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", null);
1893       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1894       assertEquals("visibleSpaces() must return: " + countSpace1, countSpace1, visibleAllSpaces.size());
1895     }
1896     
1897     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter configured firstCharacter 'M'
1898     {
1899       int countSpace2 = 10;
1900       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter("my space"));
1901       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1902       assertEquals("visibleSpaces() must return: " + countSpace2, countSpace2, visibleAllSpaces.size());
1903     }
1904     
1905     //visible with remoteId = 'demo'  return 0 spaces with SpaceFilter configured firstCharacter 'A'
1906     {
1907       int countSpace3 = 0;
1908       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter("your space"));
1909       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1910       assertEquals("visibleSpaces() must return: " + countSpace3, countSpace3, visibleAllSpaces.size());
1911     }
1912     
1913     //visible with remoteId = 'mary'  return 6 spaces with SpaceFilter = null
1914     {
1915       int privateSpace1 = 6;
1916       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", null);
1917       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1918       assertEquals("visibleSpaces() must return: " + privateSpace1, privateSpace1, privateSpaces.size());
1919     }
1920     
1921     //visible with remoteId = 'mary'  return 6 spaces with SpaceFilter configured firstCharacter 'M'
1922     {
1923       int privateSpace2 = 6;
1924       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter("my space"));
1925       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1926       assertEquals("visibleSpaces() must return: " + privateSpace2, privateSpace2, privateSpaces.size());
1927     }
1928     
1929     //visible with remoteId = 'mary'  return 0 spaces with SpaceFilter configured firstCharacter 'A'
1930     {
1931       int privateSpace3 = 0;
1932       List<Space> privateSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter("your space"));
1933       assertNotNull("visibleSpaces must not be  null", privateSpaces);
1934       assertEquals("visibleSpaces() must return: " + privateSpace3, privateSpace3, privateSpaces.size());
1935     }
1936   }
1937   
1938   /**
1939    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getVisibleSpaces(String)}
1940    *
1941    * @throws Exception
1942    * @since 1.2.5-GA
1943    */
1944   @MaxQueryNumber(210)
1945   public void testGetVisibleSpacesCloseRegistration() throws Exception {
1946     int countSpace = 10;
1947     Space []listSpace = new Space[10];
1948     
1949     //there are 6 spaces with visible = 'private'
1950     for (int i = 0; i < countSpace; i ++) {
1951     
1952       if (i < 6)
1953          //[0->5] :: there are 6 spaces with visible = 'private'
1954         listSpace[i] = this.getSpaceInstance(i, Space.PRIVATE, Space.CLOSE, "demo");
1955       else
1956         //[6->9]:: there are 4 spaces with visible = 'hidden'
1957         listSpace[i] = this.getSpaceInstance(i, Space.HIDDEN, Space.CLOSE, "demo");
1958       
1959       spaceStorage.saveSpace(listSpace[i], true);
1960       StorageUtils.persist();
1961     }
1962     
1963     //visible with remoteId = 'demo'  return 10 spaces
1964     {
1965       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", null);
1966       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
1967       assertEquals("visibleSpaces() must return: " + countSpace, countSpace, visibleAllSpaces.size());
1968     }
1969     
1970     
1971     
1972     //visible with remoteId = 'mary'  return 6 spaces: can see
1973     {
1974       int registrationCloseSpaceCount = 6;
1975       List<Space> registrationCloseSpaces = spaceStorage.getVisibleSpaces("mary", null);
1976       assertNotNull("registrationCloseSpaces must not be  null", registrationCloseSpaces);
1977       assertEquals("registrationCloseSpaces must return: " + registrationCloseSpaceCount, registrationCloseSpaceCount, registrationCloseSpaces.size());
1978     }
1979   }
1980   
1981   /**
1982    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getVisibleSpaces(String)}
1983    *
1984    * @throws Exception
1985    * @since 1.2.5-GA
1986    */
1987   @MaxQueryNumber(210)
1988   public void testGetVisibleSpacesCloseRegistrationByFilter() throws Exception {
1989     int countSpace = 10;
1990     Space []listSpace = new Space[10];
1991     
1992     //there are 6 spaces with visible = 'private'
1993     for (int i = 0; i < countSpace; i ++) {
1994     
1995       if (i < 6)
1996          //[0->5] :: there are 6 spaces with visible = 'private' and manager = "demo"
1997         listSpace[i] = this.getSpaceInstance(i, Space.PRIVATE, Space.CLOSE, "demo");
1998       else
1999         //[6->9]:: there are 4 spaces with visible = 'hidden'
2000         listSpace[i] = this.getSpaceInstance(i, Space.HIDDEN, Space.CLOSE, "demo");
2001       
2002       spaceStorage.saveSpace(listSpace[i], true);
2003       StorageUtils.persist();
2004     }
2005     
2006     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter configured firstCharacter 'M'
2007     {
2008       int countSpace1 = 10;
2009       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter('M'));
2010       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2011       assertEquals("visibleSpaces() must return: " + countSpace1, countSpace1, visibleAllSpaces.size());
2012     }
2013     
2014     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter configured firstCharacter 'M'
2015     {
2016       
2017       int countSpace2 = 0;
2018       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter('A'));
2019       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2020       assertEquals("visibleSpaces() must return: " + countSpace2, countSpace2, visibleAllSpaces.size());
2021     }
2022     
2023     //visible with remoteId = 'demo'  return 10 spaces with SpaceFilter configured name "my space"
2024     {
2025       
2026       int countSpace3 = 10;
2027       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", new SpaceFilter("my space"));
2028       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2029       assertEquals("visibleSpaces() must return: " + countSpace3, countSpace3, visibleAllSpaces.size());
2030     }
2031     
2032     //visible with remoteId = 'root'  return 10 spaces with SpaceFilter configured name "my space"
2033     {
2034       
2035       int countSpace4 = 10;
2036       List<Space> visibleAllSpaces = getSpaceWithRoot(new SpaceFilter("my space"));
2037       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2038       assertEquals("visibleSpaces() must return: " + countSpace4, countSpace4, visibleAllSpaces.size());
2039     }
2040     
2041    //visible with remoteId = 'root'  return 10 spaces with SpaceFilter is null.
2042     {
2043       
2044       int countSpace5 = 10;
2045       List<Space> visibleAllSpaces = getSpaceWithRoot(null);
2046       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2047       assertEquals("visibleSpaces() must return: " + countSpace5, countSpace5, visibleAllSpaces.size());
2048     }
2049     
2050     //visible with remoteId = 'root'  return 0 spaces with SpaceFilter configured name "my space"
2051     {
2052       
2053       int countSpace6 = 0;
2054       List<Space> visibleAllSpaces = getSpaceWithRoot(new SpaceFilter("your space"));
2055       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2056       assertEquals("visibleSpaces() must return: " + countSpace6, countSpace6, visibleAllSpaces.size());
2057     }
2058     
2059        
2060     //visible with remoteId = 'mary'  return 6 spaces: see although with SpaceFilter configured firstCharacter 'M'
2061     {
2062       int registrationCloseSpaceCount1 = 6;
2063       List<Space> registrationCloseSpaces = spaceStorage.getVisibleSpaces("mary", new SpaceFilter('M'));
2064       assertNotNull("registrationCloseSpaces must not be  null", registrationCloseSpaces);
2065       assertEquals("registrationCloseSpaces must return: " + registrationCloseSpaceCount1, registrationCloseSpaceCount1, registrationCloseSpaces.size());
2066     }
2067     
2068     //visible with remoteId = 'root'  return 10 spaces: see all spaces:: check at SpaceServiceImpl
2069     {
2070       int registrationCloseSpaceCount2 = 10;
2071       List<Space> registrationCloseSpaces1 = spaceStorage.getSpacesByFilter(new SpaceFilter('M'), 0, 200);
2072       assertNotNull("registrationCloseSpaces must not be  null", registrationCloseSpaces1);
2073       assertEquals("registrationCloseSpaces must return: " + registrationCloseSpaceCount2, registrationCloseSpaceCount2, registrationCloseSpaces1.size());
2074     }
2075   }
2076   
2077   /**
2078    * Test {@link org.exoplatform.social.core.storage.SpaceStorage#getVisibleSpaces(String)}
2079    *
2080    * @throws Exception
2081    * @since 1.2.5-GA
2082    */
2083   @MaxQueryNumber(318)
2084   public void testGetVisibleSpacesInvitedMember() throws Exception {
2085     int countSpace = 10;
2086     Space[] listSpace = new Space[10];
2087     
2088     //there are 6 spaces with visible = 'private'
2089     for (int i = 0; i < countSpace; i ++) {
2090     
2091       if (i < 6)
2092          //[0->5] :: there are 6 spaces with visible = 'private'
2093         listSpace[i] = this.getSpaceInstanceInvitedMember(i, Space.PRIVATE, Space.CLOSE, new String[] {"mary", "hacker"}, "demo");
2094       else
2095         //[6->9]:: there are 4 spaces with visible = 'hidden'
2096         listSpace[i] = this.getSpaceInstance(i, Space.HIDDEN, Space.CLOSE, "demo");
2097       
2098       spaceStorage.saveSpace(listSpace[i], true);
2099       StorageUtils.persist();
2100     }
2101     
2102     //visible with remoteId = 'demo'  return 10 spaces
2103     {
2104       List<Space> visibleAllSpaces = spaceStorage.getVisibleSpaces("demo", null);
2105       assertNotNull("visibleSpaces must not be  null", visibleAllSpaces);
2106       assertEquals("visibleSpaces() must return: " + countSpace, countSpace, visibleAllSpaces.size());
2107     }
2108     
2109     //visible with invited = 'mary'  return 6 spaces
2110     {
2111       int invitedSpaceCount1 = 6;
2112       List<Space> invitedSpaces1 = spaceStorage.getVisibleSpaces("mary", null);
2113       assertNotNull("invitedSpaces must not be  null", invitedSpaces1);
2114       assertEquals("invitedSpaces must return: " + invitedSpaceCount1, invitedSpaceCount1, invitedSpaces1.size());
2115     }
2116     
2117     //visible with invited = 'hacker'  return 6 spaces
2118     {
2119       int invitedSpaceCount1 = 6;
2120       List<Space> invitedSpaces1 = spaceStorage.getVisibleSpaces("hacker", null);
2121       assertNotNull("invitedSpaces must not be  null", invitedSpaces1);
2122       assertEquals("invitedSpaces must return: " + invitedSpaceCount1, invitedSpaceCount1, invitedSpaces1.size());
2123     }
2124     
2125     //visible with invited = 'paul'  return 6 spaces
2126     {
2127       int invitedSpaceCount2 = 6;
2128       List<Space> invitedSpaces2 = spaceStorage.getVisibleSpaces("paul", null);
2129       assertNotNull("invitedSpaces must not be  null", invitedSpaces2);
2130       assertEquals("invitedSpaces must return: " + invitedSpaceCount2, invitedSpaceCount2, invitedSpaces2.size());
2131     }
2132   }
2133   
2134   // TODO : test getSpaceByGroupId without result
2135   // TODO : save space with null member[]
2136   // TODO : test space member number
2137   // TODO : test app data
2138   // TODO : test accepte invited / pending
2139 }