http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/domain/UploadUrlResponse.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/domain/UploadUrlResponse.java b/b2/src/main/java/org/jclouds/b2/domain/UploadUrlResponse.java deleted file mode 100644 index 36712ca..0000000 --- a/b2/src/main/java/org/jclouds/b2/domain/UploadUrlResponse.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.domain; - -import java.net.URI; - -import org.jclouds.json.SerializedNames; - -import com.google.auto.value.AutoValue; - -@AutoValue -public abstract class UploadUrlResponse { - public abstract String bucketId(); - public abstract URI uploadUrl(); - public abstract String authorizationToken(); - - @SerializedNames({"bucketId", "uploadUrl", "authorizationToken"}) - public static UploadUrlResponse create(String bucketId, URI uploadUrl, String authorizationToken) { - return new AutoValue_UploadUrlResponse(bucketId, uploadUrl, authorizationToken); - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/features/AuthorizationApi.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/features/AuthorizationApi.java b/b2/src/main/java/org/jclouds/b2/features/AuthorizationApi.java deleted file mode 100644 index c232e47..0000000 --- a/b2/src/main/java/org/jclouds/b2/features/AuthorizationApi.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.b2.domain.Authorization; -import org.jclouds.rest.annotations.RequestFilters; - -public interface AuthorizationApi { - @Named("b2_authorize_account") - @GET - @Path("/b2api/v1/b2_authorize_account") - @RequestFilters(BasicAuthentication.class) - @Consumes(APPLICATION_JSON) - Authorization authorizeAccount(); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/features/BucketApi.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/features/BucketApi.java b/b2/src/main/java/org/jclouds/b2/features/BucketApi.java deleted file mode 100644 index 2e6d5de..0000000 --- a/b2/src/main/java/org/jclouds/b2/features/BucketApi.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.blobstore.attr.BlobScope; -import org.jclouds.b2.domain.Bucket; -import org.jclouds.b2.domain.BucketList; -import org.jclouds.b2.domain.BucketType; -import org.jclouds.b2.filters.RequestAuthorization; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.PayloadParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.binders.BindToJsonPayload; - -@RequestFilters(RequestAuthorization.class) -@BlobScope(CONTAINER) -@Consumes(APPLICATION_JSON) -@Produces(APPLICATION_JSON) -public interface BucketApi { - @Named("b2_create_bucket") - @POST - @Path("/b2api/v1/b2_create_bucket") - @MapBinder(BindToJsonPayload.class) - @PayloadParams(keys = {"accountId"}, values = {"{jclouds.identity}"}) - Bucket createBucket(@PayloadParam("bucketName") String bucketName, @PayloadParam("bucketType") BucketType bucketType); - - @Named("b2_delete_bucket") - @POST - @Path("/b2api/v1/b2_delete_bucket") - @MapBinder(BindToJsonPayload.class) - @PayloadParams(keys = {"accountId"}, values = {"{jclouds.identity}"}) - @Fallback(NullOnNotFoundOr404.class) - Bucket deleteBucket(@PayloadParam("bucketId") String bucketId); - - @Named("b2_update_bucket") - @POST - @Path("/b2api/v1/b2_update_bucket") - @MapBinder(BindToJsonPayload.class) - @PayloadParams(keys = {"accountId"}, values = {"{jclouds.identity}"}) - Bucket updateBucket(@PayloadParam("bucketId") String bucketId, @PayloadParam("bucketType") BucketType bucketType); - - @Named("b2_list_buckets") - @POST - @Path("/b2api/v1/b2_list_buckets") - @MapBinder(BindToJsonPayload.class) - @PayloadParams(keys = {"accountId"}, values = {"{jclouds.identity}"}) - BucketList listBuckets(); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/features/MultipartApi.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/features/MultipartApi.java b/b2/src/main/java/org/jclouds/b2/features/MultipartApi.java deleted file mode 100644 index 510fd0f..0000000 --- a/b2/src/main/java/org/jclouds/b2/features/MultipartApi.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER; - -import java.util.Collection; -import java.util.Map; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.jclouds.blobstore.attr.BlobScope; -import org.jclouds.io.Payload; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.b2.binders.UploadPartBinder; -import org.jclouds.b2.domain.B2Object; -import org.jclouds.b2.domain.GetUploadPartResponse; -import org.jclouds.b2.domain.ListPartsResponse; -import org.jclouds.b2.domain.ListUnfinishedLargeFilesResponse; -import org.jclouds.b2.domain.MultipartUploadResponse; -import org.jclouds.b2.domain.UploadPartResponse; -import org.jclouds.b2.filters.RequestAuthorization; -import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.binders.BindToJsonPayload; - -@BlobScope(CONTAINER) -@Consumes(APPLICATION_JSON) -public interface MultipartApi { - @Named("b2_start_large_file") - @POST - @Path("/b2api/v1/b2_start_large_file") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Produces(APPLICATION_JSON) - MultipartUploadResponse startLargeFile(@PayloadParam("bucketId") String bucketId, @PayloadParam("fileName") String fileName, @PayloadParam("contentType") String contentType, @PayloadParam("fileInfo") Map<String, String> fileInfo); - - @Named("b2_cancel_large_file") - @POST - @Path("/b2api/v1/b2_cancel_large_file") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Produces(APPLICATION_JSON) - B2Object cancelLargeFile(@PayloadParam("fileId") String fileId); - - @Named("b2_finish_large_file") - @POST - @Path("/b2api/v1/b2_finish_large_file") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Produces(APPLICATION_JSON) - B2Object finishLargeFile(@PayloadParam("fileId") String fileId, @PayloadParam("partSha1Array") Collection<String> contentSha1List); - - @Named("b2_get_upload_part_url") - @POST - @Path("/b2api/v1/b2_get_upload_part_url") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Produces(APPLICATION_JSON) - GetUploadPartResponse getUploadPartUrl(@PayloadParam("fileId") String fileId); - - @Named("b2_upload_part") - @POST - @MapBinder(UploadPartBinder.class) - UploadPartResponse uploadPart(@PayloadParam("response") GetUploadPartResponse response, @HeaderParam("X-Bz-Part-Number") int partNumber, @Nullable @PayloadParam("contentSha1") String sha1, @PayloadParam("payload") Payload payload); - - @Named("b2_list_parts") - @POST - @Path("/b2api/v1/b2_list_parts") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Produces(APPLICATION_JSON) - ListPartsResponse listParts(@PayloadParam("fileId") String fileId, @PayloadParam("startPartNumber") @Nullable Integer startPartNumber, @PayloadParam("maxPartCount") @Nullable Integer maxPartCount); - - @Named("b2_list_unfinished_large_files") - @POST - @Path("/b2api/v1/b2_list_unfinished_large_files") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Produces(APPLICATION_JSON) - ListUnfinishedLargeFilesResponse listUnfinishedLargeFiles(@PayloadParam("bucketId") String bucketId, @PayloadParam("startFileId") @Nullable String startFileId, @PayloadParam("maxFileCount") @Nullable Integer maxFileCount); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/features/ObjectApi.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/features/ObjectApi.java b/b2/src/main/java/org/jclouds/b2/features/ObjectApi.java deleted file mode 100644 index c8379eb..0000000 --- a/b2/src/main/java/org/jclouds/b2/features/ObjectApi.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER; - -import java.util.Map; -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.blobstore.attr.BlobScope; -import org.jclouds.http.options.GetOptions; -import org.jclouds.io.Payload; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.b2.binders.UploadFileBinder; -import org.jclouds.b2.domain.B2Object; -import org.jclouds.b2.domain.B2ObjectList; -import org.jclouds.b2.domain.DeleteFileResponse; -import org.jclouds.b2.domain.HideFileResponse; -import org.jclouds.b2.domain.UploadFileResponse; -import org.jclouds.b2.domain.UploadUrlResponse; -import org.jclouds.b2.filters.RequestAuthorization; -import org.jclouds.b2.filters.RequestAuthorizationDownload; -import org.jclouds.b2.functions.ParseB2ObjectFromResponse; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.binders.BindToJsonPayload; - -@BlobScope(CONTAINER) -public interface ObjectApi { - @Named("b2_get_upload_url") - @POST - @Path("/b2api/v1/b2_get_upload_url") - @RequestFilters(RequestAuthorization.class) - @MapBinder(BindToJsonPayload.class) - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - UploadUrlResponse getUploadUrl(@PayloadParam("bucketId") String bucketId); - - @Named("b2_upload_file") - @POST - @MapBinder(UploadFileBinder.class) - @Consumes(APPLICATION_JSON) - UploadFileResponse uploadFile(@PayloadParam("uploadUrl") UploadUrlResponse uploadUrl, @PayloadParam("fileName") String fileName, @Nullable @PayloadParam("contentSha1") String contentSha1, @PayloadParam("fileInfo") Map<String, String> fileInfo, Payload payload); - - @Named("b2_delete_file_version") - @POST - @Path("/b2api/v1/b2_delete_file_version") - @MapBinder(BindToJsonPayload.class) - @RequestFilters(RequestAuthorization.class) - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - DeleteFileResponse deleteFileVersion(@PayloadParam("fileName") String fileName, @PayloadParam("fileId") String fileId); - - @Named("b2_get_file_info") - @POST - @Path("/b2api/v1/b2_get_file_info") - @MapBinder(BindToJsonPayload.class) - @RequestFilters(RequestAuthorization.class) - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - @Fallback(NullOnNotFoundOr404.class) - B2Object getFileInfo(@PayloadParam("fileId") String fileId); - - @Named("b2_download_file_by_id") - @GET - @Path("/b2api/v1/b2_download_file_by_id") - @RequestFilters(RequestAuthorizationDownload.class) - @ResponseParser(ParseB2ObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - B2Object downloadFileById(@QueryParam("fileId") String fileId); - - @Named("b2_download_file_by_id") - @GET - @Path("/b2api/v1/b2_download_file_by_id") - @RequestFilters(RequestAuthorizationDownload.class) - @ResponseParser(ParseB2ObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - B2Object downloadFileById(@QueryParam("fileId") String fileId, GetOptions options); - - @Named("b2_download_file_by_name") - @GET - @Path("/file/{bucketName}/{fileName}") - @RequestFilters(RequestAuthorizationDownload.class) - @ResponseParser(ParseB2ObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - B2Object downloadFileByName(@PathParam("bucketName") String bucketName, @PathParam("fileName") String fileName); - - @Named("b2_download_file_by_name") - @GET - @Path("/file/{bucketName}/{fileName}") - @RequestFilters(RequestAuthorizationDownload.class) - @ResponseParser(ParseB2ObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - B2Object downloadFileByName(@PathParam("bucketName") String bucketName, @PathParam("fileName") String fileName, GetOptions options); - - @Named("b2_list_file_names") - @GET - @Path("/b2api/v1/b2_list_file_names") - @MapBinder(BindToJsonPayload.class) - @RequestFilters(RequestAuthorization.class) - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - B2ObjectList listFileNames(@PayloadParam("bucketId") String bucketId, @PayloadParam("startFileName") @Nullable String startFileName, @PayloadParam("maxFileCount") @Nullable Integer maxFileCount); - - @Named("b2_list_file_versions") - @GET - @Path("/b2api/v1/b2_list_file_versions") - @MapBinder(BindToJsonPayload.class) - @RequestFilters(RequestAuthorization.class) - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - B2ObjectList listFileVersions(@PayloadParam("bucketId") String bucketId, @PayloadParam("startFileId") @Nullable String startFileId, @PayloadParam("startFileName") @Nullable String startFileName, @PayloadParam("maxFileCount") @Nullable Integer maxFileCount); - - @Named("b2_hide_file") - @POST - @Path("/b2api/v1/b2_hide_file") - @MapBinder(BindToJsonPayload.class) - @RequestFilters(RequestAuthorization.class) - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - HideFileResponse hideFile(@PayloadParam("bucketId") String bucketId, @PayloadParam("fileName") String fileName); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/filters/B2RetryHandler.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/filters/B2RetryHandler.java b/b2/src/main/java/org/jclouds/b2/filters/B2RetryHandler.java deleted file mode 100644 index e58d712..0000000 --- a/b2/src/main/java/org/jclouds/b2/filters/B2RetryHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.filters; - -import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; -import static org.jclouds.http.HttpUtils.releasePayload; - -import javax.annotation.Resource; -import javax.inject.Inject; - -import org.jclouds.b2.B2Api; -import org.jclouds.b2.domain.GetUploadPartResponse; -import org.jclouds.b2.domain.UploadUrlResponse; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.handlers.BackoffLimitedRetryHandler; -import org.jclouds.logging.Logger; - -import com.google.common.net.HttpHeaders; -import com.google.inject.Singleton; - -@Singleton -public final class B2RetryHandler extends BackoffLimitedRetryHandler implements HttpRequestFilter { - private final B2Api api; - - @Resource - private Logger logger = Logger.NULL; - - @Inject - B2RetryHandler(B2Api api) { - this.api = api; - } - - @Override - public HttpRequest filter(HttpRequest request) throws HttpException { - HttpRequest.Builder<?> builder = request.toBuilder(); - - // B2 requires retrying on a different storage node for uploads - String path = request.getEndpoint().getPath(); - if (path.startsWith("/b2api/v1/b2_upload_file")) { - String bucketId = path.split("/")[4]; - UploadUrlResponse uploadUrl = api.getObjectApi().getUploadUrl(bucketId); - builder.endpoint(uploadUrl.uploadUrl()) - .replaceHeader(HttpHeaders.AUTHORIZATION, uploadUrl.authorizationToken()); - } else if (path.startsWith("/b2api/v1/b2_upload_part")) { - String fileId = path.split("/")[4]; - GetUploadPartResponse uploadUrl = api.getMultipartApi().getUploadPartUrl(fileId); - builder.endpoint(uploadUrl.uploadUrl()) - .replaceHeader(HttpHeaders.AUTHORIZATION, uploadUrl.authorizationToken()); - } - - return builder.build(); - } - - @Override - public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { - boolean retry = false; - try { - byte[] data = closeClientButKeepContentStream(response); - switch (response.getStatusCode()) { - case 500: - case 503: - retry = super.shouldRetryRequest(command, response); - break; - default: - break; - } - } finally { - releasePayload(response); - } - return retry; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorization.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorization.java b/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorization.java deleted file mode 100644 index b403a59..0000000 --- a/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorization.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.filters; - -import java.net.URI; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.collect.Memoized; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpRequestFilter; -import org.jclouds.b2.domain.Authorization; - -import com.google.common.base.Supplier; -import com.google.common.net.HttpHeaders; - -@Singleton -public final class RequestAuthorization implements HttpRequestFilter { - private final Supplier<Authorization> auth; - - @Inject - RequestAuthorization(@Memoized Supplier<Authorization> auth) { - this.auth = auth; - } - - @Override - public HttpRequest filter(HttpRequest request) throws HttpException { - Authorization auth = this.auth.get(); - - // Replace with API URL - URI endpoint = request.getEndpoint(); - endpoint = URI.create(auth.apiUrl() + - (endpoint.getPort() == -1 ? "" : ":" + endpoint.getPort()) + - endpoint.getPath() + - (endpoint.getQuery() == null ? "" : "?" + endpoint.getQuery())); - - request = request.toBuilder() - .endpoint(endpoint) - .replaceHeader(HttpHeaders.AUTHORIZATION, auth.authorizationToken()) - .build(); - return request; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorizationDownload.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorizationDownload.java b/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorizationDownload.java deleted file mode 100644 index e5f01ed..0000000 --- a/b2/src/main/java/org/jclouds/b2/filters/RequestAuthorizationDownload.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.filters; - -import java.net.URI; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.collect.Memoized; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpRequestFilter; -import org.jclouds.b2.domain.Authorization; - -import com.google.common.base.Supplier; -import com.google.common.net.HttpHeaders; - -@Singleton -public final class RequestAuthorizationDownload implements HttpRequestFilter { - private final Supplier<Authorization> auth; - - @Inject - RequestAuthorizationDownload(@Memoized Supplier<Authorization> auth) { - this.auth = auth; - } - - @Override - public HttpRequest filter(HttpRequest request) throws HttpException { - Authorization auth = this.auth.get(); - - // Replace with download URL - URI endpoint = request.getEndpoint(); - endpoint = URI.create(auth.downloadUrl() + - (endpoint.getPort() == -1 ? "" : ":" + endpoint.getPort()) + - endpoint.getRawPath() + - (endpoint.getQuery() == null ? "" : "?" + endpoint.getQuery())); - - request = request.toBuilder() - .endpoint(endpoint) - .replaceHeader(HttpHeaders.AUTHORIZATION, auth.authorizationToken()) - .build(); - return request; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/functions/ParseB2ObjectFromResponse.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/functions/ParseB2ObjectFromResponse.java b/b2/src/main/java/org/jclouds/b2/functions/ParseB2ObjectFromResponse.java deleted file mode 100644 index 3d122aa..0000000 --- a/b2/src/main/java/org/jclouds/b2/functions/ParseB2ObjectFromResponse.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.functions; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Date; -import java.util.Map; - -import org.jclouds.http.HttpResponse; -import org.jclouds.io.MutableContentMetadata; -import org.jclouds.io.Payload; -import org.jclouds.b2.domain.B2Object; -import org.jclouds.b2.reference.B2Headers; - -import com.google.common.base.Function; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; -import com.google.common.net.HttpHeaders; - -public final class ParseB2ObjectFromResponse implements Function<HttpResponse, B2Object> { - @Override - public B2Object apply(HttpResponse from) { - Payload payload = from.getPayload(); - MutableContentMetadata contentMeta = payload.getContentMetadata(); - - String fileId = from.getFirstHeaderOrNull(B2Headers.FILE_ID); - String fileName; - try { - fileName = URLDecoder.decode(from.getFirstHeaderOrNull(B2Headers.FILE_NAME), "UTF-8"); - } catch (UnsupportedEncodingException uee) { - throw Throwables.propagate(uee); - } - String contentSha1 = from.getFirstHeaderOrNull(B2Headers.CONTENT_SHA1); - ImmutableMap.Builder<String, String> fileInfo = ImmutableMap.builder(); - for (Map.Entry<String, String> entry : from.getHeaders().entries()) { - if (entry.getKey().regionMatches(true, 0, B2Headers.FILE_INFO_PREFIX, 0, B2Headers.FILE_INFO_PREFIX.length())) { - String value; - try { - value = URLDecoder.decode(entry.getValue(), "UTF-8"); - } catch (UnsupportedEncodingException uee) { - throw Throwables.propagate(uee); - } - fileInfo.put(entry.getKey().substring(B2Headers.FILE_INFO_PREFIX.length()), value); - } - } - Date uploadTimestamp = new Date(Long.parseLong(from.getFirstHeaderOrNull(B2Headers.UPLOAD_TIMESTAMP))); - String contentRange = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_RANGE); - - return B2Object.create(fileId, fileName, null, null, contentMeta.getContentLength(), contentSha1, contentMeta.getContentType(), fileInfo.build(), null, uploadTimestamp.getTime(), contentRange, payload); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/handlers/ParseB2ErrorFromJsonContent.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/handlers/ParseB2ErrorFromJsonContent.java b/b2/src/main/java/org/jclouds/b2/handlers/ParseB2ErrorFromJsonContent.java deleted file mode 100644 index 6442e28..0000000 --- a/b2/src/main/java/org/jclouds/b2/handlers/ParseB2ErrorFromJsonContent.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.handlers; - -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.blobstore.KeyNotFoundException; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.Json; -import org.jclouds.b2.B2ResponseException; -import org.jclouds.b2.domain.B2Error; -import org.jclouds.rest.ResourceNotFoundException; - -import com.google.inject.Inject; -import com.google.inject.TypeLiteral; - -public final class ParseB2ErrorFromJsonContent extends ParseJson<B2Error> implements HttpErrorHandler { - @Inject - ParseB2ErrorFromJsonContent(Json json) { - super(json, TypeLiteral.get(B2Error.class)); - } - - private static Exception refineException(B2Error error, Exception exception) { - if ("bad_bucket_id".equals(error.code())) { - return new ContainerNotFoundException(exception); - } else if ("bad_json".equals(error.code())) { - return new IllegalArgumentException(error.message(), exception); - } else if ("bad_request".equals(error.code())) { - return new IllegalArgumentException(error.message(), exception); - } else if ("file_not_present".equals(error.code())) { - return new KeyNotFoundException(exception); - } else if ("not_found".equals(error.code())) { - return new ResourceNotFoundException(error.message(), exception); - } else { - return exception; - } - } - - @Override - public void handleError(HttpCommand command, HttpResponse response) { - B2Error error = this.apply(response); - Exception exception = refineException(error, new B2ResponseException(command, response, error)); - command.setException(exception); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/main/java/org/jclouds/b2/reference/B2Headers.java ---------------------------------------------------------------------- diff --git a/b2/src/main/java/org/jclouds/b2/reference/B2Headers.java b/b2/src/main/java/org/jclouds/b2/reference/B2Headers.java deleted file mode 100644 index 4937c1b..0000000 --- a/b2/src/main/java/org/jclouds/b2/reference/B2Headers.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.reference; - -public final class B2Headers { - public static final String CONTENT_SHA1 = "X-Bz-Content-Sha1"; - public static final String FILE_ID = "X-Bz-File-Id"; - public static final String FILE_NAME = "X-Bz-File-Name"; - public static final String UPLOAD_TIMESTAMP = "X-Bz-Upload-Timestamp"; - /** - * Recommended user metadata for last-modified. The value should be a base 10 number which represents a UTC time - * when the original source file was last modified. It is a base 10 number of milliseconds since midnight, January - * 1, 1970 UTC. - */ - public static final String LAST_MODIFIED = "X-Bz-Info-src_last_modified_millis"; - - public static final String FILE_INFO_PREFIX = "X-Bz-Info-"; - - private B2Headers() { - throw new AssertionError("intentionally unimplemented"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/B2ProviderMetadataTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/B2ProviderMetadataTest.java b/b2/src/test/java/org/jclouds/b2/B2ProviderMetadataTest.java deleted file mode 100644 index fc142ca..0000000 --- a/b2/src/test/java/org/jclouds/b2/B2ProviderMetadataTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2; - -import org.jclouds.providers.internal.BaseProviderMetadataTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "B2ProviderMetadataTest") -public final class B2ProviderMetadataTest extends BaseProviderMetadataTest { - public B2ProviderMetadataTest() { - super(new B2ProviderMetadata(), new B2ApiMetadata()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobIntegrationLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobIntegrationLiveTest.java b/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobIntegrationLiveTest.java deleted file mode 100644 index fa0f6ae..0000000 --- a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobIntegrationLiveTest.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.blobstore.integration; - -import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BlobBuilder.PayloadBlobBuilder; -import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest; -import org.testng.SkipException; -import org.testng.annotations.Test; - -@Test(groups = { "live", "blobstorelive" }) -public final class B2BlobIntegrationLiveTest extends BaseBlobIntegrationTest { - public B2BlobIntegrationLiveTest() throws IOException { - provider = "b2"; - } - - @Override - protected long getMinimumMultipartBlobSize() { - return view.getBlobStore().getMinimumMultipartPartSize() + 1; - } - - @Override - protected void addContentMetadata(PayloadBlobBuilder blobBuilder) { - blobBuilder.contentType("text/csv"); - // B2 does not support the following: - //blobBuilder.contentDisposition("attachment; filename=photo.jpg"); - //blobBuilder.contentEncoding("gzip"); - //blobBuilder.contentLanguage("en"); - } - - @Override - protected void checkContentMetadata(Blob blob) { - checkContentType(blob, "text/csv"); - // B2 does not support the following: - //checkContentDisposition(blob, "attachment; filename=photo.jpg"); - //checkContentEncoding(blob, "gzip"); - //checkContentLanguage(blob, "en"); - } - - @Override - protected void checkMD5(BlobMetadata metadata) throws IOException { - // B2 does not support Content-MD5 - } - - @Override - public void testCopyBlobCopyMetadata() throws Exception { - try { - super.testCopyBlobCopyMetadata(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testCopyBlobReplaceMetadata() throws Exception { - try { - super.testCopyBlobReplaceMetadata(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testCopyIfMatch() throws Exception { - try { - super.testCopyIfMatch(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testCopyIfNoneMatch() throws Exception { - try { - super.testCopyIfNoneMatch(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testCopyIfModifiedSince() throws Exception { - try { - super.testCopyIfModifiedSince(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testCopyIfUnmodifiedSince() throws Exception { - try { - super.testCopyIfUnmodifiedSince(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException { - try { - super.testPutObjectStream(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not support the Cache-Control header", iae); - } - } - - @Override - public void testPutIncorrectContentMD5() throws InterruptedException, IOException { - try { - super.testPutIncorrectContentMD5(); - failBecauseExceptionWasNotThrown(AssertionError.class); - } catch (AssertionError ae) { - throw new SkipException("B2 does not enforce Content-MD5", ae); - } - } - - @Override - public void testCreateBlobWithExpiry() throws InterruptedException { - try { - super.testCreateBlobWithExpiry(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 does not allow Expires header", iae); - } - } - - @Override - public void testSetBlobAccess() throws Exception { - try { - super.testSetBlobAccess(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testPutBlobAccess() throws Exception { - try { - super.testPutBlobAccess(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testPutBlobAccessMultipart() throws Exception { - try { - super.testPutBlobAccessMultipart(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testGetIfModifiedSince() throws InterruptedException { - try { - super.testGetIfModifiedSince(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testGetIfUnmodifiedSince() throws InterruptedException { - try { - super.testGetIfUnmodifiedSince(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testGetIfMatch() throws InterruptedException { - try { - super.testGetIfMatch(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testGetIfNoneMatch() throws InterruptedException { - try { - super.testGetIfNoneMatch(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("not supported on B2", uoe); - } - } - - @Override - public void testGetRangeOutOfRange() throws InterruptedException, IOException { - try { - super.testGetRangeOutOfRange(); - failBecauseExceptionWasNotThrown(AssertionError.class); - } catch (AssertionError ae) { - throw new SkipException("B2 does not error on invalid ranges", ae); - } - } - - @Override - public void testMultipartUploadSinglePart() throws Exception { - try { - super.testMultipartUploadSinglePart(); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 requires at least two parts", iae); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobLiveTest.java b/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobLiveTest.java deleted file mode 100644 index 34e4950..0000000 --- a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobLiveTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.blobstore.integration; - -import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; - -import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest; - -import org.testng.SkipException; -import org.testng.annotations.Optional; -import org.testng.annotations.Test; - -@Test(groups = { "live" }) -public final class B2BlobLiveTest extends BaseBlobLiveTest { - public B2BlobLiveTest() { - provider = "b2"; - } - - @Override - public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception { - try { - super.testCopyUrl(httpStreamUrl, httpStreamMD5); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - throw new SkipException("B2 requires repeatable payloads to calculate SHA1 hash", iae); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobSignerLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobSignerLiveTest.java b/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobSignerLiveTest.java deleted file mode 100644 index 7a027f0..0000000 --- a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2BlobSignerLiveTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.blobstore.integration; - -import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; - -import java.io.IOException; - -import org.jclouds.blobstore.integration.internal.BaseBlobSignerLiveTest; -import org.testng.SkipException; -import org.testng.annotations.Test; - -@Test(groups = { "live" }) -public final class B2BlobSignerLiveTest extends BaseBlobSignerLiveTest { - public B2BlobSignerLiveTest() { - provider = "b2"; - } - - @Test - public void testSignGetUrl() throws Exception { - try { - super.testSignGetUrl(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignGetUrlOptions() throws Exception { - try { - super.testSignGetUrlOptions(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignGetUrlWithTime() throws InterruptedException, IOException { - try { - super.testSignGetUrlWithTime(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignGetUrlWithTimeExpired() throws InterruptedException, IOException { - try { - super.testSignGetUrlWithTimeExpired(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignPutUrl() throws Exception { - try { - super.testSignPutUrl(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignPutUrlWithTime() throws Exception { - try { - super.testSignPutUrlWithTime(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignPutUrlWithTimeExpired() throws Exception { - try { - super.testSignPutUrlWithTimeExpired(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } - - @Test - public void testSignRemoveUrl() throws Exception { - try { - super.testSignRemoveUrl(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("unsupported by B2", uoe); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerIntegrationLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerIntegrationLiveTest.java b/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerIntegrationLiveTest.java deleted file mode 100644 index 7d262ac..0000000 --- a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerIntegrationLiveTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.blobstore.integration; - -import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; - -import java.io.IOException; - -import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest; -import org.testng.SkipException; -import org.testng.annotations.DataProvider; - -import com.google.common.collect.ImmutableSet; - -public final class B2ContainerIntegrationLiveTest extends BaseContainerIntegrationTest { - public B2ContainerIntegrationLiveTest() { - provider = "b2"; - } - - @Override - public void testListMarkerAfterLastKey() throws Exception { - try { - super.testListMarkerAfterLastKey(); - failBecauseExceptionWasNotThrown(AssertionError.class); - } catch (AssertionError ae) { - throw new SkipException("B2 uses the marker as the current key, not the next key", ae); - } - } - - @Override - public void testListContainerWithZeroMaxResults() throws Exception { - try { - super.testListContainerWithZeroMaxResults(); - failBecauseExceptionWasNotThrown(AssertionError.class); - } catch (AssertionError ae) { - throw new SkipException("B2 does not enforce zero max results", ae); - } - } - - @Override - public void testDirectory() throws InterruptedException { - throw new SkipException("B2 does not support directories"); - } - - @Override - public void testSetContainerAccess() throws Exception { - try { - super.testSetContainerAccess(); - failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); - } catch (UnsupportedOperationException uoe) { - throw new SkipException("Test uses blob signer which B2 does not support", uoe); - } - } - - @Override - protected void checkMD5(BlobMetadata metadata) throws IOException { - // B2 does not support Content-MD5 - } - - // B2 does not support " " file name - @DataProvider - @Override - public Object[][] getBlobsToEscape() { - ImmutableSet<String> testNames = ImmutableSet.of("%20", "%20 ", " %20"); - Object[][] result = new Object[1][1]; - result[0][0] = testNames; - return result; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerLiveTest.java b/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerLiveTest.java deleted file mode 100644 index 65e61db..0000000 --- a/b2/src/test/java/org/jclouds/b2/blobstore/integration/B2ContainerLiveTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.blobstore.integration; - -import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest; -import org.testng.annotations.Test; - -@Test(groups = { "live" }) -public final class B2ContainerLiveTest extends BaseContainerLiveTest { - public B2ContainerLiveTest() { - provider = "b2"; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java b/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java deleted file mode 100644 index 8d3e3a0..0000000 --- a/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.net.URL; -import java.util.Set; -import java.util.Properties; - -import org.jclouds.ContextBuilder; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.b2.B2Api; -import org.jclouds.util.Strings2; - -import com.google.common.base.Charsets; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -final class B2TestUtils { - static B2Api api(String uri, String provider, Properties overrides) { - Set<Module> modules = ImmutableSet.<Module> of( - new ExecutorServiceModule(MoreExecutors.sameThreadExecutor())); - - return ContextBuilder.newBuilder(provider) - .credentials("ACCOUNT_ID", "APPLICATION_KEY") - .endpoint(uri) - .overrides(overrides) - .modules(modules) - .buildApi(B2Api.class); - } - - static B2Api api(String uri, String provider) { - return api(uri, provider, new Properties()); - } - - static MockWebServer createMockWebServer() throws IOException { - MockWebServer server = new MockWebServer(); - server.play(); - URL url = server.getUrl(""); - return server; - } - - static void assertAuthentication(MockWebServer server) { - assertThat(server.getRequestCount()).isGreaterThanOrEqualTo(1); - try { - assertThat(server.takeRequest().getRequestLine()).isEqualTo("GET /b2api/v1/b2_authorize_account HTTP/1.1"); - } catch (InterruptedException e) { - throw Throwables.propagate(e); - } - } - - /** - * Ensures the request has a json header for the proper REST methods. - * - * @param request - * @param method - * The request method (such as GET). - * @param path - * The path requested for this REST call. - * @see RecordedRequest - */ - static void assertRequest(RecordedRequest request, String method, String path) { - assertThat(request.getMethod()).isEqualTo(method); - assertThat(request.getPath()).isEqualTo(path); - } - - /** - * Ensures the request is json and has the same contents as the resource - * file provided. - * - * @param request - * @param method - * The request method (such as GET). - * @param resourceLocation - * The location of the resource file. Contents will be compared to - * the request body as JSON. - * @see RecordedRequest - */ - static void assertRequest(RecordedRequest request, String method, String path, String resourceLocation) { - assertRequest(request, method, path); - assertContentTypeIsJson(request); - JsonParser parser = new JsonParser(); - JsonElement requestJson; - try { - requestJson = parser.parse(new String(request.getBody(), Charsets.UTF_8)); - } catch (Exception e) { - throw Throwables.propagate(e); - } - JsonElement resourceJson = parser.parse(stringFromResource(resourceLocation)); - assertThat(requestJson).isEqualTo(resourceJson); - } - - /** - * Ensures the request has a json header. - * - * @param request - * @see RecordedRequest - */ - private static void assertContentTypeIsJson(RecordedRequest request) { - assertThat(request.getHeaders()).contains("Content-Type: application/json"); - } - - /** - * Get a string from a resource - * - * @param resourceName - * The name of the resource. - * @return The content of the resource - */ - static String stringFromResource(String resourceName) { - try { - return Strings2.toStringAndClose(BucketApiMockTest.class.getResourceAsStream(resourceName)); - } catch (IOException e) { - throw Throwables.propagate(e); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/features/BucketApiLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/features/BucketApiLiveTest.java b/b2/src/test/java/org/jclouds/b2/features/BucketApiLiveTest.java deleted file mode 100644 index 81e6ceb..0000000 --- a/b2/src/test/java/org/jclouds/b2/features/BucketApiLiveTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; - -import java.util.Random; - -import org.jclouds.b2.domain.Bucket; -import org.jclouds.b2.domain.BucketList; -import org.jclouds.b2.domain.BucketType; -import org.jclouds.b2.internal.BaseB2ApiLiveTest; -import org.testng.annotations.Test; - -public final class BucketApiLiveTest extends BaseB2ApiLiveTest { - private static final String BUCKET_NAME = "jcloudstestbucket" + new Random().nextInt(Integer.MAX_VALUE); - - @Test(groups = "live") - public void testCreateBucket() { - BucketApi bucketApi = api.getBucketApi(); - - Bucket response = bucketApi.createBucket(BUCKET_NAME, BucketType.ALL_PRIVATE); - try { - assertThat(response.bucketName()).isEqualTo(BUCKET_NAME); - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - } finally { - response = bucketApi.deleteBucket(response.bucketId()); - assertThat(response.bucketName()).isEqualTo(BUCKET_NAME); - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - } - } - - @Test(groups = "live") - public void testDeleteAlreadyDeletedBucket() { - BucketApi bucketApi = api.getBucketApi(); - - Bucket response = bucketApi.createBucket(BUCKET_NAME, BucketType.ALL_PRIVATE); - response = bucketApi.deleteBucket(response.bucketId()); - - response = bucketApi.deleteBucket(response.bucketId()); - assertThat(response).isNull(); - } - - @Test(groups = "live") - public void testDeleteInvalidBucketId() { - BucketApi bucketApi = api.getBucketApi(); - - try { - bucketApi.deleteBucket("4a48fe8875c6214145260818"); - failBecauseExceptionWasNotThrown(IllegalArgumentException.class); - } catch (IllegalArgumentException iae) { - assertThat(iae.getMessage()).isEqualTo("bucketId not valid for account"); - } - } - - @Test(groups = "live") - public void testUpdateBucket() { - BucketApi bucketApi = api.getBucketApi(); - - Bucket response = bucketApi.createBucket(BUCKET_NAME, BucketType.ALL_PRIVATE); - try { - response = bucketApi.updateBucket(response.bucketId(), BucketType.ALL_PUBLIC); - assertThat(response.bucketName()).isEqualTo(BUCKET_NAME); - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PUBLIC); - } finally { - response = bucketApi.deleteBucket(response.bucketId()); - assertThat(response.bucketName()).isEqualTo(BUCKET_NAME); - } - } - - @Test(groups = "live") - public void testListBuckets() { - BucketApi bucketApi = api.getBucketApi(); - - Bucket response = bucketApi.createBucket(BUCKET_NAME, BucketType.ALL_PRIVATE); - try { - boolean found = false; - BucketList buckets = bucketApi.listBuckets(); - for (Bucket bucket : buckets.buckets()) { - if (bucket.bucketName().equals(BUCKET_NAME)) { - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - found = true; - } - } - assertThat(found).isTrue(); - } finally { - response = bucketApi.deleteBucket(response.bucketId()); - assertThat(response.bucketName()).isEqualTo(BUCKET_NAME); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java b/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java deleted file mode 100644 index 5a6bf85..0000000 --- a/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.b2.features.B2TestUtils.api; -import static org.jclouds.b2.features.B2TestUtils.assertAuthentication; -import static org.jclouds.b2.features.B2TestUtils.assertRequest; -import static org.jclouds.b2.features.B2TestUtils.createMockWebServer; -import static org.jclouds.b2.features.B2TestUtils.stringFromResource; - -import org.jclouds.b2.domain.Bucket; -import org.jclouds.b2.domain.BucketList; -import org.jclouds.b2.domain.BucketType; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "BucketApiMockTest") -public final class BucketApiMockTest { - public void testCreateBucket() throws Exception { - MockWebServer server = createMockWebServer(); - server.enqueue(new MockResponse().setBody(stringFromResource("/authorize_account_response.json"))); - server.enqueue(new MockResponse().setBody(stringFromResource("/bucket.json"))); - - try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); - Bucket response = api.createBucket("any_name_you_pick", BucketType.ALL_PRIVATE); - assertThat(response.bucketId()).isEqualTo("4a48fe8875c6214145260818"); - assertThat(response.bucketName()).isEqualTo("any_name_you_pick"); - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - - assertThat(server.getRequestCount()).isEqualTo(2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "POST", "/b2api/v1/b2_create_bucket", "/create_bucket_request.json"); - } finally { - server.shutdown(); - } - } - - public void testDeleteBucket() throws Exception { - MockWebServer server = createMockWebServer(); - server.enqueue(new MockResponse().setBody(stringFromResource("/authorize_account_response.json"))); - server.enqueue(new MockResponse().setBody(stringFromResource("/bucket.json"))); - - try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); - Bucket response = api.deleteBucket("4a48fe8875c6214145260818"); - assertThat(response.bucketId()).isEqualTo("4a48fe8875c6214145260818"); - assertThat(response.bucketName()).isEqualTo("any_name_you_pick"); - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - - assertThat(server.getRequestCount()).isEqualTo(2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "POST", "/b2api/v1/b2_delete_bucket", "/delete_bucket_request.json"); - } finally { - server.shutdown(); - } - } - - public void testDeleteAlreadyDeletedBucket() throws Exception { - MockWebServer server = createMockWebServer(); - server.enqueue(new MockResponse().setBody(stringFromResource("/authorize_account_response.json"))); - server.enqueue(new MockResponse().setResponseCode(400).setBody(stringFromResource("/delete_bucket_already_deleted_response.json"))); - - try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); - Bucket response = api.deleteBucket("4a48fe8875c6214145260818"); - assertThat(response).isNull(); - - assertThat(server.getRequestCount()).isEqualTo(2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "POST", "/b2api/v1/b2_delete_bucket", "/delete_bucket_request.json"); - } finally { - server.shutdown(); - } - } - - public void testUpdateBucket() throws Exception { - MockWebServer server = createMockWebServer(); - server.enqueue(new MockResponse().setBody(stringFromResource("/authorize_account_response.json"))); - server.enqueue(new MockResponse().setBody(stringFromResource("/bucket.json"))); - - try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); - Bucket response = api.updateBucket("4a48fe8875c6214145260818", BucketType.ALL_PRIVATE); - assertThat(response.bucketId()).isEqualTo("4a48fe8875c6214145260818"); - assertThat(response.bucketName()).isEqualTo("any_name_you_pick"); - assertThat(response.bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - - assertThat(server.getRequestCount()).isEqualTo(2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "POST", "/b2api/v1/b2_update_bucket", "/update_bucket_request.json"); - } finally { - server.shutdown(); - } - } - - public void testListBuckets() throws Exception { - MockWebServer server = createMockWebServer(); - server.enqueue(new MockResponse().setBody(stringFromResource("/authorize_account_response.json"))); - server.enqueue(new MockResponse().setBody(stringFromResource("/list_buckets_response.json"))); - - try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); - BucketList response = api.listBuckets(); - - assertThat(response.buckets()).hasSize(3); - - assertThat(response.buckets().get(0).bucketName()).isEqualTo("Kitten Videos"); - assertThat(response.buckets().get(0).bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - - assertThat(response.buckets().get(1).bucketName()).isEqualTo("Puppy Videos"); - assertThat(response.buckets().get(1).bucketType()).isEqualTo(BucketType.ALL_PUBLIC); - - assertThat(response.buckets().get(2).bucketName()).isEqualTo("Vacation Pictures"); - assertThat(response.buckets().get(2).bucketType()).isEqualTo(BucketType.ALL_PRIVATE); - - assertThat(server.getRequestCount()).isEqualTo(2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "POST", "/b2api/v1/b2_list_buckets", "/list_buckets_request.json"); - } finally { - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/85b30385/b2/src/test/java/org/jclouds/b2/features/MultipartApiLiveTest.java ---------------------------------------------------------------------- diff --git a/b2/src/test/java/org/jclouds/b2/features/MultipartApiLiveTest.java b/b2/src/test/java/org/jclouds/b2/features/MultipartApiLiveTest.java deleted file mode 100644 index 332eee3..0000000 --- a/b2/src/test/java/org/jclouds/b2/features/MultipartApiLiveTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.b2.features; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Map; -import java.util.Random; - -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; -import org.jclouds.b2.domain.Action; -import org.jclouds.b2.domain.B2Object; -import org.jclouds.b2.domain.Bucket; -import org.jclouds.b2.domain.BucketType; -import org.jclouds.b2.domain.GetUploadPartResponse; -import org.jclouds.b2.domain.ListPartsResponse; -import org.jclouds.b2.domain.ListUnfinishedLargeFilesResponse; -import org.jclouds.b2.domain.MultipartUploadResponse; -import org.jclouds.b2.internal.BaseB2ApiLiveTest; -import org.jclouds.utils.TestUtils; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.hash.Hashing; -import com.google.common.io.ByteSource; - -public final class MultipartApiLiveTest extends BaseB2ApiLiveTest { - private static final Random random = new Random(); - - @Test(groups = "live") - public void testCancelMultipart() throws Exception { - BucketApi bucketApi = api.getBucketApi(); - MultipartApi multipartApi = api.getMultipartApi(); - - String fileName = "file-name"; - String contentType = "text/plain"; - Map<String, String> fileInfo = ImmutableMap.of("author", "unknown"); - - Bucket bucket = bucketApi.createBucket(getBucketName(), BucketType.ALL_PRIVATE); - try { - MultipartUploadResponse response = multipartApi.startLargeFile(bucket.bucketId(), fileName, contentType, fileInfo); - multipartApi.cancelLargeFile(response.fileId()); - } finally { - bucketApi.deleteBucket(bucket.bucketId()); - } - } - - @Test(groups = "live") - public void testFinishMultipart() throws Exception { - BucketApi bucketApi = api.getBucketApi(); - ObjectApi objectApi = api.getObjectApi(); - MultipartApi multipartApi = api.getMultipartApi(); - - String fileName = "file-name"; - String contentType = "text/plain"; - Map<String, String> fileInfo = ImmutableMap.of("author", "unknown"); - - Bucket bucket = bucketApi.createBucket(getBucketName(), BucketType.ALL_PRIVATE); - MultipartUploadResponse response = null; - B2Object b2Object = null; - try { - response = multipartApi.startLargeFile(bucket.bucketId(), fileName, contentType, fileInfo); - - ByteSource part1 = TestUtils.randomByteSource().slice(0, 100 * 1024 * 1024); - String hash1 = part1.hash(Hashing.sha1()).toString(); - Payload payload1 = Payloads.newByteSourcePayload(part1); - payload1.getContentMetadata().setContentLength(part1.size()); - GetUploadPartResponse uploadUrl = multipartApi.getUploadPartUrl(response.fileId()); - multipartApi.uploadPart(uploadUrl, 1, hash1, payload1); - - ByteSource part2 = TestUtils.randomByteSource().slice(0, 1); - String hash2 = part2.hash(Hashing.sha1()).toString(); - Payload payload2 = Payloads.newByteSourcePayload(part2); - payload2.getContentMetadata().setContentLength(part2.size()); - uploadUrl = multipartApi.getUploadPartUrl(response.fileId()); - multipartApi.uploadPart(uploadUrl, 2, hash2, payload2); - - b2Object = multipartApi.finishLargeFile(response.fileId(), ImmutableList.of(hash1, hash2)); - response = null; - - assertThat(b2Object.fileName()).isEqualTo(fileName); - assertThat(b2Object.fileInfo()).isEqualTo(fileInfo); - assertThat(b2Object.uploadTimestamp()).isAfterYear(2015); - assertThat(b2Object.action()).isEqualTo(Action.UPLOAD); - assertThat(b2Object.bucketId()).isEqualTo(bucket.bucketId()); - assertThat(b2Object.contentLength()).isEqualTo(100 * 1024 * 1024 + 1); - assertThat(b2Object.contentType()).isEqualTo(contentType); - } finally { - if (b2Object != null) { - objectApi.deleteFileVersion(fileName, b2Object.fileId()); - } - if (response != null) { - multipartApi.cancelLargeFile(response.fileId()); - } - bucketApi.deleteBucket(bucket.bucketId()); - } - } - - @Test(groups = "live") - public void testListParts() throws Exception { - BucketApi bucketApi = api.getBucketApi(); - ObjectApi objectApi = api.getObjectApi(); - MultipartApi multipartApi = api.getMultipartApi(); - - String fileName = "file-name"; - String contentType = "text/plain"; - Map<String, String> fileInfo = ImmutableMap.of("author", "unknown"); - - Bucket bucket = bucketApi.createBucket(getBucketName(), BucketType.ALL_PRIVATE); - MultipartUploadResponse response = null; - B2Object b2Object = null; - try { - response = multipartApi.startLargeFile(bucket.bucketId(), fileName, contentType, fileInfo); - - ListPartsResponse listParts = multipartApi.listParts(response.fileId(), 1, 1000); - assertThat(listParts.parts()).hasSize(0); - - long contentLength = 1024 * 1024; - ByteSource part = TestUtils.randomByteSource().slice(0, contentLength); - String hash = part.hash(Hashing.sha1()).toString(); - Payload payload = Payloads.newByteSourcePayload(part); - payload.getContentMetadata().setContentLength(contentLength); - GetUploadPartResponse uploadUrl = multipartApi.getUploadPartUrl(response.fileId()); - multipartApi.uploadPart(uploadUrl, 1, hash, payload); - - listParts = multipartApi.listParts(response.fileId(), 1, 1000); - assertThat(listParts.parts()).hasSize(1); - - ListPartsResponse.Entry entry = listParts.parts().get(0); - assertThat(entry.contentLength()).isEqualTo(contentLength); - assertThat(entry.contentSha1()).isEqualTo(hash); - assertThat(entry.partNumber()).isEqualTo(1); - } finally { - if (response != null) { - multipartApi.cancelLargeFile(response.fileId()); - } - bucketApi.deleteBucket(bucket.bucketId()); - } - } - - @Test(groups = "live") - public void testListUnfinishedLargeFiles() throws Exception { - BucketApi bucketApi = api.getBucketApi(); - ObjectApi objectApi = api.getObjectApi(); - MultipartApi multipartApi = api.getMultipartApi(); - - String fileName = "file-name"; - String contentType = "text/plain"; - Map<String, String> fileInfo = ImmutableMap.of("author", "unknown"); - - Bucket bucket = bucketApi.createBucket(getBucketName(), BucketType.ALL_PRIVATE); - MultipartUploadResponse response = null; - B2Object b2Object = null; - try { - ListUnfinishedLargeFilesResponse unfinishedLargeFiles = multipartApi.listUnfinishedLargeFiles(bucket.bucketId(), null, null); - assertThat(unfinishedLargeFiles.files()).hasSize(0); - - response = multipartApi.startLargeFile(bucket.bucketId(), fileName, contentType, fileInfo); - - unfinishedLargeFiles = multipartApi.listUnfinishedLargeFiles(bucket.bucketId(), null, null); - assertThat(unfinishedLargeFiles.files()).hasSize(1); - - ListUnfinishedLargeFilesResponse.Entry entry = unfinishedLargeFiles.files().get(0); - assertThat(entry.contentType()).isEqualTo(contentType); - assertThat(entry.fileInfo()).isEqualTo(fileInfo); - assertThat(entry.fileName()).isEqualTo(fileName); - } finally { - if (response != null) { - multipartApi.cancelLargeFile(response.fileId()); - } - bucketApi.deleteBucket(bucket.bucketId()); - } - } - - private static String getBucketName() { - return "jcloudstestbucket-" + random.nextInt(Integer.MAX_VALUE); - } -}
