forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...-sakai/src/test/org/sakaiproject/elfinder/sakai/content/ContentSiteVolumeFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.sakaiproject.elfinder.sakai.content; | ||
|
||
import cn.bluejoe.elfinder.service.FsItem; | ||
import cn.bluejoe.elfinder.service.FsVolume; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.sakaiproject.content.api.ContentHostingService; | ||
import org.sakaiproject.elfinder.sakai.SakaiFsService; | ||
import org.sakaiproject.elfinder.sakai.SiteVolume; | ||
import org.sakaiproject.site.api.SiteService; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ContentSiteVolumeFactoryTest { | ||
|
||
@Mock | ||
private ContentHostingService contentHostingService; | ||
|
||
@Mock | ||
private SiteService siteService; | ||
|
||
@Mock | ||
private SakaiFsService service; | ||
|
||
@Mock | ||
private FsItem siteItem; | ||
@Mock | ||
private FsVolume siteVolume; | ||
|
||
private ContentSiteVolumeFactory factory; | ||
|
||
@Before | ||
public void setUp() { | ||
|
||
factory = new ContentSiteVolumeFactory(); | ||
factory.setSiteService(siteService); | ||
factory.setContentHostingService(contentHostingService); | ||
|
||
} | ||
|
||
@Test | ||
public void testGetParent() { | ||
|
||
Mockito.when(contentHostingService.getSiteCollection("siteId")).thenReturn("/group/siteId"); | ||
Mockito.when(contentHostingService.getContainingCollectionId("/group/siteId/example")).thenReturn("/group/siteId"); | ||
Mockito.when(contentHostingService.getContainingCollectionId("/group/siteId")).thenReturn("/group"); | ||
Mockito.when(contentHostingService.getContainingCollectionId("/group")).thenReturn(""); | ||
Mockito.when(service.getSiteVolume("siteId")).thenReturn(siteVolume); | ||
Mockito.when(siteVolume.getRoot()).thenReturn(siteItem); | ||
|
||
SiteVolume volume = factory.getVolume(service, "siteId"); | ||
|
||
// This is for a path inside the same site | ||
FsItem fsItem = volume.fromPath("/group/siteId/example"); | ||
Assert.assertNotNull(fsItem); | ||
FsItem parent = volume.getParent(fsItem); | ||
Assert.assertNotNull(parent); | ||
FsItem siteParent = volume.getParent(parent); | ||
Assert.assertNotNull(siteParent); | ||
|
||
Assert.assertEquals("Should get site back", siteItem, siteParent); | ||
} | ||
|
||
@Test | ||
public void testParentCrossSite() { | ||
|
||
Mockito.when(contentHostingService.getSiteCollection("siteId")).thenReturn("/group/siteId"); | ||
Mockito.when(contentHostingService.getContainingCollectionId("/group/otherId/example")).thenReturn("/group/otherId"); | ||
Mockito.when(contentHostingService.getContainingCollectionId("/group/otherId")).thenReturn("/group"); | ||
Mockito.when(service.getSiteVolume("siteId")).thenReturn(siteVolume); | ||
Mockito.when(siteVolume.getRoot()).thenReturn(siteItem); | ||
|
||
SiteVolume volume = factory.getVolume(service, "siteId"); | ||
|
||
// This is for a path outisde the same site | ||
FsItem otherItem = volume.fromPath("/group/otherId/example"); | ||
Assert.assertNotNull(otherItem); | ||
FsItem otherParent = volume.getParent(otherItem); | ||
Assert.assertNotNull(otherParent); | ||
// Should have got back the site parent instead | ||
Assert.assertEquals("Should get site back", siteItem, otherParent); | ||
} | ||
|
||
} |