Skip to content

Commit

Permalink
Add test case for big files
Browse files Browse the repository at this point in the history
  • Loading branch information
lahsivjar committed Mar 11, 2019
1 parent c0b462b commit ea4642f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test/java/com/lahsivjar/GcpStorageWagonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
import com.google.common.io.Files;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
Expand Down Expand Up @@ -54,6 +55,11 @@ private void writeContentToFile(File file) throws IOException {
}
}

private void writeContentToFile(File file, int size) throws IOException {
final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile.setLength(size);
}

private void putFileUtil(GcpStorageWagon storageWagon, String destinationPath) throws IOException, ConnectionException,
AuthenticationException, AuthorizationException, ResourceDoesNotExistException, TransferFailedException {
final File sourceFile = sourceFolder.newFile(DUMMY_FILE_NAME);
Expand Down Expand Up @@ -108,6 +114,22 @@ public void testPut() throws IOException, ConnectionException, AuthenticationExc
Assert.assertTrue(blob.exists());
}

@Test
public void testPut_fileGreaterThan1MB() throws IOException, ConnectionException, AuthenticationException,
AuthorizationException, ResourceDoesNotExistException, TransferFailedException {
final Storage storage = fakeStorage();
final GcpStorageWagon storageWagon = new GcpStorageWagon(storage);
final File sourceFile = sourceFolder.newFile(DUMMY_FILE_NAME);

writeContentToFile(sourceFile, 1024 * 1024);
storageWagon.connect(fakeRepository());
storageWagon.put(sourceFile, DUMMY_FILE_NAME);

Blob blob = storage.get(BlobId.of(DUMMY_BUCKET, DUMMY_BASE_DIR + DUMMY_FILE_NAME));
Assert.assertNotNull(blob);
Assert.assertTrue(blob.exists());
}

@Test(expected = ResourceDoesNotExistException.class)
public void testPutNoResource() throws IOException, ConnectionException, AuthenticationException,
AuthorizationException, ResourceDoesNotExistException, TransferFailedException {
Expand Down

0 comments on commit ea4642f

Please sign in to comment.