use of org.webpieces.googlecloud.storage.api.GCPBlob in project webpieces by deanhiller.
the class TestLocalStorage method addFileThenReadThenDeleteThenListFiles.
@Test
public void addFileThenReadThenDeleteThenListFiles() throws IOException {
writeFile(BlobId.of("AddReadDeleteListbucket", "mytest1.txt"));
GCPBlob bucket = instance.get("AddReadDeleteListbucket", "mytest1.txt");
// passed.
Assert.assertEquals("mytest1.txt", bucket.getName());
ReadableByteChannel readFile = instance.reader("AddReadDeleteListbucket", "mytest1.txt");
InputStream i = Channels.newInputStream(readFile);
String text = new BufferedReader(new InputStreamReader(i, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
// Passed.
Assert.assertEquals("testing a bitch", text);
boolean success = instance.delete("AddReadDeleteListbucket", "mytest1.txt");
// passed.
Assert.assertEquals(true, success);
Page<GCPBlob> testbucket = instance.list("AddReadDeleteListbucket");
Iterable<GCPBlob> values = testbucket.getValues();
Iterator<GCPBlob> iter = values.iterator();
List<String> list = new ArrayList<>();
while (iter.hasNext()) {
list.add(iter.next().getName());
}
// length of the blob should be original length.
// testing on testbucket directory
Assert.assertEquals(0, list.size());
// with 2 files already existed.
}
Aggregations