@Theory public void theoryDoubleClose(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, is(resource())); OutputStream os = res.out(); os.close(); os.close(); }
@Theory public void theoryLeavesHaveEmptyListOfChildren(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); Collection<Resource> result = res.list(); assertThat(result, empty()); }
@Theory public void theoryLeavesHaveIstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); try (InputStream result = res.in()) { assertThat(result, notNullValue()); } }
@Theory public void theoryLeavesHaveOstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); try (OutputStream result = res.out()) { assertThat(result, notNullValue()); } }
@Theory public void theoryUndefinedHaveIstreamAndBecomeResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); try (InputStream result = res.in()) { assertThat(result, notNullValue()); assertThat(res, is(resource())); } }
@Theory public void theoryUndefinedHaveOstreamAndBecomeResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); try (OutputStream result = res.out()) { assertThat(result, notNullValue()); assertThat(res, is(resource())); } }
@Theory public void theoryHaveFile(String path) throws Exception { Resource res = getResource(path); assumeThat(res, resource()); File result = res.file(); assertThat(result, notNullValue()); }
@Theory public void theoryRenamedResourcesAreEquivalent(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, resource()); final byte[] expectedContent; try (InputStream in = res.in()) { expectedContent = IOUtils.toByteArray(in); } final Resource target = getUndefined(); assertThat(res.renameTo(target), is(true)); assertThat(target, resource()); final byte[] resultContent; try (InputStream in = target.in()) { resultContent = IOUtils.toByteArray(in); } assertThat(resultContent, equalTo(expectedContent)); }
@Theory public void theoryMultipleOutputStreamsAreSafe(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, is(resource())); final byte[] thread1Content = "This is the content for thread 1".getBytes(); final byte[] thread2Content = "Thread 2 has this content".getBytes(); try (OutputStream out1 = res.out()) { try (OutputStream out2 = res.out()) { for (int i = 0; i < thread1Content.length || i < thread2Content.length; i++) { if (i < thread1Content.length) { out1.write(thread1Content[i]); } if (i < thread2Content.length) { out2.write(thread2Content[i]); } } } } final byte[] resultContent; try (InputStream in = res.in()) { resultContent = IOUtils.toByteArray(in); } // 2 streams being written to concurrently should result in the resource containing // what was written to one of the two streams. assertThat(resultContent, anyOf(equalTo(thread1Content), equalTo(thread2Content))); }
@Theory public void theoryDeletedResourcesAreUndefined(String path) throws Exception { Resource res = getResource(path); assumeThat(res, resource()); assertThat(res.delete(), is(true)); assertThat(res, undefined()); }
@Theory public void theoryDoubleClose(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, is(resource())); OutputStream os = res.out(); os.close(); os.close(); }
@Theory public void theoryLeavesHaveOstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); try (OutputStream result = res.out()) { assertThat(result, notNullValue()); } }
@Theory public void theoryLeavesHaveIstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); try (InputStream result = res.in()) { assertThat(result, notNullValue()); } }
@Theory public void theoryLeavesHaveEmptyListOfChildren(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); Collection<Resource> result = res.list(); assertThat(result, empty()); }
@Theory public void theoryUndefinedHaveIstreamAndBecomeResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); try (InputStream result = res.in()) { assertThat(result, notNullValue()); assertThat(res, is(resource())); } }
@Theory public void theoryUndefinedHaveOstreamAndBecomeResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); try (OutputStream result = res.out()) { assertThat(result, notNullValue()); assertThat(res, is(resource())); } }
@Theory public void theoryHaveFile(String path) throws Exception { Resource res = getResource(path); assumeThat(res, resource()); File result = res.file(); assertThat(result, notNullValue()); }
@Theory public void theoryDeletedResourcesAreUndefined(String path) throws Exception { Resource res = getResource(path); assumeThat(res, resource()); assertThat(res.delete(), is(true)); assertThat(res, undefined()); }
@Test public void testLongQuery() throws Exception { standardData(); JDBCResourceStoreProperties config = getConfig(true, false); JDBCResourceStore store = new JDBCResourceStore(support.getDataSource(), config); store.setLockProvider(new NullLockProvider()); Resource r = store.get("DirC/DirF/DirG/FileH"); assertThat(r, not(nullValue())); assertThat(r, resource()); }
@Test public void testBasicResourceQuery() throws Exception { standardData(); JDBCResourceStoreProperties config = getConfig(true, false); JDBCResourceStore store = new JDBCResourceStore(support.getDataSource(), config); store.setLockProvider(new NullLockProvider()); Resource r = store.get("FileA"); assertThat(r, not(nullValue())); assertThat(r, resource()); }