diff --git a/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentEntity.java b/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentEntity.java index 442bc658b6cf..ca9b8ef9b92d 100644 --- a/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentEntity.java +++ b/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentEntity.java @@ -42,6 +42,7 @@ import org.sakaiproject.site.cover.SiteService; import org.sakaiproject.time.api.Time; import org.sakaiproject.time.cover.TimeService; +import org.sakaiproject.util.BaseResourcePropertiesEdit; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -71,6 +72,9 @@ public class MockContentEntity implements ContentEntity, GroupAwareEdit protected Map memberMap = new HashMap(); protected boolean isActiveEdit; + public MockContentEntity() { + this.resourceProperties = new BaseResourcePropertiesEdit(); + } /* (non-Javadoc) * @see org.sakaiproject.content.api.ContentEntity#getContainingCollection() */ diff --git a/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentResource.java b/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentResource.java index f7e852ee99e3..c17082f633e2 100644 --- a/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentResource.java +++ b/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/MockContentResource.java @@ -61,16 +61,18 @@ public class MockContentResource extends MockContentEntity implements ContentRes protected String contentType; protected String resourceId; - protected ResourcePropertiesEdit resourceProperties; - /** * @param collectionId * @param resourceId */ public MockContentResource(String collectionId, String resourceId) { + super(); this.collectionId = collectionId; this.resourceId = resourceId; + //Setup this property for sorting purposes + this.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, resourceId); + this.getPropertiesEdit().addProperty(ResourceProperties.PROP_CONTENT_LENGTH, "0"); } /* (non-Javadoc) @@ -109,6 +111,7 @@ public void setContent(byte[] content) { this.content = content; this.contentLength = this.content.length; + } /* (non-Javadoc) diff --git a/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/SortTest.java b/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/SortTest.java index f4172e0d3ba6..91a5b97a95e2 100644 --- a/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/SortTest.java +++ b/kernel/kernel-impl/src/test/java/org/sakaiproject/content/impl/test/SortTest.java @@ -21,8 +21,18 @@ package org.sakaiproject.content.impl.test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.sakaiproject.content.api.ContentResource; +import org.sakaiproject.content.api.ContentResourceEdit; import org.sakaiproject.content.impl.ContentHostingComparator; +import org.sakaiproject.entity.api.ResourceProperties; +import org.sakaiproject.entity.api.ResourcePropertiesEdit; +import junit.framework.Assert; import junit.framework.TestCase; public class SortTest extends TestCase { @@ -31,9 +41,10 @@ public SortTest(String name) { super(name); } + @SuppressWarnings("unchecked") public void testSorts() { - ContentHostingComparator c = new ContentHostingComparator(null, true); - + ContentHostingComparator c = new ContentHostingComparator(ResourceProperties.PROP_DISPLAY_NAME, true); + assertEquals(-1, c.compareLikeMacFinder("AAAAA", "BBBBBB")); assertEquals(0, c.compareLikeMacFinder("AAAA", "AAAA")); assertEquals(1, c.compareLikeMacFinder("BBBB", "AAAA")); @@ -70,8 +81,46 @@ public void testSorts() { */ //assertEquals(0, c.compareLikeMacFinder("Leon", "leon")); //assertEquals(0, c.compareLikeMacFinder("leon", "léon")); + + } + private List createResources(List resources) { + List testList = new ArrayList(); + for (String resource:resources) { + testList.add(new MockContentResource("test",resource)); + } + return testList; + } + + public void testNameCompare() { + ContentHostingComparator c = new ContentHostingComparator(ResourceProperties.PROP_DISPLAY_NAME, true, false); + //Test ids to use + List testIds = Arrays.asList("11","10","10x","1","1x","2x","2","4","4","4x","4x","6"); + //Expected sort after the "smart sort" + List smartSortIds = Arrays.asList("1","2","4","10","10x","6","11","1x","2x","4","4x","4x"); + List regularSortIds = Arrays.asList("11","10","10x","1","1x","2x","2","4","4","4x","4x","6"); + + List testResources = createResources(testIds); + List smartSortResources = createResources(smartSortIds); + List regularSortResources = createResources(regularSortIds); + Collections.sort(testResources,c); + for (int i=0;i