|
12 | 12 | import org.junit.Assert;
|
13 | 13 | import org.junit.BeforeClass;
|
14 | 14 | import org.junit.Test;
|
| 15 | +import org.sakaiproject.content.api.ContentCollection; |
| 16 | +import org.sakaiproject.content.api.ContentCollectionEdit; |
15 | 17 | import org.sakaiproject.content.api.ContentHostingService;
|
16 | 18 | import org.sakaiproject.content.api.ContentResource;
|
17 | 19 | import org.sakaiproject.content.api.ContentResourceEdit;
|
| 20 | +import org.sakaiproject.entity.api.ResourceProperties; |
| 21 | +import org.sakaiproject.entity.api.ResourcePropertiesEdit; |
| 22 | +import org.sakaiproject.exception.OverQuotaException; |
18 | 23 | import org.sakaiproject.exception.IdUnusedException;
|
19 | 24 | import org.sakaiproject.exception.IdUsedException;
|
20 | 25 | import org.sakaiproject.test.SakaiKernelTestBase;
|
|
27 | 32 | */
|
28 | 33 | public class ContentHostingServiceRecycleTest extends SakaiKernelTestBase {
|
29 | 34 | private static Logger log = LoggerFactory.getLogger(ContentHostingServiceRecycleTest.class);
|
30 |
| - |
| 35 | + private static final String SAMPLE_FOLDER = "/user/admin/"; |
| 36 | + |
31 | 37 | @BeforeClass
|
32 | 38 | public static void beforeClass() {
|
33 | 39 | try {
|
@@ -146,6 +152,66 @@ public void testDeleteResourceRestoreOnTop() throws Exception {
|
146 | 152 | ch.removeResource(filename);
|
147 | 153 | }
|
148 | 154 |
|
| 155 | + /** |
| 156 | + * This is to check that when a restore is attempted and the file exceed quota |
| 157 | + * the file is not restored and we correctly unlock it. |
| 158 | + * @throws Exception |
| 159 | + */ |
| 160 | + @Test |
| 161 | + public void testRestoreOnOverquota() throws Exception { |
| 162 | + ContentHostingService ch = getService(ContentHostingService.class); |
| 163 | + SessionManager sm = getService(SessionManager.class); |
| 164 | + ThreadLocalManager tl = getService(ThreadLocalManager.class); |
| 165 | + reset(tl, sm); |
| 166 | + |
| 167 | + // Set quota to 1kb |
| 168 | + ResourcePropertiesEdit props = ch.newResourceProperties(); |
| 169 | + props.addProperty (ResourceProperties.PROP_COLLECTION_BODY_QUOTA,"1"); |
| 170 | + ContentCollection c = ch.addCollection(SAMPLE_FOLDER,props); |
| 171 | + ContentCollectionEdit ce = ch.editCollection(SAMPLE_FOLDER); |
| 172 | + ch.commitCollection(ce); |
| 173 | + |
| 174 | + long quota = ch.getQuota(ch.getCollection(SAMPLE_FOLDER)); |
| 175 | + Assert.assertEquals("The quota is set to 1",1,quota); |
| 176 | + |
| 177 | + // Create a file |
| 178 | + String filename = SAMPLE_FOLDER + UUID.randomUUID().toString(); |
| 179 | + |
| 180 | + try { |
| 181 | + ContentResourceEdit resource = ch.addResource(filename); |
| 182 | + resource.setContent(new byte[1048]); |
| 183 | + ch.commitResource(resource); |
| 184 | + Assert.fail("We should have exceed the quota."); |
| 185 | + } catch (OverQuotaException oqe) { |
| 186 | + // OverQuota Resource Goes to Trash |
| 187 | + } |
| 188 | + |
| 189 | + try { |
| 190 | + ch.getResource(filename); |
| 191 | + Assert.fail("We shouldn't be able to find: "+ filename); |
| 192 | + } catch (IdUnusedException e) { |
| 193 | + // Expected |
| 194 | + } |
| 195 | + |
| 196 | + try { |
| 197 | + ch.restoreResource(filename); |
| 198 | + Assert.fail("We shouldn't be able to restore: "+ filename); |
| 199 | + } catch (OverQuotaException e) { |
| 200 | + // Expected |
| 201 | + } |
| 202 | + |
| 203 | + try { |
| 204 | + ch.getResource(filename); |
| 205 | + Assert.fail("We shouldn't be able to find: "+ filename); |
| 206 | + } catch (IdUnusedException e) { |
| 207 | + // Expected |
| 208 | + } |
| 209 | + |
| 210 | + List<ContentResource> allDeleted = ch.getAllDeletedResources(SAMPLE_FOLDER); |
| 211 | + Assert.assertEquals("There should only be one copy of the file in the recycle bin.", 1, allDeleted.size()); |
| 212 | + |
| 213 | + } |
| 214 | + |
149 | 215 | /**
|
150 | 216 | * Clear out any threadlocals and reset the session to be admin.
|
151 | 217 | * @param tl ThreadLocalManager service.
|
|
0 commit comments