use of okio.BufferedSource in project Store by NYTimes.
the class MultiTest method createAndPopulateTestFileSystem.
private FileSystem createAndPopulateTestFileSystem() throws IOException {
File baseDir = createTempDir();
FileSystem fileSystem = FileSystemFactory.create(baseDir);
for (String path : fileData.keySet()) {
for (String data : fileData.get(path)) {
BufferedSource source = source(data);
fileSystem.write(path, source);
source.close();
}
}
assertThat(fileSystem.list("/").size()).isEqualTo(fileData.size());
return fileSystem;
}
use of okio.BufferedSource in project Store by NYTimes.
the class SourceFilerReaderWriterStoreTest method testSimple.
@Test
public void testSimple() {
MockitoAnnotations.initMocks(this);
GsonSourceParser<Foo> parser = new GsonSourceParser<>(new Gson(), Foo.class);
Store<Foo, BarCode> simpleStore = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(fileReader, fileWriter).fetcher(fetcher).parser(parser).open();
Foo foo = new Foo();
foo.bar = barCode.getKey();
String sourceData = new Gson().toJson(foo);
BufferedSource source = source(sourceData);
Single<BufferedSource> value = Single.just(source);
when(fetcher.fetch(barCode)).thenReturn(value);
when(fileReader.read(barCode)).thenReturn(Maybe.<BufferedSource>empty()).thenReturn(value.toMaybe());
when(fileWriter.write(barCode, source)).thenReturn(Single.just(true));
Foo result = simpleStore.get(barCode).blockingGet();
assertThat(result.bar).isEqualTo(KEY);
result = simpleStore.get(barCode).blockingGet();
assertThat(result.bar).isEqualTo(KEY);
verify(fetcher, times(1)).fetch(barCode);
}
use of okio.BufferedSource in project Store by NYTimes.
the class JacksonSourceParserStoreTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
BufferedSource bufferedSource = source(sourceString);
assertNotNull(bufferedSource);
when(fetcher.fetch(barCode)).thenReturn(Single.just(bufferedSource));
when(persister.read(barCode)).thenReturn(Maybe.<BufferedSource>empty()).thenReturn(Maybe.just(bufferedSource));
when(persister.write(barCode, bufferedSource)).thenReturn(Single.just(true));
}
use of okio.BufferedSource in project Store by NYTimes.
the class JacksonSourceParserStoreTest method testCustomJsonFactorySourceParser.
@Test
public void testCustomJsonFactorySourceParser() {
JsonFactory jsonFactory = new JsonFactory();
Parser<BufferedSource, Foo> parser = JacksonParserFactory.createSourceParser(jsonFactory, Foo.class);
Store<Foo, BarCode> store = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
Foo result = store.get(barCode).blockingGet();
validateFoo(result);
verify(fetcher, times(1)).fetch(barCode);
}
use of okio.BufferedSource in project Store by NYTimes.
the class JacksonSourceParserStoreTest method testDefaultJacksonSourceParser.
@Test
public void testDefaultJacksonSourceParser() {
Parser<BufferedSource, Foo> parser = JacksonParserFactory.createSourceParser(Foo.class);
Store<Foo, BarCode> store = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
Foo result = store.get(barCode).blockingGet();
validateFoo(result);
verify(fetcher, times(1)).fetch(barCode);
}
Aggregations