Search in sources :

Example 1 with GCPBlob

use of org.webpieces.googlecloud.storage.api.GCPBlob in project webpieces by deanhiller.

the class TestLocalStorage method testCopyFromClassPath.

@Test
public void testCopyFromClassPath() throws IOException {
    String bucketName = "testbucket";
    String blobName = "mytest.txt";
    String copyBlobName = "mytest_copy.txt";
    Storage.CopyRequest request = Storage.CopyRequest.newBuilder().setSource(BlobId.of(bucketName, blobName)).setTarget(BlobId.of(bucketName, copyBlobName)).build();
    Page<GCPBlob> testbucket = instance.list("copybucket");
    CopyInterface copy = instance.copy(request);
    ReadableByteChannel readFile = instance.reader("copybucket", "mytest_copy.txt");
    InputStream i = Channels.newInputStream(readFile);
    String text = new BufferedReader(new InputStreamReader(i, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
    // Passed.
    Assert.assertEquals("Some Test", text);
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) GCPStorage(org.webpieces.googlecloud.storage.api.GCPStorage) GCPBlob(org.webpieces.googlecloud.storage.api.GCPBlob) CopyInterface(org.webpieces.googlecloud.storage.api.CopyInterface) Test(org.junit.Test)

Example 2 with GCPBlob

use of org.webpieces.googlecloud.storage.api.GCPBlob in project webpieces by deanhiller.

the class TestLocalStorage method testGetBlobFileSystem.

@Test
public void testGetBlobFileSystem() throws IOException {
    // create a file
    BlobId id = BlobId.of("testbucket", "fileSystemFile.txt");
    writeFile(id);
    GCPBlob bucket = instance.get("testbucket", "fileSystemFile.txt");
    Assert.assertEquals("fileSystemFile.txt", bucket.getName());
}
Also used : GCPBlob(org.webpieces.googlecloud.storage.api.GCPBlob) Test(org.junit.Test)

Example 3 with GCPBlob

use of org.webpieces.googlecloud.storage.api.GCPBlob in project webpieces by deanhiller.

the class TestLocalStorage method testGetBlobClassPath.

@Test
public void testGetBlobClassPath() {
    GCPBlob testbucket = instance.get("testbucket", "mytest.txt");
    Assert.assertEquals("mytest.txt", testbucket.getName());
}
Also used : GCPBlob(org.webpieces.googlecloud.storage.api.GCPBlob) Test(org.junit.Test)

Example 4 with GCPBlob

use of org.webpieces.googlecloud.storage.api.GCPBlob in project webpieces by deanhiller.

the class TestLocalStorage method validateFileNotFoundReturnsNullBlob.

@Test
public void validateFileNotFoundReturnsNullBlob() {
    GCPBlob basket = instance.get("backet", "non-existent");
    Assert.assertNull(basket);
}
Also used : GCPBlob(org.webpieces.googlecloud.storage.api.GCPBlob) Test(org.junit.Test)

Example 5 with GCPBlob

use of org.webpieces.googlecloud.storage.api.GCPBlob in project webpieces by deanhiller.

the class TestLocalStorage method addFileToBucketAndThenListFiles.

@Test
public void addFileToBucketAndThenListFiles() throws IOException {
    instance.list("ListFilebucket");
    writeFile(BlobId.of("ListFilebucket", "mytest1.txt"));
    GCPBlob bucket = instance.get("ListFilebucket", "mytest1.txt");
    // passed.
    Assert.assertEquals("mytest1.txt", bucket.getName());
    ReadableByteChannel readFile = instance.reader("ListFilebucket", "mytest1.txt");
    InputStream i = Channels.newInputStream(readFile);
    String text = new BufferedReader(new InputStreamReader(i, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
    Page<GCPBlob> listfilebucket = instance.list("ListFilebucket");
    Iterable<GCPBlob> values = listfilebucket.getValues();
    Iterator<GCPBlob> iter = values.iterator();
    List<String> list = new ArrayList<>();
    while (iter.hasNext()) {
        list.add(iter.next().getName());
    }
    Assert.assertEquals(1, list.size());
}
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