Search in sources :

Example 6 with GCPBlob

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.
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) GCPBlob(org.webpieces.googlecloud.storage.api.GCPBlob) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 GCPBlob (org.webpieces.googlecloud.storage.api.GCPBlob)6 ReadableByteChannel (java.nio.channels.ReadableByteChannel)3 ArrayList (java.util.ArrayList)2 CopyInterface (org.webpieces.googlecloud.storage.api.CopyInterface)1 GCPStorage (org.webpieces.googlecloud.storage.api.GCPStorage)1