Java Code Examples for org.alfresco.service.cmr.repository.ContentReader#getContentString()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentReader#getContentString() .
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: FailoverContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception { // Do not actually perform any transformation. The test above is only interested in whether // an exception is thrown and handled. if (logger.isInfoEnabled()) { logger.info(springBeanName + " is attempting a transformation"); } reader.getContentString(); if (alwaysFail) { throw new AlfrescoRuntimeException("Test code intentionally failed method call."); } else { return; } }
Example 2
Source File: LocalSynchronousTransformClientIntegrationTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private void checkTransform(String testFileName, String targetMimetype, Map<String, String> actualOptions, boolean expectedToPass) { if (expectedToPass) { NodeRef sourceNode = transactionService.getRetryingTransactionHelper().doInTransaction(() -> createContentNodeFromQuickFile(testFileName)); ContentReader reader = contentService.getReader(sourceNode, PROP_CONTENT); ContentWriter writer = contentService.getTempWriter(); writer.setMimetype(targetMimetype); synchronousTransformClient.transform(reader, writer, actualOptions, null, sourceNode); ContentReader transformReader = writer.getReader(); String content = transformReader == null ? null : transformReader.getContentString(); content = content == null || content.isEmpty() ? null : content; assertNotNull("The synchronous transform resulted in no content", content); } }
Example 3
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with nested mimetype multipart/alternative to text */ public void testRFC822NestedAlternativeToText() throws Exception { File emlSourceFile = loadQuickTestFile("nested.alternative.eml"); File txtTargetFile = TempFileProvider.createTempFile("test5", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_NESTED_ALTERNATIVE_CONTENT)); }
Example 4
Source File: SpoofedTextContentReaderTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testGetContentString_01() { // To URL String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 12345L, 56L, "harry"); // To Reader ContentReader reader = new SpoofedTextContentReader(url); String readerText = reader.getContentString(); assertEquals("harry have voice the from countered growth invited ", readerText); // Cannot repeat try { reader.getContentString(); fail("Should not be able to reread content."); } catch (ContentIOException e) { // Expected } // Get a new Reader reader = reader.getReader(); // Get exactly the same text assertEquals(readerText, reader.getContentString()); }
Example 5
Source File: MailContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a chinese non-unicode msg file to * text */ public void testNonUnicodeChineseMsgToText() throws Exception { File msgSourceFile = loadQuickTestFile("chinese.msg"); File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt"); ContentReader reader = new FileContentReader(msgSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); // Check the quick text String text = reader2.getContentString(); assertTrue(text.contains(QUICK_CONTENT)); // Now check the non quick parts came out ok assertTrue(text.contains("(\u5f35\u6bd3\u502b)")); assertTrue(text.contains("\u683c\u5f0f\u6e2c\u8a66 )")); }
Example 6
Source File: AbstractWritableContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testStringTruncation() throws Exception { String content = "1234567890"; ContentWriter writer = getWriter(); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); // shorter format i.t.o. bytes used // write the content writer.putContent(content); // get a reader - get it in a larger format i.t.o. bytes ContentReader reader = writer.getReader(); String checkContent = reader.getContentString(5); assertEquals("Truncated strings don't match", "12345", checkContent); }
Example 7
Source File: PoiHssfContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testCsvOutput() throws Exception { File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("xls"); ContentReader sourceReader = new FileContentReader(sourceFile); File targetFile = TempFileProvider.createTempFile( getClass().getSimpleName() + "_" + getName() + "_xls_", ".csv"); ContentWriter targetWriter = new FileContentWriter(targetFile); sourceReader.setMimetype(MimetypeMap.MIMETYPE_EXCEL); targetWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_CSV); transformer.transform(sourceReader, targetWriter); ContentReader targetReader = targetWriter.getReader(); String checkContent = targetReader.getContentString(); additionalContentCheck( MimetypeMap.MIMETYPE_EXCEL, MimetypeMap.MIMETYPE_TEXT_CSV, checkContent ); }
Example 8
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with a html part containing html special characters to text */ public void testHtmlSpecialCharsToText() throws Exception { File emlSourceFile = loadQuickTestFile("htmlChars.eml"); File txtTargetFile = TempFileProvider.createTempFile("test6", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(!contentStr.contains(HTML_SPACE_SPECIAL_CHAR)); }
Example 9
Source File: FileFolderServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testGetReaderWriter() throws Exception { // testing a failure txn.commit(); txn = transactionService.getUserTransaction(); txn.begin(); FileInfo dirInfo = getByName(NAME_L0_FOLDER_A, true); UserTransaction rollbackTxn = null; try { rollbackTxn = transactionService.getNonPropagatingUserTransaction(); rollbackTxn.begin(); fileFolderService.getWriter(dirInfo.getNodeRef()); fail("Failed to detect content write to folder"); } catch (RuntimeException e) { // expected } finally { rollbackTxn.rollback(); } FileInfo fileInfo = getByName(NAME_L1_FILE_A, false); ContentWriter writer = fileFolderService.getWriter(fileInfo.getNodeRef()); assertNotNull("Writer is null", writer); // write some content String content = "ABC"; writer.putContent(content); // read the content ContentReader reader = fileFolderService.getReader(fileInfo.getNodeRef()); assertNotNull("Reader is null", reader); String checkContent = reader.getContentString(); assertEquals("Content mismatch", content, checkContent); }
Example 10
Source File: XSLTRenderingEngineTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testParseXMLDocument() throws Exception { try { FileInfo file = createXmlFile(companyHome); createXmlFile(companyHome, "TestXML.xml", sampleXML); FileInfo xslFile = createXmlFile(companyHome, callParseXmlDocument); RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME); def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, xslFile.getNodeRef()); ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def); assertNotNull(rendition); ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT); assertNotNull(reader); String output = reader.getContentString(); log.debug("XSLT Processor output: " + output); assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output); } catch (Exception ex) { log.error("Error!", ex); fail(); } }
Example 11
Source File: RoutingContentServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks that the URL, mimetype and encoding are automatically set on the readers * and writers */ public void testAutoSettingOfProperties() throws Exception { // get a writer onto the node ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); assertNotNull("Writer should not be null", writer); assertNotNull("Content URL should not be null", writer.getContentUrl()); assertNotNull("Content mimetype should not be null", writer.getMimetype()); assertNotNull("Content encoding should not be null", writer.getEncoding()); assertNotNull("Content locale should not be null", writer.getLocale()); // write some content writer.putContent(SOME_CONTENT); // get the reader ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNotNull("Reader should not be null", reader); assertNotNull("Content URL should not be null", reader.getContentUrl()); assertNotNull("Content mimetype should not be null", reader.getMimetype()); assertNotNull("Content encoding should not be null", reader.getEncoding()); assertNotNull("Content locale should not be null", reader.getLocale()); // check that the content length is correct // - note encoding is important as we get the byte length long length = SOME_CONTENT.getBytes(reader.getEncoding()).length; // ensures correct decoding long checkLength = reader.getSize(); assertEquals("Content length incorrect", length, checkLength); // check the content - the encoding will come into effect here String contentCheck = reader.getContentString(); assertEquals("Content incorrect", SOME_CONTENT, contentCheck); }
Example 12
Source File: RenditionServiceIntegrationTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private String readTextContent(NodeRef nodeRef) { ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); assertNotNull("reader was null", reader); reader.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); return reader.getContentString(); }
Example 13
Source File: AbstractWritableContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Check that a reader is immutable, i.e. that a reader fetched before a * write doesn't suddenly become aware of the content once it has been written. */ @Test public void testReaderImmutability() { ContentWriter writer = getWriter(); ContentReader readerBeforeWrite = writer.getReader(); assertNotNull(readerBeforeWrite); assertFalse(readerBeforeWrite.exists()); // Write some content writer.putContent("Content for testReaderImmutability"); assertFalse("Reader's state changed after write", readerBeforeWrite.exists()); try { readerBeforeWrite.getContentString(); fail("Reader's state changed after write"); } catch (ContentIOException e) { // Expected } // A new reader should work ContentReader readerAfterWrite = writer.getReader(); assertTrue("New reader after write should be directed to new content", readerAfterWrite.exists()); }
Example 14
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private boolean isCommentExist(NodeRef nr, String commentForCheck) { if (!nodeService.hasAspect(nr, ForumModel.ASPECT_DISCUSSABLE)) { return false; } NodeRef forumNode = nodeService.getChildAssocs(nr, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef(); final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments")); if (existingTopics.isEmpty()) { return false; } NodeRef topicNode = existingTopics.get(0).getChildRef(); Collection<ChildAssociationRef> comments = nodeService.getChildAssocsWithoutParentAssocsOfType(topicNode, ContentModel.ASSOC_CONTAINS); for (ChildAssociationRef comment : comments) { NodeRef commentRef = comment.getChildRef(); ContentReader reader = contentService.getReader(commentRef, ContentModel.PROP_CONTENT); if (reader == null) { continue; } String contentString = reader.getContentString(); if (commentForCheck.equals(contentString)) { return true; } } return false; }
Example 15
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 16
Source File: FileFolderLoaderTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * 10 files; 10 per txn; force storage; identical */ @Test public void testLoad_04() throws Exception { try { AuthenticationUtil.pushAuthentication(); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); int created = fileFolderLoader.createFiles( writeFolderPath, 10, 10, 1024L, 1024L, 1L, true, 10, 256L); assertEquals("Incorrect number of files generated.", 10, created); // Count assertEquals(10, nodeService.countChildAssocs(writeFolderNodeRef, true)); // Check the files List<FileInfo> fileInfos = fileFolderService.listFiles(writeFolderNodeRef); String lastText = null; String lastDescr = null; String lastUrl = null; for (FileInfo fileInfo : fileInfos) { NodeRef fileNodeRef = fileInfo.getNodeRef(); // The URLs must all be unique as we wrote the physical binaries ContentReader reader = fileFolderService.getReader(fileNodeRef); assertEquals("UTF-8", reader.getEncoding()); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, reader.getMimetype()); assertEquals(1024L, reader.getSize()); if (lastUrl == null) { lastUrl = reader.getContentUrl(); } else { assertNotEquals("We expect unique URLs: ", lastUrl, reader.getContentUrl()); lastUrl = reader.getContentUrl(); } // Check content if (lastText == null) { lastText = reader.getContentString(); } else { String currentStr = reader.getContentString(); assertEquals("All text must be identical due to same seed. ", lastText, currentStr); lastText = currentStr; } // Check description if (lastDescr == null) { lastDescr = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION)); assertEquals("cm:description length is incorrect. ", 256, lastDescr.getBytes().length); } else { String currentDescr = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION)); assertEquals("All descriptions must be identical due to varying seed. ", lastDescr, currentDescr); lastDescr = currentDescr; } } } finally { AuthenticationUtil.popAuthentication(); } }
Example 17
Source File: HTMLRenderingEngineTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test for a .doc and a .docx, neither of which have images */ @Test public void testDocWithoutImages() throws Exception { def.setParameterValue( RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, targetFolderPath + "/${name}.html" ); for(String name : new String[] {"quick.doc","quick.docx"}) { sourceDoc = createForDoc(name); int numItemsStart = nodeService.getChildAssocs(targetFolder).size(); ChildAssociationRef rendition = renditionService.render(sourceDoc, def); assertNotNull(rendition); // Check it was created NodeRef htmlNode = rendition.getChildRef(); assertEquals(true, nodeService.exists(htmlNode)); // Check it got the right name assertEquals( name.substring(0, name.lastIndexOf('.')) + ".html", nodeService.getProperty(htmlNode, ContentModel.PROP_NAME) ); // Check it ended up in the right place assertEquals( "Should have been in " + targetFolderPath + " but was in" + nodeService.getPath(htmlNode), targetFolder, nodeService.getPrimaryParent(htmlNode).getParentRef() ); // Check it got the right contents ContentReader reader = contentService.getReader( htmlNode, ContentModel.PROP_CONTENT ); String html = reader.getContentString(); assertEquals("<?xml", html.substring(0, 5)); // Check we didn't get an image folder, only the html int numItems = nodeService.getChildAssocs(targetFolder).size(); assertEquals(numItemsStart+1, numItems); // Check that the html lacks img tags assertEquals( "Unexpected img tag in html:\n" + html, false, html.contains("<img") ); // Check we didn't get any images for(ChildAssociationRef ref : nodeService.getChildAssocs(htmlNode)) { // TODO Check against composite content associations when present // if(ref.getTypeQName().equals(HTMLRenderingEngine.PRIMARY_IMAGE)) // fail("Found unexpected primary image of rendered html"); // if(ref.getTypeQName().equals(HTMLRenderingEngine.SECONDARY_IMAGE)) // fail("Found unexpected secondary image of rendered html"); } // All done tidyUpSourceDoc(); } }
Example 18
Source File: RoutingContentServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Create several threads that will attempt to write to the same node property. * The ContentWriter is handed to the thread, so this checks that the stream closure * uses the transaction that called <code>close</code> and not the transaction that * fetched the <code>ContentWriter</code>. */ public synchronized void testConcurrentWritesWithMultipleTxns() throws Exception { NodeRef nodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef(); // ensure that there is no content to read on the node ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); assertNull("Reader should not be available", reader); // commit node so that threads can see node txn.commit(); txn = null; String threadContent = "Thread content"; WriteThread[] writeThreads = new WriteThread[5]; for (int i = 0; i < writeThreads.length; i++) { ContentWriter threadWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); writeThreads[i] = new WriteThread(threadWriter, threadContent); // Kick each thread off writeThreads[i].start(); } // Wait for all threads to be waiting outer: while (true) { // Wait for each thread to be in a transaction for (int i = 0; i < writeThreads.length; i++) { if (!writeThreads[i].isWaiting()) { wait(10); continue outer; } } // All threads were waiting break outer; } // Kick each thread into the stream close phase for (int i = 0; i < writeThreads.length; i++) { synchronized(writeThreads[i]) { writeThreads[i].notifyAll(); } } // Wait for the threads to complete (one way or another) for (int i = 0; i < writeThreads.length; i++) { while (!writeThreads[i].isDone()) { wait(10); } } // check content has taken on thread's content reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); assertNotNull("Reader should now be available", reader); String checkContent = reader.getContentString(); assertEquals("Content check failed", threadContent, checkContent); }
Example 19
Source File: RemoteFileFolderLoaderTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Load 15 files; 1K size; 1 document sample; force binary storage */ @SuppressWarnings("unchecked") public void testLoad_15_16bytes() throws Exception { JSONObject body = new JSONObject(); body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath); body.put(FileFolderLoaderPost.KEY_MIN_FILE_SIZE, 16L); body.put(FileFolderLoaderPost.KEY_MAX_FILE_SIZE, 16L); body.put(FileFolderLoaderPost.KEY_MAX_UNIQUE_DOCUMENTS, 1L); body.put(FileFolderLoaderPost.KEY_FORCE_BINARY_STORAGE, Boolean.TRUE); Response response = null; try { AuthenticationUtil.pushAuthentication(); AuthenticationUtil.setFullyAuthenticatedUser("maggi"); response = sendRequest( new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "maggi"); } finally { AuthenticationUtil.popAuthentication(); } assertEquals("{\"count\":100}", response.getContentAsString()); // Check file(s) assertEquals(100, nodeService.countChildAssocs(loadHomeNodeRef, true)); // Consistent binary text String contentUrlCheck = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 16L); ContentReader readerCheck = new SpoofedTextContentReader(contentUrlCheck); String textCheck = readerCheck.getContentString(); // Size should be default List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef); for (FileInfo fileInfo : fileInfos) { NodeRef fileNodeRef = fileInfo.getNodeRef(); ContentReader reader = fileFolderService.getReader(fileNodeRef); // Expect storage in store assertTrue(reader.getContentUrl().startsWith(FileContentStore.STORE_PROTOCOL)); // Check text String text = reader.getContentString(); assertEquals("Text not the same.", textCheck, text); } }
Example 20
Source File: AbstractWritableContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testClosedState() throws Exception { ContentWriter writer = getWriter(); ContentReader readerBeforeWrite = writer.getReader(); // check that streams are not flagged as closed assertFalse("Reader stream should not be closed", readerBeforeWrite.isClosed()); assertFalse("Writer stream should not be closed", writer.isClosed()); // write some stuff writer.putContent("ABC"); // check that the write has been closed assertTrue("Writer stream should be closed", writer.isClosed()); // check that we can get a reader from the writer ContentReader readerAfterWrite = writer.getReader(); assertNotNull("No reader given by closed writer", readerAfterWrite); assertFalse("Before-content reader should not be affected by content updates", readerBeforeWrite.isClosed()); assertFalse("After content reader should not be closed", readerAfterWrite.isClosed()); // check that the instance is new each time ContentReader newReaderA = writer.getReader(); ContentReader newReaderB = writer.getReader(); assertFalse("Reader must always be a new instance", newReaderA == newReaderB); // check that the readers refer to the same URL assertEquals("Readers should refer to same URL", readerBeforeWrite.getContentUrl(), readerAfterWrite.getContentUrl()); // read their content try { readerBeforeWrite.getContentString(); } catch (Throwable e) { // The content doesn't exist for this reader } String contentCheck = readerAfterWrite.getContentString(); assertEquals("Incorrect content", "ABC", contentCheck); // check closed state of readers assertFalse("Before-content reader stream should not be closed", readerBeforeWrite.isClosed()); assertTrue("After-content reader should be closed after reading", readerAfterWrite.isClosed()); }