Skip to content

Commit

Permalink
SAK-31351
Browse files Browse the repository at this point in the history
  • Loading branch information
buckett committed Jun 14, 2016
1 parent efab709 commit 8fff45d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
6 changes: 6 additions & 0 deletions textarea/elfinder-sakai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<classifier>classes</classifier>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public String asId(FsItem fsItem) {
}
}

public SiteService getSiteService() {
return siteService;
}

public void setSiteService(SiteService siteService) {
this.siteService = siteService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ public String getName(FsItem fsi) {

public FsItem getParent(FsItem fsi) {
String rootId = asId(getRoot());
String id1 = asId(fsi);
if (!rootId.equals(id1)) {
String id = asId(fsi);
String id = asId(fsi);
if (id.startsWith(rootId) && !rootId.equals(id)) {
String parentId = contentHostingService.getContainingCollectionId(id);
return fromPath(parentId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public String getSiteId() {
public SiteFsVolume(String siteId, SakaiFsService service) {
this.siteId = siteId;
this.service = service;
// TODO Injection
siteService = (SiteService) ComponentManager.get(SiteService.class);
this.siteService = service.getSiteService();
}

@Override
Expand Down
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);
}

}

0 comments on commit 8fff45d

Please sign in to comment.