Skip to content

Commit 110ab8e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into temp2
2 parents 22b877b + 0265e0a commit 110ab8e

30 files changed

+431
-41
lines changed

src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,21 @@ protected String value() {
6161
}
6262

6363
@Override
64-
public int hashCode() {
65-
return Objects.hash(type, value);
64+
public boolean equals(Object o) {
65+
if (this == o) {
66+
return true;
67+
}
68+
if (o == null || getClass() != o.getClass()) {
69+
return false;
70+
}
71+
Entity entity = (Entity) o;
72+
return Objects.equals(type, entity.type) &&
73+
Objects.equals(value, entity.value);
6674
}
6775

6876
@Override
69-
public boolean equals(Object obj) {
70-
if (obj == null || !getClass().isAssignableFrom(obj.getClass())) {
71-
return false;
72-
}
73-
return Objects.equals(toPb(), ((Entity)obj).toPb());
77+
public int hashCode() {
78+
return Objects.hash(type, value);
7479
}
7580

7681
@Override
@@ -95,6 +100,9 @@ static Entity fromPb(String entity) {
95100
if (entity.startsWith("group-")) {
96101
return new Group(entity.substring(6));
97102
}
103+
if (entity.startsWith("domain-")) {
104+
return new Domain(entity.substring(7));
105+
}
98106
if (entity.startsWith("project-")) {
99107
int idx = entity.indexOf('-', 8);
100108
String team = entity.substring(8, idx);
@@ -178,7 +186,7 @@ enum ProjectRole {
178186
OWNERS, EDITORS, VIEWERS
179187
}
180188

181-
Project(ProjectRole pRole, String projectId) {
189+
public Project(ProjectRole pRole, String projectId) {
182190
super(Type.PROJECT, pRole.name().toLowerCase() + "-" + projectId);
183191
this.pRole = pRole;
184192
this.projectId = projectId;
@@ -220,6 +228,24 @@ public Role role() {
220228
return role;
221229
}
222230

231+
@Override
232+
public int hashCode() {
233+
return Objects.hash(entity, role);
234+
}
235+
236+
@Override
237+
public boolean equals(Object obj) {
238+
if (this == obj) {
239+
return true;
240+
}
241+
if (obj == null || getClass() != obj.getClass()) {
242+
return false;
243+
}
244+
final Acl other = (Acl) obj;
245+
return Objects.equals(this.entity, other.entity)
246+
&& Objects.equals(this.role, other.role);
247+
}
248+
223249
BucketAccessControl toBucketPb() {
224250
BucketAccessControl bucketPb = new BucketAccessControl();
225251
bucketPb.setRole(role().toString());

src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static class Result<T extends Serializable> implements Serializable {
5353
this.value = null;
5454
}
5555

56+
static <T extends Serializable> Result<T> of(T value) {
57+
return new Result<>(value);
58+
}
59+
5660
/**
5761
* Returns the result.
5862
*

src/main/java/com/google/gcloud/storage/ListResult.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package com.google.gcloud.storage;
1818

19+
1920
import java.io.Serializable;
21+
import java.util.Collections;
2022
import java.util.Iterator;
2123
import java.util.Objects;
2224

@@ -41,7 +43,7 @@ public String nextPageCursor() {
4143

4244
@Override
4345
public Iterator<T> iterator() {
44-
return results.iterator();
46+
return results == null ? Collections.<T>emptyIterator() : results.iterator();
4547
}
4648

4749
@Override

src/main/java/com/google/gcloud/storage/StorageServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ private <I, O extends Serializable> List<BatchResponse.Result<O>> transformBatch
341341
for (Tuple<StorageObject, ?> tuple : request) {
342342
Tuple<I, StorageServiceException> result = results.get(tuple.x());
343343
if (result.x() != null) {
344-
response.add(new BatchResponse.Result<>(transform.apply(result.x())));
344+
response.add(BatchResponse.Result.of(transform.apply(result.x())));
345345
} else {
346346
StorageServiceException exception = result.y();
347347
if (nullOnErrorCodesSet.contains(exception.code())) {
348348
//noinspection unchecked
349349
response.add(BatchResponse.Result.<O>empty());
350350
} else {
351-
response.add(new BatchResponse.Result<O>(result.y()));
351+
response.add(new BatchResponse.Result<O>(exception));
352352
}
353353
}
354354
}

src/test/java/com/google/gcloud/datastore/BaseEntityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed 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 com.google.gcloud.datastore;import static junit.framework.TestCase.assertFalse;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertTrue;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableSet;import org.junit.Before;import org.junit.Test;import java.util.Calendar;import java.util.Collections;import java.util.List;import java.util.Set;public class BaseEntityTest { private static final Blob BLOB = Blob.copyFrom(new byte[]{1, 2}); private static final DateTime DATE_TIME = DateTime.now(); private static final Key KEY = Key.builder("ds1", "k1", "n1").build(); private static final Entity ENTITY = Entity.builder(KEY).set("name", "foo").build(); private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder("ds1", "k1").build(); private static final FullEntity<IncompleteKey> PARTIAL_ENTITY = Entity.builder(INCOMPLETE_KEY).build(); private Builder builder; private class Builder extends BaseEntity.Builder { @Override public BaseEntity build() { return new BaseEntity(this) { @Override protected Builder emptyBuilder() { return new BaseEntityTest.Builder(); } }; } } @Before public void setUp() { builder = new Builder(); builder.set("blob", BLOB).set("boolean", true).set("dateTime", DATE_TIME); builder.set("double", 1.25).set("key", KEY).set("string", "hello world"); builder.set("long", 125).setNull("null").set("entity", ENTITY); builder.set("partialEntity", PARTIAL_ENTITY).set("stringValue", StringValue.of("bla")); builder.set("list1", NullValue.of(), StringValue.of("foo")); builder.set("list2", ImmutableList.of(LongValue.of(10), DoubleValue.of(2))); builder.set("list3", Collections.singletonList(BooleanValue.of(true))); } @Test public void testContains() throws Exception { BaseEntity entity = builder.build(); assertTrue(entity.contains("list1")); assertFalse(entity.contains("bla")); entity = builder.clear().build(); assertFalse(entity.contains("list1")); } @Test public void testGetValue() throws Exception { BaseEntity entity = builder.build(); assertEquals(BlobValue.of(BLOB), entity.getValue("blob")); } @Test(expected = DatastoreServiceException.class) public void testGetValueNotFound() throws Exception { BaseEntity entity = builder.clear().build(); entity.getValue("blob"); } @Test public void testIsNull() throws Exception { BaseEntity entity = builder.build(); assertTrue(entity.isNull("null")); assertFalse(entity.isNull("blob")); entity = builder.setNull("blob").build(); assertTrue(entity.isNull("blob")); } @Test(expected = DatastoreServiceException.class) public void testIsNullNotFound() throws Exception { BaseEntity entity = builder.clear().build(); entity.isNull("null"); } @Test public void testGetString() throws Exception { BaseEntity entity = builder.build(); assertEquals("hello world", entity.getString("string")); assertEquals("bla", entity.getString("stringValue")); entity = builder.set("string", "foo").build(); assertEquals("foo", entity.getString("string")); } @Test public void testGetLong() throws Exception { BaseEntity entity = builder.build(); assertEquals(125, entity.getLong("long")); entity = builder.set("long", LongValue.of(10)).build(); assertEquals(10, entity.getLong("long")); } @Test public void testGetDouble() throws Exception { BaseEntity entity = builder.build(); assertEquals(1.25, entity.getDouble("double"), 0); entity = builder.set("double", DoubleValue.of(10)).build(); assertEquals(10, entity.getDouble("double"), 0); } @Test public void testGetBoolean() throws Exception { BaseEntity entity = builder.build(); assertTrue(entity.getBoolean("boolean")); entity = builder.set("boolean", BooleanValue.of(false)).build(); assertFalse(entity.getBoolean("boolean")); } @Test public void testGetDateTime() throws Exception { BaseEntity entity = builder.build(); assertEquals(DATE_TIME, entity.getDateTime("dateTime")); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); DateTime dateTime = DateTime.copyFrom(cal); entity = builder.set("dateTime", DateTimeValue.of(dateTime)).build(); assertEquals(dateTime, entity.getDateTime("dateTime")); } @Test public void testGetKey() throws Exception { BaseEntity entity = builder.build(); assertEquals(KEY, entity.getKey("key")); Key key = Key.builder(KEY).name("BLA").build(); entity = builder.set("key", key).build(); assertEquals(key, entity.getKey("key")); } @Test public void testGetEntity() throws Exception { BaseEntity entity = builder.build(); assertEquals(ENTITY, entity.getEntity("entity")); assertEquals(PARTIAL_ENTITY, entity.getEntity("partialEntity")); entity = builder.set("entity", EntityValue.of(PARTIAL_ENTITY)).build(); assertEquals(PARTIAL_ENTITY, entity.getEntity("entity")); } @Test public void testGetList() throws Exception { BaseEntity entity = builder.build(); List<? extends Value<?>> list = entity.getList("list1"); assertEquals(2, list.size()); assertEquals(NullValue.of(), list.get(0)); assertEquals("foo", list.get(1).get()); list = entity.getList("list2"); assertEquals(2, list.size()); assertEquals(Long.valueOf(10), list.get(0).get()); assertEquals(Double.valueOf(2), list.get(1).get()); list = entity.getList("list3"); assertEquals(1, list.size()); assertEquals(Boolean.TRUE, list.get(0).get()); entity = builder.set("list1", ListValue.of(list)).build(); assertEquals(list, entity.getList("list1")); } @Test public void testGetBlob() throws Exception { BaseEntity entity = builder.build(); assertEquals(BLOB, entity.getBlob("blob")); Blob blob = Blob.copyFrom(new byte[] {}); entity = builder.set("blob", BlobValue.of(blob)).build(); assertEquals(blob, entity.getBlob("blob")); } @Test public void testNames() throws Exception { Set<String> names = ImmutableSet.<String>builder() .add("string", "stringValue", "boolean", "double", "long", "list1", "list2", "list3") .add("entity", "partialEntity", "null", "dateTime", "blob", "key") .build(); BaseEntity entity = builder.build(); assertEquals(names, entity.names()); }}
1+
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed 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 com.google.gcloud.datastore;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertFalse;import static org.junit.Assert.assertTrue;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableSet;import org.junit.Before;import org.junit.Test;import java.util.Calendar;import java.util.Collections;import java.util.List;import java.util.Set;public class BaseEntityTest { private static final Blob BLOB = Blob.copyFrom(new byte[]{1, 2}); private static final DateTime DATE_TIME = DateTime.now(); private static final Key KEY = Key.builder("ds1", "k1", "n1").build(); private static final Entity ENTITY = Entity.builder(KEY).set("name", "foo").build(); private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder("ds1", "k1").build(); private static final FullEntity<IncompleteKey> PARTIAL_ENTITY = Entity.builder(INCOMPLETE_KEY).build(); private Builder builder; private class Builder extends BaseEntity.Builder { @Override public BaseEntity build() { return new BaseEntity(this) { @Override protected Builder emptyBuilder() { return new BaseEntityTest.Builder(); } }; } } @Before public void setUp() { builder = new Builder(); builder.set("blob", BLOB).set("boolean", true).set("dateTime", DATE_TIME); builder.set("double", 1.25).set("key", KEY).set("string", "hello world"); builder.set("long", 125).setNull("null").set("entity", ENTITY); builder.set("partialEntity", PARTIAL_ENTITY).set("stringValue", StringValue.of("bla")); builder.set("list1", NullValue.of(), StringValue.of("foo")); builder.set("list2", ImmutableList.of(LongValue.of(10), DoubleValue.of(2))); builder.set("list3", Collections.singletonList(BooleanValue.of(true))); } @Test public void testContains() throws Exception { BaseEntity entity = builder.build(); assertTrue(entity.contains("list1")); assertFalse(entity.contains("bla")); entity = builder.clear().build(); assertFalse(entity.contains("list1")); } @Test public void testGetValue() throws Exception { BaseEntity entity = builder.build(); assertEquals(BlobValue.of(BLOB), entity.getValue("blob")); } @Test(expected = DatastoreServiceException.class) public void testGetValueNotFound() throws Exception { BaseEntity entity = builder.clear().build(); entity.getValue("blob"); } @Test public void testIsNull() throws Exception { BaseEntity entity = builder.build(); assertTrue(entity.isNull("null")); assertFalse(entity.isNull("blob")); entity = builder.setNull("blob").build(); assertTrue(entity.isNull("blob")); } @Test(expected = DatastoreServiceException.class) public void testIsNullNotFound() throws Exception { BaseEntity entity = builder.clear().build(); entity.isNull("null"); } @Test public void testGetString() throws Exception { BaseEntity entity = builder.build(); assertEquals("hello world", entity.getString("string")); assertEquals("bla", entity.getString("stringValue")); entity = builder.set("string", "foo").build(); assertEquals("foo", entity.getString("string")); } @Test public void testGetLong() throws Exception { BaseEntity entity = builder.build(); assertEquals(125, entity.getLong("long")); entity = builder.set("long", LongValue.of(10)).build(); assertEquals(10, entity.getLong("long")); } @Test public void testGetDouble() throws Exception { BaseEntity entity = builder.build(); assertEquals(1.25, entity.getDouble("double"), 0); entity = builder.set("double", DoubleValue.of(10)).build(); assertEquals(10, entity.getDouble("double"), 0); } @Test public void testGetBoolean() throws Exception { BaseEntity entity = builder.build(); assertTrue(entity.getBoolean("boolean")); entity = builder.set("boolean", BooleanValue.of(false)).build(); assertFalse(entity.getBoolean("boolean")); } @Test public void testGetDateTime() throws Exception { BaseEntity entity = builder.build(); assertEquals(DATE_TIME, entity.getDateTime("dateTime")); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); DateTime dateTime = DateTime.copyFrom(cal); entity = builder.set("dateTime", DateTimeValue.of(dateTime)).build(); assertEquals(dateTime, entity.getDateTime("dateTime")); } @Test public void testGetKey() throws Exception { BaseEntity entity = builder.build(); assertEquals(KEY, entity.getKey("key")); Key key = Key.builder(KEY).name("BLA").build(); entity = builder.set("key", key).build(); assertEquals(key, entity.getKey("key")); } @Test public void testGetEntity() throws Exception { BaseEntity entity = builder.build(); assertEquals(ENTITY, entity.getEntity("entity")); assertEquals(PARTIAL_ENTITY, entity.getEntity("partialEntity")); entity = builder.set("entity", EntityValue.of(PARTIAL_ENTITY)).build(); assertEquals(PARTIAL_ENTITY, entity.getEntity("entity")); } @Test public void testGetList() throws Exception { BaseEntity entity = builder.build(); List<? extends Value<?>> list = entity.getList("list1"); assertEquals(2, list.size()); assertEquals(NullValue.of(), list.get(0)); assertEquals("foo", list.get(1).get()); list = entity.getList("list2"); assertEquals(2, list.size()); assertEquals(Long.valueOf(10), list.get(0).get()); assertEquals(Double.valueOf(2), list.get(1).get()); list = entity.getList("list3"); assertEquals(1, list.size()); assertEquals(Boolean.TRUE, list.get(0).get()); entity = builder.set("list1", ListValue.of(list)).build(); assertEquals(list, entity.getList("list1")); } @Test public void testGetBlob() throws Exception { BaseEntity entity = builder.build(); assertEquals(BLOB, entity.getBlob("blob")); Blob blob = Blob.copyFrom(new byte[] {}); entity = builder.set("blob", BlobValue.of(blob)).build(); assertEquals(blob, entity.getBlob("blob")); } @Test public void testNames() throws Exception { Set<String> names = ImmutableSet.<String>builder() .add("string", "stringValue", "boolean", "double", "long", "list1", "list2", "list3") .add("entity", "partialEntity", "null", "dateTime", "blob", "key") .build(); BaseEntity entity = builder.build(); assertEquals(names, entity.names()); }}

src/test/java/com/google/gcloud/datastore/BlobValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.google.gcloud.datastore;
1818

19-
import static junit.framework.TestCase.assertFalse;
2019
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
2121
import static org.junit.Assert.assertTrue;
2222

2323
import org.junit.Test;

src/test/java/com/google/gcloud/datastore/BooleanValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.google.gcloud.datastore;
1818

19-
import static junit.framework.TestCase.assertFalse;
2019
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
2121
import static org.junit.Assert.assertTrue;
2222

2323
import org.junit.Test;

src/test/java/com/google/gcloud/datastore/DatastoreHelperTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616

1717
package com.google.gcloud.datastore;
1818

19-
import static junit.framework.TestCase.assertTrue;
20-
import static junit.framework.TestCase.fail;
21-
import static org.easymock.EasyMock.*;
22-
import static org.junit.Assert.*;
19+
import static org.easymock.EasyMock.createMock;
20+
import static org.easymock.EasyMock.createStrictMock;
21+
import static org.easymock.EasyMock.expect;
22+
import static org.easymock.EasyMock.replay;
23+
import static org.easymock.EasyMock.verify;
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertNull;
26+
import static org.junit.Assert.assertSame;
27+
import static org.junit.Assert.assertTrue;
28+
import static org.junit.Assert.fail;
2329

2430
import com.google.common.collect.Iterators;
2531
import com.google.gcloud.datastore.DatastoreService.TransactionCallable;
32+
2633
import org.easymock.EasyMock;
2734
import org.junit.Test;
2835

0 commit comments

Comments
 (0)