JCLOUDS-458: Add Bucket Operation with live tests

This commit is contained in:
hsbhathiya 2014-06-24 08:38:17 +05:30 committed by Andrew Gaul
parent 236e0b9b17
commit 4e4558cf18
50 changed files with 3135 additions and 175 deletions

View File

@ -38,6 +38,7 @@ MIICXgIBAAKBgQRRbRqVDtJLN1MO/xJoKqZuphDeBh5jIKueW3aNIiWs1XFcct+h
...
aH7xmpHSTbbXmQkuuv+z8EKijigprd/FoJpTX1f5/R+4wQ==
-----END RSA PRIVATE KEY-----</test.google-cloud-storage.credential>
<test.google-cloud-storage.project-number>123451234</test.google-cloud-storage.project-number>
</properties>
```

View File

@ -111,6 +111,7 @@
<jclouds.blobstore.httpstream.md5>${jclouds.blobstore.httpstream.md5}</jclouds.blobstore.httpstream.md5>
<test.google-cloud-storage.identity>${test.google-cloud-storage.identity}</test.google-cloud-storage.identity>
<test.google-cloud-storage.credential>${test.google-cloud-storage.credential}</test.google-cloud-storage.credential>
<test.google-cloud-storage.project-number>${test.google-cloud-storage.project-number}</test.google-cloud-storage.project-number>
<test.google-cloud-storage.api-version>${test.google-cloud-storage.api-version}</test.google-cloud-storage.api-version>
<test.google-cloud-storage.build-version>${test.google-cloud-storage.build-version}</test.google-cloud-storage.build-version>
</systemPropertyVariables>

View File

@ -21,6 +21,7 @@ import java.io.Closeable;
import javax.ws.rs.Path;
import org.jclouds.googlecloudstorage.features.BucketAccessControlsApi;
import org.jclouds.googlecloudstorage.features.BucketApi;
import org.jclouds.googlecloudstorage.features.DefaultObjectAccessControlsApi;
import org.jclouds.rest.annotations.Delegate;
@ -44,4 +45,11 @@ public interface GoogleCloudStorageApi extends Closeable {
@Delegate
@Path("")
BucketAccessControlsApi getBucketAccessControlsApi();
/**
* Provides access to Bucket features
*/
@Delegate
@Path("")
BucketApi getBucketsApi();
}

View File

@ -0,0 +1,298 @@
/*
* 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.googlecloudstorage.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Date;
import java.util.Set;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.internal.BucketCors;
import org.jclouds.googlecloudstorage.domain.internal.BucketLifeCycle;
import org.jclouds.googlecloudstorage.domain.internal.Logging;
import org.jclouds.googlecloudstorage.domain.internal.Owner;
import org.jclouds.googlecloudstorage.domain.internal.Versioning;
import org.jclouds.googlecloudstorage.domain.internal.Website;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* The Bucket represents a bucket in Google Cloud Storage There is a single global namespace shared by all buckets
*
* @see <a href = " https://developers.google.com/storage/docs/json_api/v1/buckets"/>
*/
public class Bucket extends Resource {
private final String name;
private final Long projectNumber;
private final Date timeCreated;
private final Long metageneration;
private final Set<BucketAccessControls> acl;
private final Set<DefaultObjectAccessControls> defaultObjectAcl;
private final Owner owner;
private final Location location;
private final Website website;
private final Logging logging;
private final Versioning versioning;
private final Set<BucketCors> cors;
private final BucketLifeCycle lifeCycle;
private final StorageClass storageClass;
public Bucket(String id, URI selfLink, String name, String etag, Long projectNumber, Date timeCreated,
Long metageneration, Set<BucketAccessControls> acl, Set<DefaultObjectAccessControls> defaultObjectAcl,
Owner owner, Location location, Website website, Logging logging, Versioning versioning, Set<BucketCors> cors,
BucketLifeCycle lifeCycle, StorageClass storageClass) {
super(Kind.BUCKET, id, selfLink, etag);
this.projectNumber = projectNumber;
this.timeCreated = checkNotNull(timeCreated, "timeCreated");
this.metageneration = checkNotNull(metageneration, "metageneration");
this.acl = acl.isEmpty() ? null : acl;
this.defaultObjectAcl = defaultObjectAcl.isEmpty() ? null : defaultObjectAcl;
this.owner = checkNotNull(owner, "Owner");
this.location = checkNotNull(location, "location");
this.website = website;
this.logging = logging;
this.versioning = versioning;
this.cors = cors.isEmpty() ? null : cors;
this.lifeCycle = lifeCycle;
this.storageClass = storageClass;
this.name = checkNotNull(name, "name");
}
public Long getProjectNumber() {
return projectNumber;
}
public String getName() {
return name;
}
public Date getTimeCreated() {
return timeCreated;
}
public Long getMetageneration() {
return metageneration;
}
public Set<BucketAccessControls> getAcl() {
return acl;
}
public Set<DefaultObjectAccessControls> getDefaultObjectAcl() {
return defaultObjectAcl;
}
public Owner getOwner() {
return owner;
}
public Location getLocation() {
return location;
}
public Website getWebsite() {
return website;
}
public Logging getLogging() {
return logging;
}
public Versioning getVersioning() {
return versioning;
}
public Set<BucketCors> getCors() {
return cors;
}
public BucketLifeCycle getLifeCycle() {
return lifeCycle;
}
public StorageClass getStorageClass() {
return storageClass;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Bucket that = Bucket.class.cast(obj);
return equal(this.kind, that.kind) && equal(this.name, that.name)
&& equal(this.projectNumber, that.projectNumber);
}
protected Objects.ToStringHelper string() {
return super.string().omitNullValues().add("name", name).add("timeCreated", timeCreated)
.add("projectNumber", projectNumber).add("metageneration", metageneration).add("acl", acl)
.add("defaultObjectAcl", defaultObjectAcl).add("owner", owner).add("location", location)
.add("website", website).add("logging", logging).add("versioning", versioning).add("cors", cors)
.add("lifeCycle", lifeCycle).add("storageClass", storageClass);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromBucket(this);
}
public static final class Builder extends Resource.Builder<Builder> {
private String name;
private Long projectNumber;
private Date timeCreated;
private Long metageneration;
private ImmutableSet.Builder<BucketAccessControls> acl = ImmutableSet.builder();
private ImmutableSet.Builder<DefaultObjectAccessControls> defaultObjectAcl = ImmutableSet.builder();
private Owner owner;
private Location location;
private Website website;
private Logging logging;
private Versioning versioning;
private ImmutableSet.Builder<BucketCors> cors = ImmutableSet.builder();
private BucketLifeCycle lifeCycle;
private StorageClass storageClass;
public Builder name(String name) {
this.name = name;
return this;
}
public Builder projectNumber(Long projectNumber) {
this.projectNumber = projectNumber;
return this;
}
public Builder timeCreated(Date timeCreated) {
this.timeCreated = timeCreated;
return this;
}
public Builder metageneration(Long metageneration) {
this.metageneration = metageneration;
return this;
}
public Builder owner(Owner owner) {
this.owner = owner;
return this;
}
public Builder location(Location location) {
this.location = location;
return this;
}
public Builder website(Website website) {
this.website = website;
return this;
}
public Builder logging(Logging logging) {
this.logging = logging;
return this;
}
public Builder versioning(Versioning versioning) {
this.versioning = versioning;
return this;
}
public Builder lifeCycle(BucketLifeCycle lifeCycle) {
this.lifeCycle = lifeCycle;
return this;
}
public Builder storageClass(StorageClass storageClass) {
this.storageClass = storageClass;
return this;
}
public Builder addAcl(BucketAccessControls bucketAccessControls) {
this.acl.add(bucketAccessControls);
return this;
}
public Builder acl(Set<BucketAccessControls> acl) {
this.acl.addAll(acl);
return this;
}
public Builder addDefaultObjectAcl(DefaultObjectAccessControls defaultObjectAccessControls) {
this.defaultObjectAcl.add(defaultObjectAccessControls);
return this;
}
public Builder defaultObjectAcl(Set<DefaultObjectAccessControls> defaultObjectAcl) {
this.defaultObjectAcl.addAll(defaultObjectAcl);
return this;
}
public Builder addCORS(BucketCors cors) {
this.cors.add(cors);
return this;
}
public Builder cors(Set<BucketCors> cors) {
this.cors.addAll(cors);
return this;
}
@Override
protected Builder self() {
return this;
}
public Bucket build() {
return new Bucket(super.id, super.selfLink, name, super.etag, projectNumber, timeCreated, metageneration,
acl.build(), defaultObjectAcl.build(), owner, location, website, logging, versioning, cors.build(),
lifeCycle, storageClass);
}
public Builder fromBucket(Bucket in) {
return super.fromResource(in).name(in.getName()).projectNumber(in.getProjectNumber())
.timeCreated(in.getTimeCreated()).metageneration(in.getMetageneration()).acl(in.getAcl())
.defaultObjectAcl(in.getDefaultObjectAcl()).owner(in.getOwner()).location(in.getLocation())
.website(in.getWebsite()).logging(in.getLogging()).versioning(in.getVersioning()).cors(in.getCors())
.lifeCycle(in.getLifeCycle()).storageClass(in.getStorageClass());
}
}
}

View File

@ -17,12 +17,13 @@
package org.jclouds.googlecloudstorage.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam;
import com.google.common.base.Objects;
/**
@ -32,10 +33,6 @@ import com.google.common.base.Objects;
*/
public class BucketAccessControls extends Resource {
public enum Role {
READER, WRITER, OWNER
}
protected final String bucket;
protected final String entity;
protected final Role role;
@ -85,78 +82,6 @@ public class BucketAccessControls extends Resource {
return projectTeam;
}
public static class ProjectTeam {
public enum Team {
owners, editors, viewers;
}
private final String projectId;
private final Team team;
@ConstructorProperties({ "projectId", "team" })
public ProjectTeam(String projectId, Team team) {
this.projectId = projectId;
this.team = team;
}
public String getProjectId() {
return projectId;
}
public Team getTeam() {
return team;
}
@Override
public int hashCode() {
return Objects.hashCode(projectId, team);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
ProjectTeam that = ProjectTeam.class.cast(obj);
return equal(this.projectId, that.projectId) && equal(this.team, that.team);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("projectId", projectId).add("team", team);
}
@Override
public String toString() {
return string().toString();
}
public static class Builder {
private String projectId;
private Team team;
public Builder projectId(String projectId) {
this.projectId = projectId;
return this;
}
public Builder team(Team team) {
this.team = team;
return this;
}
public ProjectTeam build() {
return new ProjectTeam(this.projectId, this.team);
}
public Builder fromProjectTeam(ProjectTeam in) {
return this.projectId(in.getProjectId()).team(in.getTeam());
}
}
}
@Override
public boolean equals(Object obj) {
if (this == obj)

View File

@ -0,0 +1,213 @@
/*
* 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.googlecloudstorage.domain;
import java.util.Set;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.internal.BucketCors;
import org.jclouds.googlecloudstorage.domain.internal.BucketLifeCycle;
import org.jclouds.googlecloudstorage.domain.internal.Logging;
import org.jclouds.googlecloudstorage.domain.internal.Owner;
import org.jclouds.googlecloudstorage.domain.internal.Versioning;
import org.jclouds.googlecloudstorage.domain.internal.Website;
import com.google.common.collect.Sets;
public class BucketTemplate {
private String name;
private Long projectNumber;
private Set<BucketAccessControls> acl;
private Set<DefaultObjectAccessControls> defaultObjectAccessControls;
private Owner owner;
private Location location;
private Website website;
private Logging logging;
private Versioning versioning;
private Set<BucketCors> cors;
private BucketLifeCycle lifeCycle;
private StorageClass storageClass;
public BucketTemplate name(String name) {
this.name = name;
return this;
}
public BucketTemplate projectNumber(Long projectNumber) {
this.projectNumber = projectNumber;
return this;
}
public BucketTemplate owner(Owner owner) {
this.owner = owner;
return this;
}
public BucketTemplate location(Location location) {
this.location = location;
return this;
}
public BucketTemplate website(Website website) {
this.website = website;
return this;
}
public BucketTemplate logging(Logging logging) {
this.logging = logging;
return this;
}
public BucketTemplate versioning(Versioning versioning) {
this.versioning = versioning;
return this;
}
public BucketTemplate lifeCycle(BucketLifeCycle lifeCycle) {
this.lifeCycle = lifeCycle;
return this;
}
public BucketTemplate storageClass(StorageClass storageClass) {
this.storageClass = storageClass;
return this;
}
public BucketTemplate addAcl(BucketAccessControls bucketAccessControls) {
if (this.acl == null) {
this.acl = Sets.newLinkedHashSet();
}
this.acl.add(bucketAccessControls);
return this;
}
public BucketTemplate acl(Set<BucketAccessControls> acl) {
if (this.acl == null) {
this.acl = Sets.newLinkedHashSet();
}
this.acl.addAll(acl);
return this;
}
public BucketTemplate addDefaultObjectAccessControls(DefaultObjectAccessControls oac) {
if (this.defaultObjectAccessControls == null) {
this.defaultObjectAccessControls = Sets.newLinkedHashSet();
}
this.defaultObjectAccessControls.add(oac);
return this;
}
public BucketTemplate defaultObjectAccessControls(Set<DefaultObjectAccessControls> defaultObjectAcl) {
if (this.defaultObjectAccessControls == null) {
this.defaultObjectAccessControls = Sets.newLinkedHashSet();
}
this.defaultObjectAccessControls.addAll(defaultObjectAcl);
return this;
}
public BucketTemplate addCORS(BucketCors cors) {
if (this.cors == null) {
this.cors = Sets.newLinkedHashSet();
}
this.cors.add(cors);
return this;
}
public BucketTemplate cors(Set<BucketCors> cors) {
if (this.cors == null) {
this.cors = Sets.newLinkedHashSet();
}
this.cors.addAll(cors);
return this;
}
public Long getProjectNumber() {
return projectNumber;
}
public String getName() {
return name;
}
public Set<BucketAccessControls> getAcl() {
return acl;
}
public Set<DefaultObjectAccessControls> getDefaultObjectAccessControls() {
return defaultObjectAccessControls;
}
public Owner getOwner() {
return owner;
}
public Location getLocation() {
return location;
}
public Website getWebsite() {
return website;
}
public Logging getLogging() {
return logging;
}
public Versioning getVersioning() {
return versioning;
}
public Set<BucketCors> getCors() {
return cors;
}
public BucketLifeCycle getLifeCycle() {
return lifeCycle;
}
public StorageClass getStorageClass() {
return storageClass;
}
public static Builder builder() {
return new Builder();
}
public static BucketTemplate fromBucketsTemplate(BucketTemplate bucketTemplate) {
return Builder.fromBucketsTemplate(bucketTemplate);
}
public static class Builder {
public static BucketTemplate fromBucketsTemplate(BucketTemplate in) {
return new BucketTemplate().name(in.getName()).projectNumber(in.getProjectNumber()).acl(in.getAcl())
.defaultObjectAccessControls(in.getDefaultObjectAccessControls()).owner(in.getOwner())
.location(in.getLocation()).website(in.getWebsite()).logging(in.getLogging())
.versioning(in.getVersioning()).cors(in.getCors()).lifeCycle(in.getLifeCycle())
.storageClass(in.getStorageClass());
}
}
}

View File

@ -17,13 +17,12 @@
package org.jclouds.googlecloudstorage.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam;
import com.google.common.base.Objects;
@ -83,78 +82,6 @@ public class DefaultObjectAccessControls extends Resource {
return projectTeam;
}
public static class ProjectTeam {
public enum Team {
owners, editors, viewers;
}
private final String projectId;
private final Team team;
@ConstructorProperties({ "projectId", "team" })
public ProjectTeam(String projectId, Team team) {
this.projectId = projectId;
this.team = team;
}
public String getProjectId() {
return projectId;
}
public Team getTeam() {
return team;
}
@Override
public int hashCode() {
return Objects.hashCode(projectId, team);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
ProjectTeam that = ProjectTeam.class.cast(obj);
return equal(this.projectId, that.projectId) && equal(this.team, that.team);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("projectId", projectId).add("team", team);
}
@Override
public String toString() {
return string().toString();
}
public static class Builder {
private String projectId;
private Team team;
public Builder projectId(String projectId) {
this.projectId = projectId;
return this;
}
public Builder team(Team team) {
this.team = team;
return this;
}
public ProjectTeam build() {
return new ProjectTeam(this.projectId, this.team);
}
public Builder fromProjectTeam(ProjectTeam in) {
return this.projectId(in.getProjectId()).team(in.getTeam());
}
}
}
@Override
public boolean equals(Object obj) {
if (this == obj)

View File

@ -16,7 +16,7 @@
*/
package org.jclouds.googlecloudstorage.domain;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
/**
* Represents a Object Access Control Resource

View File

@ -14,19 +14,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecloudstorage.features;
package org.jclouds.googlecloudstorage.domain;
import com.google.common.base.CaseFormat;
public final class ApiResourceRefferences {
public final class DomainResourceRefferences {
private ApiResourceRefferences() {
private DomainResourceRefferences() {
}
public enum Role {
READER, WRITER, OWNER
}
public enum ObjectRole {
READER, OWNER
}
public enum Location {
ASIA, EU, US, ASIA_EAST1, US_CENTRAL1, US_CENTRAL2, US_EAST1, US_EAST2, US_EAST3, US_WEST1;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()).toUpperCase();
}
@Override
public String toString() {
return value().toUpperCase();
}
public static Location fromValue(String location) {
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, location.toLowerCase()));
}
}
public enum StorageClass {
STANDARD, DURABLE_REDUCED_AVAILABILITY;
}
public enum Projection {
NO_ACL, FULL;

View File

@ -0,0 +1,92 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
/**
* This is an Internal Object used in BucketLifeCycles/Rules.
*/
public class Action {
private final String type;
public Action(String type) {
this.type = type;
}
public String getType() {
return type;
}
@Override
public int hashCode() {
return Objects.hashCode(type);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Action other = (Action) obj;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("type", type);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String type;
public Builder type(String type) {
this.type = type;
return this;
}
public Action build() {
return new Action(this.type);
}
public Builder fromAction(Action in) {
return this.type(in.getType());
}
}
}

View File

@ -0,0 +1,151 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* The bucket's Cross-Origin Resource Sharing (CORS) configuration.
*
* @see <a href= "https://developers.google.com/storage/docs/cross-origin" />
*/
public final class BucketCors {
private final Set<String> origins;
private final Set<String> methods;
private final Set<String> responseHeaders;
private final Integer maxAgeSeconds;
public BucketCors(@Nullable Set<String> origin, @Nullable Set<String> method, @Nullable Set<String> responseHeader,
Integer maxAgeSeconds) {
this.origins = origin == null ? ImmutableSet.<String> of() : origin;
this.methods = method == null ? ImmutableSet.<String> of() : method;
this.responseHeaders = responseHeader == null ? ImmutableSet.<String> of() : responseHeader;
this.maxAgeSeconds = maxAgeSeconds;
}
public Set<String> getOrigin() {
return origins;
}
public Set<String> getMethod() {
return methods;
}
public Set<String> getResponseHeader() {
return responseHeaders;
}
public Integer getMaxAgeSeconds() {
return maxAgeSeconds;
}
@Override
public int hashCode() {
return Objects.hashCode(origins, methods, responseHeaders, maxAgeSeconds);
}
/* TODO -Check equals */
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
BucketCors that = BucketCors.class.cast(obj);
return equal(this.origins, that.origins) && equal(this.methods, that.methods)
&& equal(this.responseHeaders, that.responseHeaders) && equal(this.maxAgeSeconds, that.maxAgeSeconds);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("origin", origins).add("method", methods).add("responseHeader", responseHeaders)
.add("maxAgeSeconds", maxAgeSeconds);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private ImmutableSet.Builder<String> origins = ImmutableSet.builder();
private ImmutableSet.Builder<String> methods = ImmutableSet.builder();
private ImmutableSet.Builder<String> reponseHeaders = ImmutableSet.builder();
private Integer maxAgeSeconds;
public Builder addOrigin(String origin) {
this.origins.add(origin);
return this;
}
public Builder origin(Set<String> origin) {
this.origins.addAll(origin);
return this;
}
public Builder addMethod(String method) {
this.methods.add(method);
return this;
}
public Builder method(Set<String> method) {
this.methods.addAll(method);
return this;
}
public Builder addResponseHeader(String responseHeader) {
this.reponseHeaders.add(responseHeader);
return this;
}
public Builder responseHeader(Set<String> responseHeader) {
this.reponseHeaders.addAll(responseHeader);
return this;
}
public Builder maxAgeSeconds(Integer maxAgeSeconds) {
this.maxAgeSeconds = maxAgeSeconds;
return this;
}
public BucketCors build() {
return new BucketCors(this.origins.build(), this.methods.build(), this.reponseHeaders.build(),
this.maxAgeSeconds);
}
public Builder fromCors(BucketCors c) {
return this.maxAgeSeconds(c.getMaxAgeSeconds()).origin(c.getOrigin()).method(c.getMethod())
.responseHeader(c.getResponseHeader());
}
}
}

View File

@ -0,0 +1,101 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.toStringHelper;
import java.util.Set;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* The bucket's lifecycle configuration.
*
* @see <a href= "https://developers.google.com/storage/docs/lifecycle" />
*/
public class BucketLifeCycle {
private final Set<Rule> rules;
public BucketLifeCycle(Set<Rule> rule) {
this.rules = rule == null ? ImmutableSet.<Rule> of() : rule;
}
public Set<Rule> getRule() {
return rules;
}
@Override
public int hashCode() {
return Objects.hashCode(rules);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BucketLifeCycle other = (BucketLifeCycle) obj;
if (rules == null) {
if (other.rules != null)
return false;
} else if (!rules.equals(other.rules))
return false;
return true;
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("rule", rules);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
ImmutableSet.Builder<Rule> rules = ImmutableSet.builder();
public Builder addRule(Rule rule) {
this.rules.add(rule);
return this;
}
public Builder rule(Set<Rule> rule) {
this.rules.addAll(rule);
return this;
}
public BucketLifeCycle build() {
return new BucketLifeCycle(this.rules.build());
}
public Builder fromLifeCycle(BucketLifeCycle in) {
return this.rule(in.getRule());
}
}
}

View File

@ -0,0 +1,147 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.toStringHelper;
import java.util.Date;
import com.google.common.base.Objects;
/**
* This is an Internal Object used in BucketLifeCycles/Rules.
*/
public class Condition {
private final Integer age;
private final Date createdBefore;
private final Boolean isLive;
private final Integer numNewerVersions;
public Condition(Integer age, Date createdBefore, Boolean isLive, Integer numNewerVersions) {
this.age = age;
this.createdBefore = createdBefore;
this.isLive = isLive;
this.numNewerVersions = numNewerVersions;
}
public Integer getAge() {
return age;
}
public Date getCreatedBefore() {
return createdBefore;
}
public Boolean getIsLive() {
return isLive;
}
public Integer getNumNewerVersions() {
return numNewerVersions;
}
@Override
public int hashCode() {
return Objects.hashCode(age, createdBefore, isLive, numNewerVersions);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Condition other = (Condition) obj;
if (age == null) {
if (other.age != null)
return false;
} else if (!age.equals(other.age))
return false;
if (createdBefore == null) {
if (other.createdBefore != null)
return false;
} else if (!createdBefore.equals(other.createdBefore))
return false;
if (isLive == null) {
if (other.isLive != null)
return false;
} else if (!isLive.equals(other.isLive))
return false;
if (numNewerVersions == null) {
if (other.numNewerVersions != null)
return false;
} else if (!numNewerVersions.equals(other.numNewerVersions))
return false;
return true;
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("age", age).add("createdBefore", createdBefore).add("isLive", isLive)
.add("numNewerVersions", numNewerVersions);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private Integer age;
private Date createdBefore;
private Boolean isLive;
private Integer numNewerVersions;
public Builder age(Integer age) {
this.age = age;
return this;
}
public Builder createdBefore(Date createdBefore) {
this.createdBefore = createdBefore;
return this;
}
public Builder isLive(Boolean isLive) {
this.isLive = isLive;
return this;
}
public Builder numNewerVersions(Integer numNewerVersions) {
this.numNewerVersions = numNewerVersions;
return this;
}
public Condition build() {
return new Condition(this.age, this.createdBefore, this.isLive, this.numNewerVersions);
}
public Builder fromCondition(Condition in) {
return this.age(in.getAge()).createdBefore(in.getCreatedBefore()).isLive(in.getIsLive())
.numNewerVersions(in.getNumNewerVersions());
}
}
}

View File

@ -0,0 +1,101 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
/**
* The bucket's logging configuration, which defines the destination bucket and optional name prefix for the current
* bucket's logs.
*
* @see <a href= "https://developers.google.com/storage/docs/accesslogs" />
*/
public final class Logging {
private final String logBucket;
private final String logObjectPrefix;
public Logging(String logBucket, String logObjectPrefix) {
this.logBucket = logBucket;
this.logObjectPrefix = logObjectPrefix;
}
public String getLogBucket() {
return logBucket;
}
public String getLogObjectPrefix() {
return logObjectPrefix;
}
@Override
public int hashCode() {
return Objects.hashCode(logBucket, logObjectPrefix);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Logging that = Logging.class.cast(obj);
return equal(this.logBucket, that.logBucket) && equal(this.logObjectPrefix, that.logObjectPrefix);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("logBucket", logBucket).add("logObjectPrefix", logObjectPrefix);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String logBucket;
private String logObjectPrefix;
public Builder logBucket(String logBucket) {
this.logBucket = logBucket;
return this;
}
public Builder logObjectPrefix(String logObjectPrefix) {
this.logObjectPrefix = logObjectPrefix;
return this;
}
public Logging build() {
return new Logging(this.logBucket, this.logObjectPrefix);
}
public Builder fromLogging(Logging in) {
return this.logBucket(in.getLogBucket()).logObjectPrefix(in.getLogObjectPrefix());
}
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
/**
* This is an internal object used in both Bucket and Object representation
*/
public final class Owner {
private final String entity;
private final String entityId;
public Owner(String entity, String entityId) {
this.entity = entity;
this.entityId = entityId;
}
public String getEntity() {
return entity;
}
public String getEntityId() {
return entityId;
}
@Override
public int hashCode() {
return Objects.hashCode(entity, entityId);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Owner that = Owner.class.cast(obj);
return equal(this.entity, that.entity);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).omitNullValues().add("entiy", entity).add("entityId", entityId);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String entity;
private String entityId;
public Builder entity(String entity) {
this.entity = entity;
return this;
}
public Builder entityId(String entityId) {
this.entityId = entityId;
return this;
}
public Owner build() {
return new Owner(this.entity, this.entityId);
}
public Builder fromOwner(Owner in) {
return this.entity(in.getEntity()).entityId(in.getEntityId());
}
}
}

View File

@ -0,0 +1,101 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import java.beans.ConstructorProperties;
import com.google.common.base.Objects;
/**
* The bucket's logging configuration, which defines the destination bucket and optional name prefix for the current
* bucket's logs.
*/
public final class ProjectTeam {
public enum Team {
owners, editors, viewers;
}
private final String projectId;
private final Team team;
@ConstructorProperties({ "projectId", "team" })
public ProjectTeam(String projectId, Team team) {
this.projectId = projectId;
this.team = team;
}
public String getProjectId() {
return projectId;
}
public Team getTeam() {
return team;
}
@Override
public int hashCode() {
return Objects.hashCode(projectId, team);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
ProjectTeam that = ProjectTeam.class.cast(obj);
return equal(this.projectId, that.projectId) && equal(this.team, that.team);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("projectId", projectId).add("team", team);
}
@Override
public String toString() {
return string().toString();
}
public static class Builder {
private String projectId;
private Team team;
public Builder projectId(String projectId) {
this.projectId = projectId;
return this;
}
public Builder team(Team team) {
this.team = team;
return this;
}
public ProjectTeam build() {
return new ProjectTeam(this.projectId, this.team);
}
public Builder fromProjectTeam(ProjectTeam in) {
return this.projectId(in.getProjectId()).team(in.getTeam());
}
}
}

View File

@ -0,0 +1,109 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
/**
* The bucket's logging configuration, which defines the destination bucket and optional name prefix for the current
* bucket's logs.
*/
public class Rule {
private final Action action;
private final Condition condition;
public Rule(Action action, Condition condition) {
this.action = action;
this.condition = condition;
}
public Action getAction() {
return action;
}
public Condition getCondition() {
return condition;
}
@Override
public int hashCode() {
return Objects.hashCode(action, condition);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Rule other = (Rule) obj;
if (action == null) {
if (other.action != null)
return false;
} else if (!action.equals(other.action))
return false;
if (condition == null) {
if (other.condition != null)
return false;
} else if (!condition.equals(other.condition))
return false;
return true;
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("condition", condition).add("action", action);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private Action action;
private Condition condition;
public Builder action(Action action) {
this.action = action;
return this;
}
public Builder condtion(Condition condition) {
this.condition = condition;
return this;
}
public Rule build() {
return new Rule(this.action, this.condition);
}
public Builder fromRule(Rule in) {
return this.action(in.getAction()).condtion(in.getCondition());
}
}
}

View File

@ -0,0 +1,94 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
/**
* The bucket's versioning configuration.
*
* @see <a href= "https://developers.google.com/storage/docs/object-versioning" />
*/
public final class Versioning {
private final Boolean enabled;
public Versioning(Boolean enabled) {
this.enabled = enabled;
}
public Boolean isEnabled() {
return enabled;
}
@Override
public int hashCode() {
return Objects.hashCode(enabled);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Versioning other = (Versioning) obj;
if (enabled == null) {
if (other.enabled != null)
return false;
} else if (!enabled.equals(other.enabled))
return false;
return true;
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("enabled", enabled);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private Boolean enabled;
public Builder enalbled(Boolean enabled) {
this.enabled = enabled;
return this;
}
public Versioning build() {
return new Versioning(this.enabled);
}
public Builder fromVersioning(Versioning in) {
return this.enalbled(in.isEnabled());
}
}
}

View File

@ -0,0 +1,101 @@
/*
* 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.googlecloudstorage.domain.internal;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
/**
* This is a internal object in bucket resource
*
* @see <a href= "https://developers.google.com/storage/docs/website-configuration" />
*/
public class Website {
private final String mainPageSuffix;
private final String notFoundPage;
public Website(String mainPageSuffix, String notFoundPage) {
this.mainPageSuffix = mainPageSuffix;
this.notFoundPage = notFoundPage;
}
public String getMainPageSuffix() {
return mainPageSuffix;
}
public String getNotFoundPage() {
return notFoundPage;
}
@Override
public int hashCode() {
return Objects.hashCode(mainPageSuffix, notFoundPage);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Website that = Website.class.cast(obj);
return equal(this.mainPageSuffix, that.mainPageSuffix);
}
protected Objects.ToStringHelper string() {
return toStringHelper(this).add("mainPageSuffix", mainPageSuffix).add("notFoundPage", notFoundPage);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String mainPageSuffix;
private String notFoundPage;
public Builder mainPageSuffix(String mainPageSuffix) {
this.mainPageSuffix = mainPageSuffix;
return this;
}
public Builder notFoundPage(String notFoundPage) {
this.notFoundPage = notFoundPage;
return this;
}
public Website build() {
return new Website(this.mainPageSuffix, this.notFoundPage);
}
public Builder fromWebsite(Website in) {
return this.mainPageSuffix(in.getMainPageSuffix()).notFoundPage(in.getNotFoundPage());
}
}
}

View File

@ -0,0 +1,313 @@
/*
* 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.googlecloudstorage.features;
import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_FULLCONTROL_SCOPE;
import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_READONLY_SCOPE;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.BucketTemplate;
import org.jclouds.googlecloudstorage.domain.ListPage;
import org.jclouds.googlecloudstorage.handlers.BucketBinder;
import org.jclouds.googlecloudstorage.options.DeleteBucketOptions;
import org.jclouds.googlecloudstorage.options.GetBucketOptions;
import org.jclouds.googlecloudstorage.options.InsertBucketOptions;
import org.jclouds.googlecloudstorage.options.ListOptions;
import org.jclouds.googlecloudstorage.options.UpdateBucketOptions;
import org.jclouds.http.HttpResponse;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to Bucket entities via their REST API.
*
* @see <a href = " https://developers.google.com/storage/docs/json_api/v1/buckets"/>
*/
@SkipEncoding({ '/', '=' })
@RequestFilters(OAuthAuthenticator.class)
public interface BucketApi {
/**
* Returns metadata for the specified bucket.
*
* @param bucketName
* Name of the bucket
*
* @return a {@link Bucket} resource
*/
@Named("Bucket:get")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
Bucket getBuckets(@PathParam("bucket") String bucketName);
/**
* Returns metadata for the specified bucket
*
* @param bucketName
* Name of the bucket
* @param options
* Supply {@link GetBucketOptions} with optional query parameters
*
* @return a {@link Bucket} resource
*/
@Named("Bucket:get")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
Bucket getBuckets(@PathParam("bucket") String bucketName, GetBucketOptions options);
/**
* Creates a new bucket
*
* @param projectId
* A valid API project identifier
* @param bucketTemplate
* In the request body, supply a bucket resource
*
* @return If successful, this method returns a {@link Bucket} resource in the response body
*/
@Named("Bucket:insert")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/b")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@MapBinder(BucketBinder.class)
Bucket createBuckets(@QueryParam("project") String projectId,
@PayloadParam("template") BucketTemplate bucketTemplate);
/**
* Creates a new Bucket
*
* @param projectNumber
* A valid API project identifier
*
* @param bucketTemplate
* In the request body, supply a {@link Bucket} resource
* @param options
* Supply {@link InsertBucketOptions} with optional query parameters
*
* @return If successful, this method returns a {@link Bucket} resource in the response body
*/
@Named("Bucket:insert")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/b")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@MapBinder(BucketBinder.class)
Bucket createBuckets(@QueryParam("project") String projectNumber,
@PayloadParam("template") BucketTemplate bucketTemplate, InsertBucketOptions options);
/**
* Permanently deletes an empty Bucket
*
* @param bucketName
* Name of the bucket
*
* @return If successful, this method returns an empty response body
*/
@Named("Bucket:delete")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
HttpResponse deleteBuckets(@PathParam("bucket") String bucketName);
/**
* Permanently deletes an empty Bucket
*
* @param bucketName
* Name of the bucket
* @param options
* Supply {@link DeleteBucketOptions} with optional query parameters
*
* @return If successful, this method returns an empty response body.
*/
@Named("Bucket:delete")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
HttpResponse deleteBuckets(@PathParam("bucket") String bucketName, DeleteBucketOptions options);
/**
* Retrieves a list of buckets for a given project
*
* @param project
* Name of the project to retrieve the buckets
*
* @return a {@link ListPage<Bucket>}
*/
@Named("Bucket:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
ListPage<Bucket> listBuckets(@QueryParam("project") String project);
/**
* Retrieves a list of buckets for a given project
*
* @param project
* Name of the project to retrieve the buckets
* @param options
* Supply {@link ListOptions} with optional query parameters
*
*
*/
@Named("Bucket:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
ListPage<Bucket> listBuckets(@QueryParam("project") String project, ListOptions options);
/**
* Updates a bucket
*
* @param bucketName
* Name of the bucket
* @param bucket
* In the request body, supply a bucket resource with list of {@link BucketAccessControls}
*
* @return If successful, this method returns a {@link Bucket} resource in the response body
*/
@Named("Bucket:update")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Bucket updateBuckets(@PathParam("bucket") String bucketName,
@BinderParam(BindToJsonPayload.class) BucketTemplate bucketTemplate);
/**
* Updates a bucket
*
* @param bucketName
* In the request body, supply a bucket resource with list of {@link BucketAccessControls} (acl[])
* @param options
* Supply {@link UpdateBucketOptions} with optional query parameters
*
* @return If successful,this method returns a {@link Bucket} resource in the response body
*/
@Named("Bucket:update")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Bucket updateBuckets(@PathParam("bucket") String bucketName,
@BinderParam(BindToJsonPayload.class) BucketTemplate bucketTemplate, UpdateBucketOptions options);
/**
* Updates a bucket supporting patch semantics.
*
* @param bucketName
* In the request body, supply a bucket resource with list of {@link BucketAccessControls} (acl[])
* @param bucketTemplate
* In the request body, supply the relevant portions of a bucket resource
*
* @return If successful, this method returns a {@link Bucket} resource in the response body
*/
@Named("Bucket:patch")
@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Bucket patchBuckets(@PathParam("bucket") String bucketName,
@BinderParam(BindToJsonPayload.class) BucketTemplate bucketTemplate);
/**
* Updates a bucket supporting patch semantics.
*
* @param bucketName
* In the request body, supply a bucket resource with list of {@link BucketAccessControls} (acl[])
* @param bucketTemplate
* In the request body, supply the relevant portions of a bucket resource
* @param options
* Supply {@link UpdateBucketOptions} with optional query parameters
*
* @return If successful, this method returns a {@link Bucket} resource in the response body
*/
@Named("Bucket:patch")
@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/b/{bucket}")
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Bucket patchBuckets(@PathParam("bucket") String bucketName,
@BinderParam(BindToJsonPayload.class) BucketTemplate bucketTemplate, UpdateBucketOptions options);
}

View File

@ -34,7 +34,7 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.ListDefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControlsTemplate;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.handlers.DefaultObjectAccessControlsBinder;
import org.jclouds.http.HttpResponse;
import org.jclouds.javax.annotation.Nullable;

View File

@ -0,0 +1,43 @@
/*
* 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.googlecloudstorage.handlers;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.googlecloudstorage.domain.BucketTemplate;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
public class BucketBinder implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
BucketTemplate postBucket = (BucketTemplate) postParams.get("template");
return bindToRequest(request, postBucket);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.googlecloudstorage.options;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Allows to optionally specify ifMetagenerationMatch,ifMetagenerationNotMatch and projection which used in Bucket
*/
public class DeleteBucketOptions extends BaseHttpRequestOptions {
public DeleteBucketOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
this.queryParameters.put("ifMetagenerationMatch", checkNotNull(ifMetagenerationMatch, "ifMetagenerationMatch")
+ "");
return this;
}
public DeleteBucketOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
this.queryParameters.put("ifMetagenerationNotMatch",
checkNotNull(ifMetagenerationNotMatch, "ifMetagenerationNotMatch") + "");
return this;
}
public static class Builder {
public DeleteBucketOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
return new DeleteBucketOptions().ifMetagenerationMatch(ifMetagenerationMatch);
}
public DeleteBucketOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
return new DeleteBucketOptions().ifMetagenerationNotMatch(ifMetagenerationNotMatch);
}
}
}

View File

@ -0,0 +1,61 @@
/*
* 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.googlecloudstorage.options;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Projection;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Allows to optionally specify ifMetagenerationMatch,ifMetagenerationNotMatch and projection which used in Bucket
*/
public class GetBucketOptions extends BaseHttpRequestOptions {
public GetBucketOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
this.queryParameters.put("ifMetagenerationMatch", checkNotNull(ifMetagenerationMatch, "ifMetagenerationMatch")
+ "");
return this;
}
public GetBucketOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
this.queryParameters.put("ifMetagenerationNotMatch",
checkNotNull(ifMetagenerationNotMatch, "ifMetagenerationNotMatch") + "");
return this;
}
public GetBucketOptions projection(Projection projection) {
this.queryParameters.put("projection", checkNotNull(projection, "projection").toString());
return this;
}
public static class Builder {
public GetBucketOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
return new GetBucketOptions().ifMetagenerationMatch(ifMetagenerationMatch);
}
public GetBucketOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
return new GetBucketOptions().ifMetagenerationNotMatch(ifMetagenerationNotMatch);
}
public GetBucketOptions projection(Projection projection) {
return new GetBucketOptions().projection(projection);
}
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.googlecloudstorage.options;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.PredefinedAcl;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Projection;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Allows to optionally specify predefinedAcl and projection which used in Bucket
*
* @see <a href="https://developers.google.com/storage/docs/json_api/v1/buckets/insert"/>
*/
public class InsertBucketOptions extends BaseHttpRequestOptions {
public InsertBucketOptions predefinedAcl(PredefinedAcl predefinedAcl) {
this.queryParameters.put("predefinedAcl", checkNotNull(predefinedAcl, "predefinedAcl").toString());
return this;
}
public InsertBucketOptions projection(Projection projection) {
this.queryParameters.put("projection", checkNotNull(projection, "projection").toString());
return this;
}
public static class Builder {
public InsertBucketOptions predefinedAcl(PredefinedAcl predefinedAcl) {
return new InsertBucketOptions().predefinedAcl(predefinedAcl);
}
public InsertBucketOptions projection(Projection projection) {
return new InsertBucketOptions().projection(projection);
}
}
}

View File

@ -0,0 +1,55 @@
/*
* 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.googlecloudstorage.options;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Projection;
import org.jclouds.http.options.BaseHttpRequestOptions;
public class ListOptions extends BaseHttpRequestOptions {
public ListOptions pageToken(String pageToken) {
this.queryParameters.put("pageToken", checkNotNull(pageToken, "pageToken"));
return this;
}
public ListOptions maxResults(Integer maxResults) {
this.queryParameters.put("maxResults", checkNotNull(maxResults, "maxResults") + "");
return this;
}
public ListOptions projection(Projection projection) {
this.queryParameters.put("projection", checkNotNull(projection, "projection").toString());
return this;
}
public static class Builder {
public ListOptions pageToken(String pageToken) {
return new ListOptions().pageToken(pageToken);
}
public ListOptions maxResults(Integer maxResults) {
return new ListOptions().maxResults(maxResults);
}
public ListOptions projection(Projection projection) {
return new ListOptions().projection(projection);
}
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.googlecloudstorage.options;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.PredefinedAcl;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Projection;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Allows to optionally specify ifMetagenerationMatch,ifMetagenerationNotMatch and projection which used in Bucket
*/
public class UpdateBucketOptions extends BaseHttpRequestOptions {
public UpdateBucketOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
this.queryParameters.put("ifMetagenerationMatch", checkNotNull(ifMetagenerationMatch, "ifMetagenerationMatch")
+ "");
return this;
}
public UpdateBucketOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
this.queryParameters.put("ifMetagenerationNotMatch",
checkNotNull(ifMetagenerationNotMatch, "ifMetagenerationNotMatch") + "");
return this;
}
public UpdateBucketOptions projection(Projection projection) {
this.queryParameters.put("projection", checkNotNull(projection, "projection").toString());
return this;
}
public UpdateBucketOptions predefinedAcl(PredefinedAcl predefinedAcl) {
this.queryParameters.put("predefinedAcl", checkNotNull(predefinedAcl, "predefinedAcl").toString());
return this;
}
public static class Builder {
public UpdateBucketOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
return new UpdateBucketOptions().ifMetagenerationMatch(ifMetagenerationMatch);
}
public UpdateBucketOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
return new UpdateBucketOptions().ifMetagenerationNotMatch(ifMetagenerationNotMatch);
}
public UpdateBucketOptions projection(Projection projection) {
return new UpdateBucketOptions().projection(projection);
}
public UpdateBucketOptions predefinedAcl(PredefinedAcl predefinedAcl) {
return new UpdateBucketOptions().predefinedAcl(predefinedAcl);
}
}
}

View File

@ -26,7 +26,7 @@ import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiExpectTest;
import org.jclouds.googlecloudstorage.parse.BucketAclGetTest;
import org.jclouds.googlecloudstorage.parse.BucketAclInsertTest;

View File

@ -0,0 +1,259 @@
/*
* 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.googlecloudstorage.features;
import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_FULLCONTROL_SCOPE;
import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.BucketTemplate;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Projection;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiExpectTest;
import org.jclouds.googlecloudstorage.options.GetBucketOptions;
import org.jclouds.googlecloudstorage.options.ListOptions;
import org.jclouds.googlecloudstorage.options.UpdateBucketOptions;
import org.jclouds.googlecloudstorage.parse.BucketUpdateTest;
import org.jclouds.googlecloudstorage.parse.NoAclBucketTest;
import org.jclouds.googlecloudstorage.parse.NoAclBucketListTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class BucketApiExpectTest extends BaseGoogleCloudStorageApiExpectTest {
private static final String EXPECTED_TEST_BUCKET = "bhashbucket";
private static final String EXPECTED_TEST_PROJECT_NUMBER = "1082289308625";
private static final HttpRequest GET_BUCKET_REQUEST = HttpRequest.builder().method("GET")
.endpoint("https://www.googleapis.com/storage/v1/b/bhashbucket").addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
private static final HttpRequest GET_BUCKET_REQUEST_WITHOPTIONS = HttpRequest.builder().method("GET")
.endpoint("https://www.googleapis.com/storage/v1/b/bhashbucket")
.addQueryParam("ifMetagenerationNotMatch", "100").addQueryParam("projection", "full")
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
private final HttpResponse BUCKET_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/noAcl_bucket.json")).build();
public static final HttpRequest LIST_BUCKET_REQUEST = HttpRequest.builder().method("GET")
.endpoint("https://www.googleapis.com/storage/v1/b").addQueryParam("project", EXPECTED_TEST_PROJECT_NUMBER)
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
public static final HttpRequest LIST_BUCKET_REQUEST_WITHOPTIONS = HttpRequest.builder().method("GET")
.endpoint("https://www.googleapis.com/storage/v1/b").addQueryParam("project", EXPECTED_TEST_PROJECT_NUMBER)
.addQueryParam("maxResults", "2").addQueryParam("pageToken", "jcloudtestbucket500")
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
private final HttpResponse LIST_BUCKET_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/noAcl_bucket_list.json")).build();
// Test getBucket without options
public void testGetBucketWithNoOptionsResponseIs2xx() throws Exception {
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_READONLY_SCOPE), TOKEN_RESPONSE,
GET_BUCKET_REQUEST, BUCKET_RESPONSE).getBucketsApi();
assertEquals(api.getBuckets(EXPECTED_TEST_BUCKET), new NoAclBucketTest().expected());
}
public void testGetBucketResponseIs4xx() throws Exception {
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_READONLY_SCOPE), TOKEN_RESPONSE,
GET_BUCKET_REQUEST, getResponse).getBucketsApi();
assertNull("404", api.getBuckets(EXPECTED_TEST_BUCKET));
}
// Test getBucket with options
public void testGetBucketWithOptionsResponseIs2xx() throws Exception {
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_READONLY_SCOPE), TOKEN_RESPONSE,
GET_BUCKET_REQUEST_WITHOPTIONS, BUCKET_RESPONSE).getBucketsApi();
GetBucketOptions options = new GetBucketOptions().ifMetagenerationNotMatch(Long.valueOf(100)).projection(
Projection.FULL);
assertEquals(api.getBuckets(EXPECTED_TEST_BUCKET, options), new NoAclBucketTest().expected());
}
// Test listBucket without options
public void testListBucketWithNoOptionsResponseIs2xx() throws Exception {
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
LIST_BUCKET_REQUEST, LIST_BUCKET_RESPONSE).getBucketsApi();
assertEquals(api.listBuckets(EXPECTED_TEST_PROJECT_NUMBER), new NoAclBucketListTest().expected());
}
public void testListBucketWithOptionsResponseIs2xx() throws Exception {
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
LIST_BUCKET_REQUEST_WITHOPTIONS, LIST_BUCKET_RESPONSE).getBucketsApi();
ListOptions options = new ListOptions().maxResults(2).pageToken("jcloudtestbucket500");
assertEquals(api.listBuckets(EXPECTED_TEST_PROJECT_NUMBER, options), new NoAclBucketListTest().expected());
}
public void testListBucketResponseIs4xx() throws Exception {
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
LIST_BUCKET_REQUEST, listResponse).getBucketsApi();
assertNull(api.listBuckets(EXPECTED_TEST_PROJECT_NUMBER));
}
// Test createBucket without options
public void testCreateBucketWithNoOptionsResponseIs2xx() throws Exception {
HttpRequest createRequest = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/storage/v1/b")
.addHeader("Accept", "application/json")
.addQueryParam("project", EXPECTED_TEST_PROJECT_NUMBER)
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/bucket_insert_requestpayload.json",
MediaType.APPLICATION_JSON)).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
createRequest, BUCKET_RESPONSE).getBucketsApi();
BucketTemplate template = new BucketTemplate().name("bhashbucket");
assertEquals(api.createBuckets(EXPECTED_TEST_PROJECT_NUMBER, template), new NoAclBucketTest().expected());
}
public void testUpdateBucketWithNoOptionsResponseIs2xx() throws Exception {
BucketAccessControls bucketacl = BucketAccessControls.builder().bucket(EXPECTED_TEST_BUCKET)
.entity("allAuthenticatedUsers").role(Role.OWNER).build();
BucketTemplate template = new BucketTemplate().name(EXPECTED_TEST_BUCKET).addAcl(bucketacl);
HttpRequest updateRequest = HttpRequest
.builder()
.method("PUT")
.endpoint("https://www.googleapis.com/storage/v1/b/" + EXPECTED_TEST_BUCKET)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/bucket_update_requestpayload.json",
MediaType.APPLICATION_JSON)).build();
HttpResponse updateResponse = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/bucket_update_response.json")).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
updateRequest, updateResponse).getBucketsApi();
assertEquals(api.updateBuckets(EXPECTED_TEST_BUCKET, template), new BucketUpdateTest().expected());
}
public void testUpdateBucketWithOptionsResponseIs2xx() throws Exception {
BucketAccessControls bucketacl = BucketAccessControls.builder().bucket(EXPECTED_TEST_BUCKET)
.entity("allAuthenticatedUsers").role(Role.OWNER).build();
UpdateBucketOptions options = new UpdateBucketOptions().projection(Projection.NO_ACL).ifMetagenerationNotMatch(
Long.valueOf(100));
BucketTemplate template = new BucketTemplate().name(EXPECTED_TEST_BUCKET).addAcl(bucketacl);
HttpRequest updateRequest = HttpRequest
.builder()
.method("PUT")
.endpoint("https://www.googleapis.com/storage/v1/b/" + EXPECTED_TEST_BUCKET)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.addQueryParam("projection", Projection.NO_ACL.toString())
.addQueryParam("ifMetagenerationNotMatch", "100")
.payload(payloadFromResourceWithContentType("/bucket_update_requestpayload.json",
MediaType.APPLICATION_JSON)).build();
HttpResponse updateResponse = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/bucket_update_response.json")).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
updateRequest, updateResponse).getBucketsApi();
assertEquals(api.updateBuckets(EXPECTED_TEST_BUCKET, template, options), new BucketUpdateTest().expected());
}
public void testPatchBucketWithNoOptionsResponseIs2xx() throws Exception {
BucketAccessControls bucketacl = BucketAccessControls.builder().bucket(EXPECTED_TEST_BUCKET)
.entity("allAuthenticatedUsers").role(Role.OWNER).build();
BucketTemplate template = new BucketTemplate().name(EXPECTED_TEST_BUCKET).addAcl(bucketacl);
HttpRequest patchRequest = HttpRequest
.builder()
.method("PATCH")
.endpoint("https://www.googleapis.com/storage/v1/b/" + EXPECTED_TEST_BUCKET)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/bucket_update_requestpayload.json",
MediaType.APPLICATION_JSON)).build();
HttpResponse patchResponse = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/bucket_update_response.json")).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, patchRequest,
patchResponse).getBucketsApi();
assertEquals(api.patchBuckets(EXPECTED_TEST_BUCKET, template), new BucketUpdateTest().expected());
}
public void testPatchBucketWithOptionsResponseIs2xx() throws Exception {
BucketAccessControls bucketacl = BucketAccessControls.builder().bucket(EXPECTED_TEST_BUCKET)
.entity("allAuthenticatedUsers").role(Role.OWNER).build();
UpdateBucketOptions options = new UpdateBucketOptions().projection(Projection.NO_ACL).ifMetagenerationNotMatch(
Long.valueOf(100));
BucketTemplate template = new BucketTemplate().name(EXPECTED_TEST_BUCKET).addAcl(bucketacl);
HttpRequest patchRequest = HttpRequest
.builder()
.method("PUT")
.endpoint("https://www.googleapis.com/storage/v1/b/" + EXPECTED_TEST_BUCKET)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.addQueryParam("projection", Projection.NO_ACL.toString())
.addQueryParam("ifMetagenerationNotMatch", "100")
.payload(payloadFromResourceWithContentType("/bucket_update_requestpayload.json",
MediaType.APPLICATION_JSON)).build();
HttpResponse patchResponse = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/bucket_update_response.json")).build();
BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, patchRequest,
patchResponse).getBucketsApi();
assertEquals(api.updateBuckets(EXPECTED_TEST_BUCKET, template, options), new BucketUpdateTest().expected());
}
}

View File

@ -0,0 +1,219 @@
/*
* 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.googlecloudstorage.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Projection;
import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.BucketTemplate;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.ListPage;
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
import org.jclouds.googlecloudstorage.domain.internal.BucketCors;
import org.jclouds.googlecloudstorage.domain.internal.Logging;
import org.jclouds.googlecloudstorage.domain.internal.Versioning;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiLiveTest;
import org.jclouds.googlecloudstorage.options.DeleteBucketOptions;
import org.jclouds.googlecloudstorage.options.GetBucketOptions;
import org.jclouds.googlecloudstorage.options.InsertBucketOptions;
import org.jclouds.googlecloudstorage.options.UpdateBucketOptions;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;
public class BucketApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
private static final String BUCKET_NAME = "jcloudtestbucket" + (int) (Math.random() * 10000);
private static final String BUCKET_NAME_WITHOPTIONS = "jcloudtestbucketoptions" + (int) (Math.random() * 10000);
private static final String LOG_BUCKET_NAME = "jcloudtestbucket" + (int) (Math.random() * 10000);
private Long metageneration;
private BucketApi api() {
return api.getBucketsApi();
}
@Test(groups = "live")
public void testCreateBucket() {
BucketTemplate logTemplate = new BucketTemplate().name(LOG_BUCKET_NAME);
Bucket logResponse = api().createBuckets(PROJECT_NUMBER, logTemplate);
assertNotNull(logResponse);
BucketAccessControls acl = BucketAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers").role(Role.OWNER)
.build();
DefaultObjectAccessControls oac = DefaultObjectAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers")
.role(ObjectRole.OWNER).build();
BucketCors bucketCors = BucketCors.builder().addOrigin("http://example.appspot.com").addMethod("GET").addMethod("HEAD")
.addResponseHeader("x-meta-goog-custom").maxAgeSeconds(10).build();
Versioning version = Versioning.builder().enalbled(true).build();
Logging log = new Logging(LOG_BUCKET_NAME, BUCKET_NAME);
BucketTemplate template = new BucketTemplate().name(BUCKET_NAME).addAcl(acl)
.addDefaultObjectAccessControls(oac).versioning(version).location(Location.US_CENTRAL2).logging(log)
.storageClass(StorageClass.DURABLE_REDUCED_AVAILABILITY).addCORS(bucketCors);
Bucket response = api().createBuckets(PROJECT_NUMBER, template);
assertNotNull(response);
assertNotNull(response.getCors());
assertEquals(response.getKind(), Kind.BUCKET);
assertEquals(response.getName(), BUCKET_NAME);
assertEquals(response.getLocation(), Location.US_CENTRAL2);
assertTrue(response.getVersioning().isEnabled());
}
@Test(groups = "live")
public void testCreateBucketWithOptions() {
DefaultObjectAccessControls oac = DefaultObjectAccessControls.builder().bucket(BUCKET_NAME_WITHOPTIONS)
.entity("allUsers").role(ObjectRole.OWNER).build();
BucketCors bucketCors = BucketCors.builder().addOrigin("http://example.appspot.com").addMethod("GET").addMethod("HEAD")
.addResponseHeader("x-meta-goog-custom").maxAgeSeconds(10).build();
Versioning version = Versioning.builder().enalbled(true).build();
BucketTemplate template = new BucketTemplate().name(BUCKET_NAME_WITHOPTIONS)
.addDefaultObjectAccessControls(oac).versioning(version).location(Location.US_CENTRAL2)
.storageClass(StorageClass.DURABLE_REDUCED_AVAILABILITY).addCORS(bucketCors);
InsertBucketOptions options = new InsertBucketOptions().projection(Projection.FULL);
Bucket response = api().createBuckets(PROJECT_NUMBER, template, options);
assertNotNull(response);
assertNotNull(response.getCors());
assertEquals(response.getKind(), Kind.BUCKET);
assertEquals(response.getName(), BUCKET_NAME_WITHOPTIONS);
assertEquals(response.getLocation(), Location.US_CENTRAL2);
assertTrue(response.getVersioning().isEnabled());
}
@Test(groups = "live", dependsOnMethods = "testCreateBucket")
public void testUpdateBucket() {
BucketAccessControls bucketacl = BucketAccessControls.builder().bucket(BUCKET_NAME)
.entity("allAuthenticatedUsers").role(Role.OWNER).build();
BucketTemplate template = new BucketTemplate().name(BUCKET_NAME).addAcl(bucketacl);
Bucket response = api().updateBuckets(BUCKET_NAME, template);
assertNotNull(response);
assertEquals(response.getName(), BUCKET_NAME);
assertNotNull(response.getAcl());
}
@Test(groups = "live", dependsOnMethods = "testCreateBucketWithOptions")
public void testUpdateBucketWithOptions() {
BucketAccessControls bucketacl = BucketAccessControls.builder().bucket(BUCKET_NAME_WITHOPTIONS)
.entity("allAuthenticatedUsers").role(Role.OWNER).build();
UpdateBucketOptions options = new UpdateBucketOptions().projection(Projection.FULL);
BucketTemplate template = new BucketTemplate().name(BUCKET_NAME_WITHOPTIONS).addAcl(bucketacl);
Bucket response = api().updateBuckets(BUCKET_NAME_WITHOPTIONS, template, options);
assertNotNull(response);
metageneration = response.getMetageneration();
assertEquals(response.getName(), BUCKET_NAME_WITHOPTIONS);
assertNotNull(response.getAcl());
}
@Test(groups = "live", dependsOnMethods = "testCreateBucket")
public void testGetBucket() {
Bucket response = api().getBuckets(BUCKET_NAME);
assertNotNull(response);
assertEquals(response.getName(), BUCKET_NAME);
assertEquals(response.getKind(), Kind.BUCKET);
}
@Test(groups = "live", dependsOnMethods = "testUpdateBucketWithOptions")
public void testGetBucketWithOptions() {
GetBucketOptions options = new GetBucketOptions().ifMetagenerationMatch(metageneration);
Bucket response = api().getBuckets(BUCKET_NAME_WITHOPTIONS, options);
assertNotNull(response);
assertEquals(response.getName(), BUCKET_NAME_WITHOPTIONS);
assertEquals(response.getKind(), Kind.BUCKET);
}
@Test(groups = "live", dependsOnMethods = "testCreateBucket")
public void testListBucket() {
ListPage<Bucket> bucket = api().listBuckets(PROJECT_NUMBER);
Iterator<Bucket> pageIterator = bucket.iterator();
assertTrue(pageIterator.hasNext());
Bucket singlePageIterator = pageIterator.next();
List<Bucket> bucketAsList = Lists.newArrayList(singlePageIterator);
assertNotNull(singlePageIterator);
assertSame(bucketAsList.size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testCreateBucket")
public void testPatchBucket() {
Logging logging = new Logging(LOG_BUCKET_NAME, BUCKET_NAME);
BucketTemplate template = new BucketTemplate().name(BUCKET_NAME).logging(logging);
Bucket response = api().patchBuckets(BUCKET_NAME, template);
assertNotNull(response);
assertEquals(response.getName(), BUCKET_NAME);
assertEquals(response.getLogging().getLogBucket(), LOG_BUCKET_NAME);
}
@Test(groups = "live", dependsOnMethods = { "testListBucket", "testGetBucket", "testUpdateBucket" })
public void testDeleteBucket() {
HttpResponse response = api().deleteBuckets(BUCKET_NAME);
HttpResponse response2 = api().deleteBuckets(LOG_BUCKET_NAME);
assertNotNull(response);
assertEquals(response.getStatusCode(), 204);
assertNotNull(response2);
assertEquals(response2.getStatusCode(), 204);
}
@Test(groups = "live", dependsOnMethods = { "testGetBucketWithOptions" })
public void testDeleteBucketWithOptions() {
DeleteBucketOptions options = new DeleteBucketOptions().ifMetagenerationMatch(metageneration)
.ifMetagenerationNotMatch(metageneration + 1);
HttpResponse response = api().deleteBuckets(BUCKET_NAME_WITHOPTIONS, options);
assertNotNull(response);
assertEquals(response.getStatusCode(), 204);
}
}

View File

@ -25,7 +25,7 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControlsTemplate;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiExpectTest;
import org.jclouds.googlecloudstorage.parse.DefaultObjectAclGetTest;
import org.jclouds.googlecloudstorage.parse.DefaultObjectAclInsertTest;

View File

@ -20,13 +20,13 @@ import java.util.Properties;
import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.googlecloudstorage.GoogleCloudStorageApi;
import com.google.inject.Injector;
import com.google.inject.Module;
public class BaseGoogleCloudStorageApiLiveTest extends BaseApiLiveTest<GoogleCloudStorageApi> {
protected static final String PROJECT_NUMBER = System.getProperty("test.google-cloud-storage.project-number");
public BaseGoogleCloudStorageApiLiveTest() {
provider = "google-cloud-storage";
}

View File

@ -22,7 +22,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class BucketAclGetTest extends BaseGoogleCloudStorageParseTest<BucketAccessControls> {

View File

@ -22,7 +22,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class BucketAclInsertTest extends BaseGoogleCloudStorageParseTest<BucketAccessControls> {

View File

@ -22,12 +22,13 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.domain.ListBucketAccessControls;
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
import com.google.common.collect.ImmutableSet;
public class BucketAclListTest extends BaseGoogleCloudStorageParseTest<ListBucketAccessControls> {

View File

@ -22,7 +22,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class BucketAclUpdateTest extends BaseGoogleCloudStorageParseTest<BucketAccessControls> {

View File

@ -0,0 +1,49 @@
/*
* 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.googlecloudstorage.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.internal.Owner;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class BucketUpdateTest extends BaseGoogleCloudStorageParseTest<Bucket> {
@Override
public String resource() {
return "/bucket_update_response.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Bucket expected() {
return Bucket.builder().id("bhashbucket")
.selfLink(URI.create("https://www.googleapis.com/storage/v1/b/bhashbucket")).name("bhashbucket")
.projectNumber(Long.valueOf("1082289308625"))
.timeCreated(new SimpleDateFormatDateService().iso8601DateParse("2014-06-02T19:19:41.112z"))
.metageneration(Long.valueOf(204)).location(Location.US).storageClass(StorageClass.STANDARD)
.etag("CMwB").owner(Owner.builder().entity("project-owners-1082289308625").build()).build();
}
}

View File

@ -19,10 +19,10 @@ package org.jclouds.googlecloudstorage.parse;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class DefaultObjectAclGetTest extends BaseGoogleCloudStorageParseTest<DefaultObjectAccessControls> {

View File

@ -20,7 +20,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class DefaultObjectAclInsertTest extends BaseGoogleCloudStorageParseTest<DefaultObjectAccessControls> {

View File

@ -19,12 +19,12 @@ package org.jclouds.googlecloudstorage.parse;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.domain.ListDefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
import com.google.common.collect.ImmutableSet;

View File

@ -0,0 +1,66 @@
/*
* 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.googlecloudstorage.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.internal.Owner;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam;
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam.Team;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class FullBucketGetTest extends BaseGoogleCloudStorageParseTest<Bucket> {
private final BucketAccessControls acl_1 = BucketAccessControls
.builder()
.id("jcloudtestbucket3500/project-owners-1082289308625")
.selfLink(
URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket3500/acl/project-owners-1082289308625"))
.bucket("jcloudtestbucket3500").entity("project-owners-1082289308625").role(Role.OWNER)
.projectTeam(new ProjectTeam("1082289308625", Team.owners)).etag("CAo=").build();
private final DefaultObjectAccessControls defObjectAcl = DefaultObjectAccessControls.builder()
.entity("project-owners-1082289308625").role(ObjectRole.OWNER).etag("CAo=").build();
@Override
public String resource() {
return "/full_bucket_get.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Bucket expected() {
return Bucket.builder().id("jcloudtestbucket3500")
.selfLink(URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket3500"))
.name("jcloudtestbucket3500").projectNumber(Long.valueOf("1082289308625"))
.timeCreated(new SimpleDateFormatDateService().iso8601DateParse("2014-06-19T14:03:22.345Z"))
.metageneration(Long.valueOf(10)).owner(Owner.builder().entity("project-owners-1082289308625").build())
.location(Location.US).storageClass(StorageClass.STANDARD).etag("CAo=").addAcl(acl_1)
.addDefaultObjectAcl(defObjectAcl).build();
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.googlecloudstorage.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.ListPage;
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
import org.jclouds.googlecloudstorage.domain.internal.Owner;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class NoAclBucketListTest extends BaseGoogleCloudStorageParseTest<ListPage<Bucket>> {
private Bucket item_1 = Bucket.builder().id("bhashbucket")
.selfLink(URI.create("https://content.googleapis.com/storage/v1/b/bhashbucket")).name("bhashbucket")
.projectNumber(Long.valueOf("1082289308625"))
.timeCreated(new SimpleDateFormatDateService().iso8601DateParse("2014-06-02T19:19:41.112z"))
.metageneration(Long.valueOf(99)).owner(Owner.builder().entity("project-owners-1082289308625").build())
.location(Location.US).storageClass(StorageClass.STANDARD).etag("CGM=").build();
@Override
public String resource() {
return "/noAcl_bucket_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ListPage<Bucket> expected() {
return ListPage.<Bucket> builder().kind(Kind.BUCKETS).nextPageToken("bhashbucket").addItem(item_1).build();
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.googlecloudstorage.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Location;
import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.internal.Owner;
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
public class NoAclBucketTest extends BaseGoogleCloudStorageParseTest<Bucket> {
@Override
public String resource() {
return "/noAcl_bucket.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Bucket expected() {
return Bucket.builder().id("bhashbucket")
.selfLink(URI.create("https://content.googleapis.com/storage/v1/b/bhashbucket")).name("bhashbucket")
.projectNumber(Long.valueOf("1082289308625"))
.timeCreated(new SimpleDateFormatDateService().iso8601DateParse("2014-06-02T19:19:41.112z"))
.metageneration(Long.valueOf(87)).owner(Owner.builder().entity("project-owners-1082289308625").build())
.location(Location.US).storageClass(StorageClass.STANDARD).etag("CFc=").build();
}
}

View File

@ -0,0 +1,3 @@
{
"name": "bhashbucket"
}

View File

@ -0,0 +1,12 @@
{
"name":"bhashbucket",
"acl": [
{
"kind":"storage#bucketAccessControl",
"bucket":"bhashbucket",
"id":"bhashbucket/allAuthenticatedUsers",
"entity": "allAuthenticatedUsers",
"role": "OWNER"
}
]
}

View File

@ -0,0 +1,15 @@
{
"kind": "storage#bucket",
"id": "bhashbucket",
"selfLink": "https://www.googleapis.com/storage/v1/b/bhashbucket",
"projectNumber": "1082289308625",
"name": "bhashbucket",
"timeCreated": "2014-06-02T19:19:41.112Z",
"metageneration": "204",
"owner": {
"entity": "project-owners-1082289308625"
},
"location": "US",
"storageClass": "STANDARD",
"etag": "CMwB"
}

View File

@ -0,0 +1,38 @@
{
"kind": "storage#bucket",
"id": "jcloudtestbucket3500",
"selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket3500",
"projectNumber": "1082289308625",
"name": "jcloudtestbucket3500",
"timeCreated": "2014-06-19T14:03:22.345Z",
"metageneration": "10",
"acl": [
{
"kind": "storage#bucketAccessControl",
"id": "jcloudtestbucket3500/project-owners-1082289308625",
"selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket3500/acl/project-owners-1082289308625",
"bucket": "jcloudtestbucket3500",
"entity": "project-owners-1082289308625",
"role": "OWNER",
"projectTeam": {
"projectNumber": "1082289308625",
"team": "owners"
},
"etag": "CAo="
}
],
"defaultObjectAcl": [
{
"kind": "storage#objectAccessControl",
"entity": "project-owners-1082289308625",
"role": "OWNER",
"etag": "CAo="
}
],
"owner": {
"entity": "project-owners-1082289308625"
},
"location": "US",
"storageClass": "STANDARD",
"etag": "CAo="
}

View File

@ -0,0 +1,21 @@
{
"kind": "storage#buckets",
"nextPageToken": "jcloudtestbucket500",
"items": [
{
"kind": "storage#bucket",
"id": "jcloudtestbucket500",
"selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket500",
"projectNumber": "1082289308625",
"name": "jcloudtestbucket500",
"timeCreated": "2014-06-17T14:17:50.155Z",
"metageneration": "1",
"owner": {
"entity": "project-owners-1082289308625"
},
"location": "US",
"storageClass": "STANDARD",
"etag": "CAE="
}
]
}

View File

@ -0,0 +1,15 @@
{
"kind": "storage#bucket",
"id": "bhashbucket",
"selfLink": "https://content.googleapis.com/storage/v1/b/bhashbucket",
"projectNumber": "1082289308625",
"name": "bhashbucket",
"timeCreated": "2014-06-02T19:19:41.112Z",
"metageneration": "87",
"owner": {
"entity": "project-owners-1082289308625"
},
"location": "US",
"storageClass": "STANDARD",
"etag": "CFc="
}

View File

@ -0,0 +1,21 @@
{
"kind": "storage#buckets",
"nextPageToken": "bhashbucket",
"items": [
{
"kind": "storage#bucket",
"id": "bhashbucket",
"selfLink": "https://content.googleapis.com/storage/v1/b/bhashbucket",
"projectNumber": "1082289308625",
"name": "bhashbucket",
"timeCreated": "2014-06-02T19:19:41.112Z",
"metageneration": "99",
"owner": {
"entity": "project-owners-1082289308625"
},
"location": "US",
"storageClass": "STANDARD",
"etag": "CGM="
}
]
}