@Override public void addListener(ContentStreamListener listener) { delegatee.addListener(listener); }
@Override public void addListener(ContentStreamListener listener) { delegatee.addListener(listener); }
@Override public void addListener(ContentStreamListener listener) { this.cacheWriter.addListener(listener); }
@Override public void addListener(ContentStreamListener listener) { this.cacheWriter.addListener(listener); }
@Test(expected=RuntimeException.class) // Check that exceptions raised by the backing store's putContent(ContentReader) // aren't swallowed and can therefore cause the transaction to fail. public void exceptionRaisedWhenCopyingTempToBackingStoreIsPropogatedCorrectly() throws ContentIOException, IOException { cachingStore = new CachingContentStore(backingStore, cache, true); ContentContext ctx = ContentContext.NULL_CONTEXT; ContentWriter bsWriter = mock(ContentWriter.class); when(backingStore.getWriter(ctx)).thenReturn(bsWriter); when(bsWriter.getContentUrl()).thenReturn("url"); ContentWriter cacheWriter = mock(ContentWriter.class); when(cache.getWriter("url")).thenReturn(cacheWriter); ContentReader readerFromCacheWriter = mock(ContentReader.class); when(cacheWriter.getReader()).thenReturn(readerFromCacheWriter); doThrow(new RuntimeException()).when(bsWriter).putContent(any(ContentReader.class)); cachingStore.getWriter(ctx); // Get the stream listener and trigger it ArgumentCaptor<ContentStreamListener> arg = ArgumentCaptor.forClass(ContentStreamListener.class); verify(cacheWriter).addListener(arg.capture()); // Simulate a stream close arg.getValue().contentStreamClosed(); }
@Test public void encodingAttrsCopiedToBackingStoreWriter() { cachingStore = new CachingContentStore(backingStore, cache, true); ContentContext ctx = ContentContext.NULL_CONTEXT; ContentWriter bsWriter = mock(ContentWriter.class); when(backingStore.getWriter(ctx)).thenReturn(bsWriter); when(bsWriter.getContentUrl()).thenReturn("url"); ContentWriter cacheWriter = mock(ContentWriter.class); when(cache.getWriter("url")).thenReturn(cacheWriter); ContentReader readerFromCacheWriter = mock(ContentReader.class); when(cacheWriter.getReader()).thenReturn(readerFromCacheWriter); when(cacheWriter.getEncoding()).thenReturn("UTF-8"); when(cacheWriter.getLocale()).thenReturn(Locale.UK); when(cacheWriter.getMimetype()).thenReturn("not/real/mimetype"); cachingStore.getWriter(ctx); // Get the stream listener and trigger it ArgumentCaptor<ContentStreamListener> arg = ArgumentCaptor.forClass(ContentStreamListener.class); verify(cacheWriter).addListener(arg.capture()); // Simulate a stream close arg.getValue().contentStreamClosed(); verify(bsWriter).setEncoding("UTF-8"); verify(bsWriter).setLocale(Locale.UK); verify(bsWriter).setMimetype("not/real/mimetype"); }
verify(cacheWriter).addListener(arg.capture());
verify(cacheWriter).addListener(arg.capture());
/** * Checks that the writer can have a listener attached */ @Test public void testWriteStreamListener() throws Exception { ContentWriter writer = getWriter(); final boolean[] streamClosed = new boolean[] {false}; // has to be final ContentStreamListener listener = new ContentStreamListener() { public void contentStreamClosed() throws ContentIOException { streamClosed[0] = true; } }; writer.addListener(listener); // write some content writer.putContent("ABC"); // check that the listener was called assertTrue("Write stream listener was not called for the stream close", streamClosed[0]); }
writer.addListener(listener);
writer.addListener(listener);