Skip to content

Commit

Permalink
Add list/get options serialization tests + other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Nov 30, 2015
1 parent 4107bbe commit d67f94b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private Builder() {
Builder(ProjectInfo info) {
this.name = info.name;
this.projectId = info.projectId;
this.labels = Maps.newHashMap(checkNotNull(info.labels));
this.labels.putAll(info.labels);
this.projectNumber = info.projectNumber;
this.state = info.state;
this.createTimeMillis = info.createTimeMillis;
Expand All @@ -159,7 +159,7 @@ public Builder name(String name) {
* project.
*/
public Builder projectId(String projectId) {
this.projectId = projectId;
this.projectId = checkNotNull(projectId);
return this;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public ProjectInfo build() {

ProjectInfo(Builder builder) {
this.name = builder.name;
this.projectId = checkNotNull(builder.projectId);
this.projectId = builder.projectId;
this.labels = ImmutableMap.copyOf(builder.labels);
this.projectNumber = builder.projectNumber;
this.state = builder.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ResourceManager extends Service<ResourceManagerOptions> {
/**
* The fields of a project.
*
* These values can be used to specify the fields to include of in a partial response when calling
* These values can be used to specify the fields to include in a partial response when calling
* {@link ResourceManager#get} or {@link ResourceManager#list}. Project ID is always returned,
* even if not specified.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class DefaultResourceManagerRpc implements ResourceManagerRpc {

// see https://cloud.google.com/resource-manager/v1/errors/core_errors
private static final Set<Integer> RETRYABLE_CODES = ImmutableSet.of(503, 500, 429, 417);

private final ResourceManagerOptions options;
Expand Down Expand Up @@ -45,9 +46,7 @@ private static ResourceManagerException translate(IOException exception) {
}

private static ResourceManagerException translate(GoogleJsonError exception) {
boolean retryable =
RETRYABLE_CODES.contains(exception.getCode())
|| "InternalError".equals(exception.getMessage());
boolean retryable = RETRYABLE_CODES.contains(exception.getCode());
return new ResourceManagerException(exception.getCode(), exception.getMessage(), retryable);
}

Expand All @@ -63,7 +62,7 @@ public void delete(String projectId) throws ResourceManagerException {
}

@Override
public Project get(String projectId) throws ResourceManagerException {
public Project get(String projectId, Map<Option, ?> options) throws ResourceManagerException {
// TODO(ajaykannan): fix me!
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Y y() {

void delete(String projectId) throws ResourceManagerException;

Project get(String projectId) throws ResourceManagerException;
Project get(String projectId, Map<Option, ?> options) throws ResourceManagerException;

Tuple<String, Iterable<Project>> list(Map<Option, ?> options) throws ResourceManagerException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -94,15 +93,13 @@ public void testResourceManager() {
@Test
public void testDelete() {
resourceManager.delete(PROJECT_INFO.projectId());
expectLastCall();
replay(resourceManager);
project.delete();
}

@Test
public void testUndelete() {
resourceManager.undelete(PROJECT_INFO.projectId());
expectLastCall();
replay(resourceManager);
project.undelete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class SerializationTest {
.build();
private static final PageImpl<ProjectInfo> PAGE_RESULT =
new PageImpl<>(null, "c", Collections.singletonList(PARTIAL_PROJECT_INFO));
private static final ResourceManager.ProjectGetOption PROJECT_GET_OPTION =
ResourceManager.ProjectGetOption.fields(ResourceManager.ProjectField.NAME);
private static final ResourceManager.ProjectListOption PROJECT_LIST_OPTION =
ResourceManager.ProjectListOption.filter("name:*");

@Test
public void testServiceOptions() throws Exception {
Expand All @@ -63,7 +67,8 @@ public void testServiceOptions() throws Exception {

@Test
public void testModelAndRequests() throws Exception {
Serializable[] objects = {PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, PAGE_RESULT};
Serializable[] objects = {PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, PAGE_RESULT,
PROJECT_GET_OPTION, PROJECT_LIST_OPTION};
for (Serializable obj : objects) {
Object copy = serializeAndDeserialize(obj);
assertEquals(obj, obj);
Expand Down

0 comments on commit d67f94b

Please sign in to comment.