Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Mar 7, 2016
1 parent 1e84435 commit b8b3bcc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 49 deletions.
10 changes: 5 additions & 5 deletions src/main/java/synapticloop/b2/B2ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import synapticloop.b2.response.B2GetUploadUrlResponse;
import synapticloop.b2.response.B2HideFileResponse;
import synapticloop.b2.response.B2ListFilesResponse;
import synapticloop.b2.util.Helper;
import synapticloop.b2.util.ChecksumHelper;

/**
* This is a wrapper class for the underlying calls to the request/response
Expand Down Expand Up @@ -327,7 +327,7 @@ public B2FileResponse uploadFile(String bucketId, String fileName, HttpEntity en
public B2FileResponse uploadFile(String bucketId, String fileName, File file, String mimeType, Map<String, String> fileInfo) throws B2ApiException {
B2GetUploadUrlResponse b2GetUploadUrlResponse = new B2GetUploadUrlRequest(client, b2AuthorizeAccountResponse, bucketId).getResponse();
return new B2UploadFileRequest(client, b2AuthorizeAccountResponse, b2GetUploadUrlResponse, fileName, file,
Helper.calculateSha1(file), mimeType, fileInfo).getResponse();
ChecksumHelper.calculateSha1(file), mimeType, fileInfo).getResponse();
}

/**
Expand All @@ -347,7 +347,7 @@ public B2FileResponse uploadFile(String bucketId, String fileName, File file, St
public B2FileResponse uploadFile(String bucketId, String fileName, File file, Map<String, String> fileInfo) throws B2ApiException {
B2GetUploadUrlResponse b2GetUploadUrlResponse = new B2GetUploadUrlRequest(client, b2AuthorizeAccountResponse, bucketId).getResponse();
return new B2UploadFileRequest(client, b2AuthorizeAccountResponse, b2GetUploadUrlResponse, fileName, file,
Helper.calculateSha1(file), fileInfo).getResponse();
ChecksumHelper.calculateSha1(file), fileInfo).getResponse();
}

/**
Expand All @@ -369,7 +369,7 @@ public B2FileResponse uploadFile(String bucketId, String fileName, File file, Ma
public B2FileResponse uploadFile(String bucketId, String fileName, File file, String mimeType) throws B2ApiException {
B2GetUploadUrlResponse b2GetUploadUrlResponse = new B2GetUploadUrlRequest(client, b2AuthorizeAccountResponse, bucketId).getResponse();
return new B2UploadFileRequest(client, b2AuthorizeAccountResponse, b2GetUploadUrlResponse, fileName, file,
Helper.calculateSha1(file), mimeType).getResponse();
ChecksumHelper.calculateSha1(file), mimeType).getResponse();
}

/**
Expand All @@ -388,7 +388,7 @@ public B2FileResponse uploadFile(String bucketId, String fileName, File file, St
public B2FileResponse uploadFile(String bucketId, String fileName, File file) throws B2ApiException {
B2GetUploadUrlResponse b2GetUploadUrlResponse = new B2GetUploadUrlRequest(client, b2AuthorizeAccountResponse, bucketId).getResponse();
return new B2UploadFileRequest(client, b2AuthorizeAccountResponse, b2GetUploadUrlResponse, fileName,
file, Helper.calculateSha1(file)).getResponse();
file, ChecksumHelper.calculateSha1(file)).getResponse();
}


Expand Down
28 changes: 9 additions & 19 deletions src/test/java/synapticloop/b2/helper/B2TestHelper.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
package synapticloop.b2.helper;

import org.apache.http.impl.client.HttpClients;
import synapticloop.b2.BucketType;
import synapticloop.b2.exception.B2ApiException;
import synapticloop.b2.request.*;
import synapticloop.b2.response.*;
import synapticloop.b2.util.ChecksumHelper;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;

import org.apache.http.impl.client.HttpClients;

import synapticloop.b2.BucketType;
import synapticloop.b2.exception.B2ApiException;
import synapticloop.b2.request.B2AuthorizeAccountRequest;
import synapticloop.b2.request.B2CreateBucketRequest;
import synapticloop.b2.request.B2DeleteBucketRequest;
import synapticloop.b2.request.B2DeleteFileVersionRequest;
import synapticloop.b2.request.B2GetUploadUrlRequest;
import synapticloop.b2.request.B2UploadFileRequest;
import synapticloop.b2.response.B2AuthorizeAccountResponse;
import synapticloop.b2.response.B2BucketResponse;
import synapticloop.b2.response.B2DeleteFileVersionResponse;
import synapticloop.b2.response.B2FileResponse;
import synapticloop.b2.response.B2GetUploadUrlResponse;
import synapticloop.b2.util.Helper;

public class B2TestHelper {
public static final String B2_BUCKET_PREFIX = "b2api-test-";
public static final String B2_ACCOUNT_ID = "B2_ACCOUNT_ID";
Expand Down Expand Up @@ -131,7 +121,7 @@ public static B2FileResponse uploadTemporaryFileToBucket(String bucketId) throws
throw new B2ApiException("Could not create temporary file", ioex);
}
return(new B2UploadFileRequest(HttpClients.createDefault(), getB2AuthorizeAccountResponse(),
b2GetUploadUrlResponse, file.getName(), file, Helper.calculateSha1(file)).getResponse());
b2GetUploadUrlResponse, file.getName(), file, ChecksumHelper.calculateSha1(file)).getResponse());
}

// public static B2FileResponse uploadTemporaryFileToBucketWithPath(String bucketId) throws B2Exception {
Expand Down Expand Up @@ -173,7 +163,7 @@ public static B2FileResponse uploadTemporaryFileToBucket(String bucketId, Map<St
throw new B2ApiException("Could not create temporary file", ioex);
}
return(new B2UploadFileRequest(HttpClients.createDefault(), getB2AuthorizeAccountResponse(), b2GetUploadUrlResponse, file.getName(), file,
Helper.calculateSha1(file), fileInfo).getResponse());
ChecksumHelper.calculateSha1(file), fileInfo).getResponse());
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package synapticloop.b2.request;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.apache.http.impl.client.HttpClients;
import org.junit.Test;

import synapticloop.b2.exception.B2ApiException;
import synapticloop.b2.helper.B2TestHelper;
import synapticloop.b2.response.B2BucketResponse;
import synapticloop.b2.response.B2DeleteFileVersionResponse;
import synapticloop.b2.response.B2DownloadFileResponse;
import synapticloop.b2.response.B2FileResponse;
import synapticloop.b2.response.B2GetUploadUrlResponse;
import synapticloop.b2.util.Helper;
import synapticloop.b2.response.*;
import synapticloop.b2.util.ChecksumHelper;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import static org.junit.Assert.assertEquals;

public class B2DownloadFileRequestTest {
private B2BucketResponse randomPrivateBucket = null;
Expand All @@ -37,7 +32,7 @@ public void testDownloadByFilePath() throws Exception {
B2FileResponse b2UploadFileResponse = new B2UploadFileRequest(HttpClients.createDefault(),
B2TestHelper.getB2AuthorizeAccountResponse(),
b2GetUploadUrlResponse,
testFileName, file, Helper.calculateSha1(file)).getResponse();
testFileName, file, ChecksumHelper.calculateSha1(file)).getResponse();

String fileName = b2UploadFileResponse.getFileName();
String fileId = b2UploadFileResponse.getFileId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package synapticloop.b2.request;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.impl.client.HttpClients;
import org.junit.Test;

import synapticloop.b2.helper.B2TestHelper;
import synapticloop.b2.response.B2BucketResponse;
import synapticloop.b2.response.B2DeleteFileVersionResponse;
import synapticloop.b2.response.B2FileResponse;
import synapticloop.b2.response.B2GetUploadUrlResponse;
import synapticloop.b2.util.Helper;
import synapticloop.b2.util.ChecksumHelper;

import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;


public class B2UploadAndDeleteFileRequestTest {
Expand All @@ -31,7 +30,7 @@ public void testFileUpload() throws Exception {
fileWriter.close();
B2FileResponse b2UploadFileResponse = new B2UploadFileRequest(HttpClients.createDefault(),
B2TestHelper.getB2AuthorizeAccountResponse(), b2GetUploadUrlResponse, file.getName(), file,
Helper.calculateSha1(file)).getResponse();
ChecksumHelper.calculateSha1(file)).getResponse();

String fileName = b2UploadFileResponse.getFileName();
String fileId = b2UploadFileResponse.getFileId();
Expand Down Expand Up @@ -60,7 +59,7 @@ public void testFileUploadWithInfo() throws Exception {

B2FileResponse b2UploadFileResponse = new B2UploadFileRequest(HttpClients.createDefault(),
B2TestHelper.getB2AuthorizeAccountResponse(), b2GetUploadUrlResponse, file.getName(), file,
Helper.calculateSha1(file), fileInfo).getResponse();
ChecksumHelper.calculateSha1(file), fileInfo).getResponse();

String fileName = b2UploadFileResponse.getFileName();
String fileId = b2UploadFileResponse.getFileId();
Expand Down

0 comments on commit b8b3bcc

Please sign in to comment.