Java Code Examples for org.alfresco.service.cmr.repository.ContentWriter#getContentUrl()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentWriter#getContentUrl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompressingContentStore.java From alfresco-simple-content-stores with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ContentWriter getWriter(final ContentContext context) { final ContentWriter backingWriter = super.getWriter(context); if (TransactionSupportUtil.isActualTransactionActive()) { // this is a new URL so register for rollback handling final Set<String> urlsToDelete = TransactionalResourceHelper.getSet(StoreConstants.KEY_POST_ROLLBACK_DELETION_URLS); urlsToDelete.add(backingWriter.getContentUrl()); } final ContentWriter writer = new CompressingContentWriter(backingWriter.getContentUrl(), context, this.temporaryStore, backingWriter, this.compressionType, this.mimetypesToCompress); return writer; }
Example 2
Source File: AbstractWritableContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testDeleteSimple() throws Exception { ContentStore store = getStore(); ContentWriter writer = getWriter(); writer.putContent("Content for testDeleteSimple"); String contentUrl = writer.getContentUrl(); assertTrue("Content must now exist", store.exists(contentUrl)); try { store.delete(contentUrl); } catch (UnsupportedOperationException e) { logger.warn("Store test testDeleteSimple not possible on " + store.getClass().getName()); return; } assertFalse("Content must now be removed", store.exists(contentUrl)); }
Example 3
Source File: RoutingContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testGeneralUse() { for (int i = 0 ; i < 20; i++) { ContentContext contentContext = new ContentContext(null, null); ContentWriter writer = routingStore.getWriter(contentContext); String content = "This was generated by " + this.getClass().getName() + "#testGeneralUse number " + i; writer.putContent(content); // Check that it exists String contentUrl = writer.getContentUrl(); checkForContent(contentUrl, content); // Now go direct to the routing store and check that it is able to find the appropriate URLs ContentReader reader = routingStore.getReader(contentUrl); assertNotNull("Null reader returned", reader); assertTrue("Reader should be onto live content", reader.exists()); } }
Example 4
Source File: CachingContentStoreSpringTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testStoreWillReadFromCacheWhenAvailable() { final String content = "Content for " + getName() + " test."; // Write some content to the backing store. ContentWriter writer = backingStore.getWriter(ContentContext.NULL_CONTEXT); writer.putContent(content); final String contentUrl = writer.getContentUrl(); // Read content using the CachingContentStore - will cause content to be cached. String retrievedContent = store.getReader(contentUrl).getContentString(); assertEquals(content, retrievedContent); // Remove the original content from the backing store. backingStore.delete(contentUrl); assertFalse("Original content should have been deleted", backingStore.exists(contentUrl)); // The cached version is still available. String contentAfterDelete = store.getReader(contentUrl).getContentString(); assertEquals(content, contentAfterDelete); }
Example 5
Source File: AbstractWritableContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Get a writer and write a little bit of content before reading it. */ @Test public void testSimpleUse() { ContentStore store = getStore(); String content = "Content for testSimpleUse"; ContentWriter writer = store.getWriter(ContentStore.NEW_CONTENT_CONTEXT); assertNotNull("Writer may not be null", writer); // Ensure that the URL is available String contentUrlBefore = writer.getContentUrl(); assertNotNull("Content URL may not be null for unused writer", contentUrlBefore); assertTrue("URL is not valid: " + contentUrlBefore, AbstractContentStore.isValidContentUrl(contentUrlBefore)); // Write something writer.putContent(content); String contentUrlAfter = writer.getContentUrl(); assertTrue("URL is not valid: " + contentUrlBefore, AbstractContentStore.isValidContentUrl(contentUrlAfter)); assertEquals("The content URL may not change just because the writer has put content", contentUrlBefore, contentUrlAfter); // Get the readers ContentReader reader = store.getReader(contentUrlBefore); assertNotNull("Reader from store is null", reader); assertEquals(reader.getContentUrl(), writer.getContentUrl()); String checkContent = reader.getContentString(); assertEquals("Content is different", content, checkContent); }
Example 6
Source File: FileContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Checks that the store disallows concurrent writers to be issued to the same URL. */ @SuppressWarnings("unused") @Test public void testConcurrentWriteDetection() throws Exception { ByteBuffer buffer = ByteBuffer.wrap("Something".getBytes()); ContentStore store = getStore(); ContentContext firstContentCtx = ContentStore.NEW_CONTENT_CONTEXT; ContentWriter firstWriter = store.getWriter(firstContentCtx); String contentUrl = firstWriter.getContentUrl(); ContentContext secondContentCtx = new ContentContext(null, contentUrl); try { ContentWriter secondWriter = store.getWriter(secondContentCtx); fail("Store must disallow more than one writer onto the same content URL: " + store); } catch (ContentExistsException e) { // expected } }
Example 7
Source File: ReadOnlyFileContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void before() throws Exception { // create a store that uses a subdirectory of the temp directory File tempDir = TempFileProvider.getTempDir(); store = new FileContentStore(ctx, tempDir.getAbsolutePath() + File.separatorChar + getName()); // Put some content into it ContentWriter writer = store.getWriter(new ContentContext(null, null)); writer.putContent("Content for getExistingContentUrl"); this.contentUrl = writer.getContentUrl(); // disallow random access store.setReadOnly(true); }
Example 8
Source File: FileContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
@Test public void unconfiguredWriteReadDelete() throws Exception { final FileContentStore store = this.createDefaultStore(); store.afterPropertiesSet(); Assert.assertTrue("Store should support write", store.isWriteSupported()); final String testText = generateText(SEED_PRNG.nextLong()); final Date dateBeforeWrite = new Date(); final ContentWriter writer = this.testIndividualWriteAndRead(store, testText); final String contentUrl = writer.getContentUrl(); final DateFormat df = new SimpleDateFormat("yyyy/M/d/H/m", Locale.ENGLISH); df.setTimeZone(TimeZone.getDefault()); final String expectedPattern = "^" + STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + df.format(dateBeforeWrite) + "/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\.bin$"; Assert.assertTrue("Content URL did not match expected date-based pattern with UUID", contentUrl.matches(expectedPattern)); Assert.assertTrue("Content should have been deleted", store.delete(contentUrl)); final Path rootPath = this.storeFolder.toPath(); final long subPathCount = TestUtilities.walk(rootPath, (stream) -> { return stream.filter((path) -> { return !path.equals(rootPath); }).count(); }, FileVisitOption.FOLLOW_LINKS); Assert.assertEquals("Store path should not contain any elements after delete", 0, subPathCount); }
Example 9
Source File: FileContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
@Test public void dontDeleteEmptryDirs() throws Exception { final FileContentStore store = this.createDefaultStore(); store.setDeleteEmptyDirs(false); store.afterPropertiesSet(); Assert.assertTrue("Store should support write", store.isWriteSupported()); final String testText = generateText(SEED_PRNG.nextLong()); final ContentWriter writer = this.testIndividualWriteAndRead(store, testText); final String contentUrl = writer.getContentUrl(); Assert.assertTrue("Content should have been deleted", store.delete(contentUrl)); final Path rootPath = this.storeFolder.toPath(); final long subPathCount = TestUtilities.walk(rootPath, (stream) -> { return stream.filter((path) -> { return !path.equals(rootPath); }).count(); }, FileVisitOption.FOLLOW_LINKS); Assert.assertNotEquals("Store path should contain additional elements after delete without allowing empty directory deletion", 0, subPathCount); final long filesCount = TestUtilities.walk(rootPath, (stream) -> { return stream.filter((path) -> { return path.toFile().isFile(); }).count(); }, FileVisitOption.FOLLOW_LINKS); Assert.assertEquals("Store path should not contain any content files after deletion", 0, filesCount); }
Example 10
Source File: RoutingContentServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testGetRawReader() throws Exception { ContentReader reader = contentService.getRawReader("test://non-existence"); assertNotNull("A reader is expected with content URL referencing no content", reader); assertFalse("Reader should not have any content", reader.exists()); // Now write something ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, false); writer.putContent("ABC from " + getName()); // Try again String contentUrl = writer.getContentUrl(); reader = contentService.getRawReader(contentUrl); assertNotNull("Expected reader for live, raw content", reader); assertEquals("Content sizes don't match", writer.getSize(), reader.getSize()); }
Example 11
Source File: AbstractWritableContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * <p> * This implementation creates some content in the store and returns the new content URL. */ protected String getExistingContentUrl() { ContentWriter writer = getWriter(); writer.putContent("Content for getExistingContentUrl"); return writer.getContentUrl(); }
Example 12
Source File: StandardQuotaStrategyTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private String writeSingleFileInMB(int sizeInMb) throws IOException { ContentWriter writer = store.getWriter(ContentContext.NULL_CONTEXT); File content = createFileOfSize(sizeInMb * 1024); writer.putContent(content); return writer.getContentUrl(); }
Example 13
Source File: FileContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
@Test @Ignore public void deleteEmptyParentsButNotSymbolicLinks() throws Exception { this.linkedFolder = TestUtilities.createFolder(); final DateFormat df = new SimpleDateFormat("yyyy/M/d", Locale.ENGLISH); df.setTimeZone(TimeZone.getDefault()); final String relativePathForSymbolicLink = df.format(new Date()); final String relativePathForFolder = relativePathForSymbolicLink.substring(0, relativePathForSymbolicLink.lastIndexOf('/')); final String linkName = relativePathForSymbolicLink.substring(relativePathForSymbolicLink.lastIndexOf('/') + 1); final Path folderForLink = Files.createDirectories(this.storeFolder.toPath().resolve(relativePathForFolder)); final Path linkPath = folderForLink.resolve(linkName); Files.createSymbolicLink(linkPath, this.linkedFolder.toPath()); final FileContentStore store = this.createDefaultStore(); store.afterPropertiesSet(); Assert.assertTrue("Store should support write", store.isWriteSupported()); final String testText = generateText(SEED_PRNG.nextLong()); final ContentWriter writer = this.testIndividualWriteAndRead(store, testText); final String contentUrl = writer.getContentUrl(); Assert.assertTrue("Content should have been deleted", store.delete(contentUrl)); final Path linkedRootPath = this.linkedFolder.toPath(); final long linkedFolderSubPaths = TestUtilities.walk(linkedRootPath, (stream) -> { return stream.filter((path) -> { return !path.equals(linkedRootPath); }).count(); }, FileVisitOption.FOLLOW_LINKS); Assert.assertEquals("Linked folder should not contain additional elements after delete", 0, linkedFolderSubPaths); Assert.assertTrue("Link should still exist after delete", Files.exists(linkPath)); }
Example 14
Source File: FileContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
@Test public void wildcardContentURL() throws Exception { final FileContentStore store = this.createDefaultStore(); store.afterPropertiesSet(); Assert.assertTrue("Store should support write", store.isWriteSupported()); final String testText = generateText(SEED_PRNG.nextLong()); final String dummyContentUrl = StoreConstants.WILDCARD_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do"; final String expectedContentUrl = STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do"; final ContentWriter writer = this.testIndividualWriteAndRead(store, new ContentContext(null, dummyContentUrl), testText); final String contentUrl = writer.getContentUrl(); Assert.assertEquals("Effective content URL did not match expected URL", expectedContentUrl, contentUrl); Assert.assertTrue("Wildcard-based content URL should have been reported as supported", store.isContentUrlSupported(dummyContentUrl)); Assert.assertTrue("Wildcard-based content URL should have been reported as existing", store.exists(dummyContentUrl)); final ContentReader reader = store.getReader(dummyContentUrl); Assert.assertNotNull("Wildcard-based content URL should have yielded a reader", reader); Assert.assertTrue("Wildcard-based content URL should have yielded a reader to existing content", reader.exists()); final String readContent = reader.getContentString(); Assert.assertEquals("Content read from reader for wildcard-based content URL did not match written content", testText, readContent); Assert.assertTrue("Content should have been deleted using wildcard-based content URL", store.delete(dummyContentUrl)); Assert.assertFalse( "Content should not be reported as existing for explicit content URL after having been deleted via wildcard-based content URL", store.exists(contentUrl)); }
Example 15
Source File: AggregatingContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testAddContent() throws Exception { ContentWriter writer = getWriter(); writer.putContent(SOME_CONTENT); String contentUrl = writer.getContentUrl(); checkForUrl(contentUrl, true); }
Example 16
Source File: AggregatingContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 4 votes |
@Test public void primaryOnlyWrite() throws Exception { final AggregatingContentStore aggregatingContentStore = new AggregatingContentStore(); final FileContentStore store1 = new FileContentStore(); store1.setRootDirectory(store1Folder.getAbsolutePath()); store1.setProtocol(STORE_1_PROTOCOL); aggregatingContentStore.setPrimaryStore(store1); final FileContentStore store2 = new FileContentStore(); store2.setRootDirectory(store2Folder.getAbsolutePath()); store2.setProtocol(STORE_2_PROTOCOL); final FileContentStore store3 = new FileContentStore(); store3.setRootDirectory(store3Folder.getAbsolutePath()); store3.setProtocol(STORE_3_PROTOCOL); aggregatingContentStore.setSecondaryStores(Arrays.asList(store2, store3)); store1.afterPropertiesSet(); store2.afterPropertiesSet(); store3.afterPropertiesSet(); aggregatingContentStore.afterPropertiesSet(); final String primaryText1 = generateText(SEED_PRNG.nextLong()); final String primaryText2 = generateText(SEED_PRNG.nextLong()); final ContentWriter primaryWriter1 = testIndividualWriteAndRead(aggregatingContentStore, primaryText1, STORE_1_PROTOCOL); final String contentUrl1 = primaryWriter1.getContentUrl(); final String wildcardContentUrl = contentUrl1.replaceFirst(STORE_1_PROTOCOL, StoreConstants.WILDCARD_PROTOCOL); Assert.assertTrue("Aggregating content store did not write content to primary store", store1.exists(wildcardContentUrl)); Assert.assertFalse("Aggregating content store wrote content to 1st secondcary store", store2.exists(wildcardContentUrl)); Assert.assertFalse("Aggregating content store wrote content to 2nd secondcary store", store3.exists(wildcardContentUrl)); final ContentReader reader1 = store1.getReader(wildcardContentUrl); Assert.assertTrue("Aggregating store did not return valid reader for content URL in primary store", reader1 != null && reader1.exists()); Assert.assertEquals("Content retrieved from primary store does not match content written via aggregating store", primaryText1, reader1.getContentString()); store1.setReadOnly(true); this.thrown.expect(UnsupportedOperationException.class); testIndividualWriteAndRead(aggregatingContentStore, primaryText2, STORE_1_PROTOCOL); }
Example 17
Source File: AggregatingContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 4 votes |
@Test public void primaryOnlyDeletion() throws Exception { final AggregatingContentStore aggregatingContentStore = new AggregatingContentStore(); aggregatingContentStore.setDeleteContentFromSecondaryStores(false); // all stores need to use identical protocol in content URLs final FileContentStore store1 = new FileContentStore(); store1.setRootDirectory(store1Folder.getAbsolutePath()); store1.setProtocol(STORE_1_PROTOCOL); aggregatingContentStore.setPrimaryStore(store1); final FileContentStore store2 = new FileContentStore(); store2.setRootDirectory(store2Folder.getAbsolutePath()); store2.setProtocol(STORE_1_PROTOCOL); final FileContentStore store3 = new FileContentStore(); store3.setRootDirectory(store3Folder.getAbsolutePath()); store3.setProtocol(STORE_1_PROTOCOL); aggregatingContentStore.setSecondaryStores(Arrays.asList(store2, store3)); store1.afterPropertiesSet(); store2.afterPropertiesSet(); store3.afterPropertiesSet(); aggregatingContentStore.afterPropertiesSet(); final String text = generateText(SEED_PRNG.nextLong()); final ContentWriter primaryWriter = testIndividualWriteAndRead(aggregatingContentStore, text, STORE_1_PROTOCOL); final String contentUrl = primaryWriter.getContentUrl(); // copy into secondary stores final String wildcardContentUrl = contentUrl.replaceFirst(STORE_1_PROTOCOL, StoreConstants.WILDCARD_PROTOCOL); final ContentWriter store2Writer = store2.getWriter(new ContentContext(null, wildcardContentUrl)); store2Writer.putContent(primaryWriter.getReader()); final ContentWriter store3Writer = store3.getWriter(new ContentContext(null, wildcardContentUrl)); store3Writer.putContent(primaryWriter.getReader()); final boolean deleted = aggregatingContentStore.delete(contentUrl); Assert.assertTrue("Aggregating content store did not report content as deleted", deleted); Assert.assertFalse("Primary store still contains deleted content", store1.exists(contentUrl)); Assert.assertTrue("1st secondary store does not still contain content despite deletion not allowed for secondary stores", store2.exists(store2Writer.getContentUrl())); Assert.assertTrue("2nd secondary store does not still contain content despite deletion not allowed for secondary stores", store3.exists(store3Writer.getContentUrl())); }
Example 18
Source File: CheckOutCheckInServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test checkIn */ @Test public void testCheckIn() { NodeRef workingCopy = checkout(); // Test standard check-in Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(); versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version"); cociService.checkin(workingCopy, versionProperties); // Test check-in with content NodeRef workingCopy3 = checkout(); nodeService.setProperty(workingCopy3, PROP_NAME_QNAME, TEST_VALUE_2); nodeService.setProperty(workingCopy3, PROP2_QNAME, TEST_VALUE_3); ContentWriter tempWriter = this.contentService.getWriter(workingCopy3, ContentModel.PROP_CONTENT, false); assertNotNull(tempWriter); tempWriter.putContent(CONTENT_2); String contentUrl = tempWriter.getContentUrl(); Map<String, Serializable> versionProperties3 = new HashMap<String, Serializable>(); versionProperties3.put(Version.PROP_DESCRIPTION, "description"); versionProperties3.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR); NodeRef origNodeRef = cociService.checkin(workingCopy3, versionProperties3, contentUrl, true); assertNotNull(origNodeRef); // Check the checked in content ContentReader contentReader = this.contentService.getReader(origNodeRef, ContentModel.PROP_CONTENT); assertNotNull(contentReader); assertEquals(CONTENT_2, contentReader.getContentString()); // Check that the version history is correct Version version = this.versionService.getCurrentVersion(origNodeRef); assertNotNull(version); assertEquals("description", version.getDescription()); assertEquals(VersionType.MAJOR, version.getVersionType()); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); assertNotNull(versionNodeRef); // Check the verioned content ContentReader versionContentReader = this.contentService.getReader(versionNodeRef, ContentModel.PROP_CONTENT); assertNotNull(versionContentReader); assertEquals(CONTENT_2, versionContentReader.getContentString()); // Check that the name is not updated during the check-in assertEquals(TEST_VALUE_2, nodeService.getProperty(versionNodeRef, PROP_NAME_QNAME)); assertEquals(TEST_VALUE_2, nodeService.getProperty(origNodeRef, PROP_NAME_QNAME)); // Check that the other properties are updated during the check-in assertEquals(TEST_VALUE_3, nodeService.getProperty(versionNodeRef, PROP2_QNAME)); assertEquals(TEST_VALUE_3, nodeService.getProperty(origNodeRef, PROP2_QNAME)); // Cancel the check out after is has been left checked out cociService.cancelCheckout(workingCopy3); // Test keep checked out flag NodeRef workingCopy2 = checkout(); Map<String, Serializable> versionProperties2 = new HashMap<String, Serializable>(); versionProperties2.put(Version.PROP_DESCRIPTION, "Another version test"); this.cociService.checkin(workingCopy2, versionProperties2, null, true); this.cociService.checkin(workingCopy2, new HashMap<String, Serializable>(), null, true); }
Example 19
Source File: AggregatingContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 4 votes |
@Test public void readAggregation() throws Exception { final AggregatingContentStore aggregatingContentStore = new AggregatingContentStore(); final FileContentStore store1 = new FileContentStore(); store1.setRootDirectory(store1Folder.getAbsolutePath()); store1.setProtocol(STORE_1_PROTOCOL); aggregatingContentStore.setPrimaryStore(store1); final FileContentStore store2 = new FileContentStore(); store2.setRootDirectory(store2Folder.getAbsolutePath()); store2.setProtocol(STORE_2_PROTOCOL); final FileContentStore store3 = new FileContentStore(); store3.setRootDirectory(store3Folder.getAbsolutePath()); store3.setProtocol(STORE_3_PROTOCOL); aggregatingContentStore.setSecondaryStores(Arrays.asList(store2, store3)); store1.afterPropertiesSet(); store2.afterPropertiesSet(); store3.afterPropertiesSet(); aggregatingContentStore.afterPropertiesSet(); final String textStore1 = generateText(SEED_PRNG.nextLong()); final String textStore2 = generateText(SEED_PRNG.nextLong()); final String textStore3 = generateText(SEED_PRNG.nextLong()); { final ContentWriter store1Writer = testIndividualWriteAndRead(store1, textStore1, STORE_1_PROTOCOL); final String contentUrl1 = store1Writer.getContentUrl(); Assert.assertTrue("Aggregating store does not support URL of primary store", aggregatingContentStore.isContentUrlSupported(contentUrl1)); Assert.assertTrue("Aggregating store claims content URL of primary store does not exist", aggregatingContentStore.exists(contentUrl1)); final ContentReader reader1 = aggregatingContentStore.getReader(contentUrl1); Assert.assertTrue("Aggregating store did not return valid reader for content URL in primary store", reader1 != null && reader1.exists()); Assert.assertEquals("Content retrieved via aggregating store does not match content in primary store", textStore1, reader1.getContentString()); } { final ContentWriter store2Writer = testIndividualWriteAndRead(store2, textStore2, STORE_2_PROTOCOL); final String contentUrl2 = store2Writer.getContentUrl(); Assert.assertTrue("Aggregating store does not support URL of 1st secondary store", aggregatingContentStore.isContentUrlSupported(contentUrl2)); Assert.assertTrue("Aggregating store claims content URL of 1st secondary store does not exist", aggregatingContentStore.exists(contentUrl2)); final ContentReader reader2 = aggregatingContentStore.getReader(contentUrl2); Assert.assertTrue("Aggregating store did not return valid reader for content URL in 1st secondary store", reader2 != null && reader2.exists()); Assert.assertEquals("Content retrieved via aggregating store does not match content in 1st secondary store", textStore2, reader2.getContentString()); } { final ContentWriter store3Writer = testIndividualWriteAndRead(store3, textStore3, STORE_3_PROTOCOL); final String contentUrl3 = store3Writer.getContentUrl(); Assert.assertTrue("Aggregating store does not support URL of 2nd secondary store", aggregatingContentStore.isContentUrlSupported(contentUrl3)); Assert.assertTrue("Aggregating store claims content URL of 2nd secondary store does not exist", aggregatingContentStore.exists(contentUrl3)); final ContentReader reader3 = aggregatingContentStore.getReader(contentUrl3); Assert.assertTrue("Aggregating store did not return valid reader for content URL in 2nd secondary store", reader3 != null && reader3.exists()); Assert.assertEquals("Content retrieved via aggregating store does not match content in 2nd secondary store", textStore3, reader3.getContentString()); } }
Example 20
Source File: AggregatingContentStoreTest.java From alfresco-simple-content-stores with Apache License 2.0 | 4 votes |
@Test public void defaultSecondaryStoreDeletionWithPartialReadOnlyStores() throws Exception { final AggregatingContentStore aggregatingContentStore = new AggregatingContentStore(); // all stores need to use identical protocol in content URLs final FileContentStore store1 = new FileContentStore(); store1.setRootDirectory(store1Folder.getAbsolutePath()); store1.setProtocol(STORE_1_PROTOCOL); aggregatingContentStore.setPrimaryStore(store1); final FileContentStore store2 = new FileContentStore(); store2.setRootDirectory(store2Folder.getAbsolutePath()); store2.setProtocol(STORE_1_PROTOCOL); final FileContentStore store3 = new FileContentStore(); store3.setRootDirectory(store3Folder.getAbsolutePath()); store3.setProtocol(STORE_1_PROTOCOL); aggregatingContentStore.setSecondaryStores(Arrays.asList(store2, store3)); store1.afterPropertiesSet(); store2.afterPropertiesSet(); store3.afterPropertiesSet(); aggregatingContentStore.afterPropertiesSet(); final String text = generateText(SEED_PRNG.nextLong()); final ContentWriter primaryWriter = testIndividualWriteAndRead(aggregatingContentStore, text, STORE_1_PROTOCOL); final String contentUrl = primaryWriter.getContentUrl(); // copy into secondary stores final String wildcardContentUrl = contentUrl.replaceFirst(STORE_1_PROTOCOL, StoreConstants.WILDCARD_PROTOCOL); final ContentWriter store2Writer = store2.getWriter(new ContentContext(null, wildcardContentUrl)); store2Writer.putContent(primaryWriter.getReader()); final ContentWriter store3Writer = store3.getWriter(new ContentContext(null, wildcardContentUrl)); store3Writer.putContent(primaryWriter.getReader()); // mark 2nd secondary store as read-only store3.setReadOnly(true); final boolean deleted = aggregatingContentStore.delete(contentUrl); Assert.assertTrue("Aggregating content store did not report content as deleted", deleted); Assert.assertFalse("Primary store still contains deleted content", store1.exists(contentUrl)); Assert.assertFalse("1st secondary store still contains deleted content", store2.exists(store2Writer.getContentUrl())); Assert.assertTrue("2nd secondary store does not still contain content despite store being read-only", store3.exists(store3Writer.getContentUrl())); }