public void testOverwriteAttachmentThrowsException() throws Exception { String testData = "First."; AttachmentId id = new AttachmentId("", "id_7"); AttachmentStore store = makeStoreWithData(id, testData); boolean exceptionThrown=false; try { // A second element added with the same ID should not write. writeStringDataToAttachmentStore(store, id, "Second"); } catch (IOException ex) { exceptionThrown=true; } //assertTrue(exceptionThrown); // Check that the database still contains the original entry assertEquals(testData, dataToString(store.getAttachment(id))); }
public void testStoreReturnsNullForNonexistantId() throws IOException { AttachmentStore store = newAttachmentStore(); AttachmentId id = new AttachmentId("", "some_madeup_id"); assertNull(store.getAttachment(id)); }
@Override protected void tearDown() throws Exception { super.tearDown(); org.apache.commons.io.FileUtils.deleteDirectory(path); // On Linux, it will be impossible to delete the directory until all of the // input streams have been closed. This is annoying, but gives us a nice // check to make sure everyone is behaving themselves. assertFalse(path.exists()); } }
protected AttachmentStore makeStoreWithData(AttachmentId id, String data) throws Exception { AttachmentStore store = newAttachmentStore(); writeStringDataToAttachmentStore(store, id, data); return store; }
public void testStoreCanStoreData() throws Exception { String testData = "some file data"; AttachmentId id = new AttachmentId("", "id_1"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); assertEquals(testData, dataToString(data)); }
public void testContentLengthMatchesDataSize() throws Exception { String testData = "blah blah blah"; AttachmentId id = new AttachmentId("", "id_2"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); assertEquals(testData.length(), data.getSize()); }
public void testGetStreamReturnsNewStream() throws Exception { String testData = "There's something quite peaceful about writing tests."; AttachmentId id = new AttachmentId("", "id_6"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); InputStream is1 = data.getInputStream(); InputStream is2 = data.getInputStream(); InputStream is3 = null; try { assertNotSame(is1, is2); int firstByte = is1.read(); assertSame(firstByte, is2.read()); // Check that a new input stream created now still has the same first // byte. is3 = data.getInputStream(); assertSame(firstByte, is3.read()); } finally { is1.close(); is2.close(); if (is3 != null) { is3.close(); } } }
public void testStoreCanDeleteData() throws Exception { String testData = "some day, I'm going to run out of test strings"; AttachmentId id = new AttachmentId("", "id_3"); AttachmentStore store = makeStoreWithData(id, testData); store.deleteAttachment(id); AttachmentData data = store.getAttachment(id); assertNull(data); }
@Override protected void setUp() throws Exception { path = FileUtils.createTemporaryDirectory(); super.setUp(); }
public void testContentLengthMatchesDataSize() throws Exception { String testData = "blah blah blah"; AttachmentId id = new AttachmentId("", "id_2"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); assertEquals(testData.length(), data.getSize()); }
public void testStoreCanStoreData() throws Exception { String testData = "some file data"; AttachmentId id = new AttachmentId("", "id_1"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); assertEquals(testData, dataToString(data)); }
public void testGetStreamReturnsNewStream() throws Exception { String testData = "There's something quite peaceful about writing tests."; AttachmentId id = new AttachmentId("", "id_6"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); InputStream is1 = data.getInputStream(); InputStream is2 = data.getInputStream(); InputStream is3 = null; try { assertNotSame(is1, is2); int firstByte = is1.read(); assertSame(firstByte, is2.read()); // Check that a new input stream created now still has the same first // byte. is3 = data.getInputStream(); assertSame(firstByte, is3.read()); } finally { is1.close(); is2.close(); if (is3 != null) { is3.close(); } } }
public void testStoreCanDeleteData() throws Exception { String testData = "some day, I'm going to run out of test strings"; AttachmentId id = new AttachmentId("", "id_3"); AttachmentStore store = makeStoreWithData(id, testData); store.deleteAttachment(id); AttachmentData data = store.getAttachment(id); assertNull(data); }
protected AttachmentStore makeStoreWithData(AttachmentId id, String data) throws Exception { AttachmentStore store = newAttachmentStore(); writeStringDataToAttachmentStore(store, id, data); return store; }
@Override protected void setUp() throws Exception { path = FileUtils.createTemporaryDirectory(); super.setUp(); }
public void testOverwriteAttachmentThrowsException() throws Exception { String testData = "First."; AttachmentId id = new AttachmentId("", "id_7"); AttachmentStore store = makeStoreWithData(id, testData); boolean exceptionThrown=false; try { // A second element added with the same ID should not write. writeStringDataToAttachmentStore(store, id, "Second"); } catch (IOException ex) { exceptionThrown=true; } //assertTrue(exceptionThrown); // Check that the database still contains the original entry assertEquals(testData, dataToString(store.getAttachment(id))); }
public void testAttachmentHasWorkingInputStream() throws Exception { String testData = "I suppose these strings don't actually need to be different"; AttachmentId id = new AttachmentId("", "id_5"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); BufferedReader reader = new BufferedReader(new InputStreamReader(data.getInputStream())); StringBuilder builder = new StringBuilder(); String line; try { while ((line = reader.readLine()) != null) { // This little snippet will discard any "\n" characters, but it shouldn't // matter. builder.append(line); } } finally { reader.close(); } assertEquals(testData, builder.toString()); }
public void testStoreReturnsNullForNonexistantId() throws IOException { AttachmentStore store = newAttachmentStore(); AttachmentId id = new AttachmentId("", "some_madeup_id"); assertNull(store.getAttachment(id)); }
@Override protected void tearDown() throws Exception { super.tearDown(); database.drop(); }
public void testAttachmentHasWorkingInputStream() throws Exception { String testData = "I suppose these strings don't actually need to be different"; AttachmentId id = new AttachmentId("", "id_5"); AttachmentStore store = makeStoreWithData(id, testData); AttachmentData data = store.getAttachment(id); BufferedReader reader = new BufferedReader(new InputStreamReader(data.getInputStream())); StringBuilder builder = new StringBuilder(); String line; try { while ((line = reader.readLine()) != null) { // This little snippet will discard any "\n" characters, but it shouldn't // matter. builder.append(line); } } finally { reader.close(); } assertEquals(testData, builder.toString()); }