querys = new ArrayList<>();
+ CollectionReference cities = db.collection("cities");
+
+ // [START fs_simple_queries]
+ Query countryQuery = cities.whereEqualTo("state", "CA");
+ Query populationQuery = cities.whereLessThan("population", 1000000L);
+ Query cityQuery = cities.whereGreaterThanOrEqualTo("name", "San Francisco");
+ // [END fs_simple_queries]
+
+ querys.add(countryQuery);
+ querys.add(populationQuery);
+ querys.add(cityQuery);
+ return querys;
+ }
+
+ /**
+ * Creates chained where clauses.
+ *
+ * Note : equality and inequality clauses over multiple fields cannot be chained.
+ *
+ * @return query
+ */
+ Query createChainedQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_chained_query]
+ Query chainedQuery1 = cities.whereEqualTo("state", "CO")
+ .whereEqualTo("name", "Denver");
+ // [END fs_chained_query]
+ return chainedQuery1;
+ }
+
+ /**
+ * An instance of a currently unsupported chained query: equality with inequality.
+ * NOTE : Requires support for creation of composite indices.
+ *
+ * @return query
+ */
+ Query createCompositeIndexChainedQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_composite_index_chained_query]
+ Query chainedQuery2 = cities.whereEqualTo("state", "CA")
+ .whereLessThan("population", 1000000L);
+ // [END fs_composite_index_chained_query]
+ return chainedQuery2;
+ }
+
+ /**
+ * An instance of a valid range/inequality query : range operators are limited to a single field.
+ *
+ * @return query
+ */
+ Query createRangeQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_range_query]
+ Query validQuery1 = cities.whereGreaterThanOrEqualTo("state", "CA")
+ .whereLessThanOrEqualTo("state", "IN");
+ Query validQuery2 = cities.whereEqualTo("state", "CA")
+ .whereGreaterThan("population", 1000000);
+ // [END fs_range_query]
+ return validQuery1;
+ }
+
+ /**
+ * An instance of an invalid range query : range operators are limited to a single field.
+ *
+ * @return query
+ */
+ Query createInvalidRangeQuery() {
+ CollectionReference cities = db.collection("cities");
+ // Violates constraint : range operators are limited to a single field
+ // [START fs_invalid_range_query]
+ Query invalidRangeQuery = cities.whereGreaterThanOrEqualTo("state", "CA")
+ .whereGreaterThan("population", 100000);
+ // [END fs_invalid_range_query]
+ return invalidRangeQuery;
+ }
+
+ /**
+ * Creates a query that combines order by with limit.
+ *
+ * @return query
+ */
+ Query createOrderByNameWithLimitQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_order_by_name_limit_query]
+ Query query = cities.orderBy("name").limit(3);
+ // [END fs_order_by_name_limit_query]
+ return query;
+ }
+
+ /**
+ * Creates a query that orders by country and population(descending).
+ *
+ * @return query
+ */
+ Query createOrderByCountryAndPopulation() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_order_by_country_population]
+ Query query = cities.orderBy("state").orderBy("population", Direction.DESCENDING);
+ // [END fs_order_by_country_population]
+ return query;
+ }
+
+ /**
+ * Creates a query that combines order by in descending order with the limit operator.
+ *
+ * @return query
+ */
+ Query createOrderByNameDescWithLimitQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_order_by_name_desc_limit_query]
+ Query query = cities.orderBy("name", Direction.DESCENDING).limit(3);
+ // [END fs_order_by_name_desc_limit_query]
+ return query;
+ }
+
+ /**
+ * Creates a query that combines where clause with order by and limit operator.
+ *
+ * @return query
+ */
+ Query createWhereWithOrderByAndLimitQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_where_order_by_limit_query]
+ Query query = cities.whereGreaterThan("population", 2500000L).orderBy("population").limit(2);
+ // [END fs_where_order_by_limit_query]
+ return query;
+ }
+
+ /**
+ * Creates a query using a range where clause with order by. Order by must be based on the same
+ * field as the range clause.
+ *
+ * @return query
+ */
+ Query createRangeWithOrderByQuery() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_range_order_by_query]
+ Query query = cities.whereGreaterThan("population", 2500000L).orderBy("population");
+ // [END fs_range_order_by_query]
+ return query;
+ }
+
+ /**
+ * Creates an instance of an invalid range combined with order. Violates the constraint that range
+ * and order by are required to be on the same field.
+ *
+ * @return query
+ */
+ Query createInvalidRangeWithOrderByQuery() {
+ CollectionReference cities = db.collection("cities");
+ // Violates the constraint that range and order by are required to be on the same field
+ // [START fs_invalid_range_order_by_query]
+ Query query = cities.whereGreaterThan("population", 2500000L).orderBy("country");
+ // [END fs_invalid_range_order_by_query]
+ return query;
+ }
+
+ /**
+ * Create a query defining the start point of a query.
+ *
+ * @return query
+ */
+ Query createStartAtFieldQueryCursor() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_start_at_field_query_cursor]
+ Query query = cities.orderBy("population").startAt(4921000L);
+ // [END fs_start_at_field_query_cursor]
+ return query;
+ }
+
+ /**
+ * Create a query defining the start point of a query.
+ *
+ * @return query
+ */
+ Query createEndAtFieldQueryCursor() {
+ CollectionReference cities = db.collection("cities");
+ // [START fs_end_at_field_query_cursor]
+ Query query = cities.orderBy("population").endAt(4921000L);
+ // [END fs_end_at_field_query_cursor]
+ return query;
+ }
+
+ /* Create queries with multiple cursor conditions. */
+ void createMultipleCursorConditionsQuery() {
+ // [START fs_multiple_cursor_conditions]
+ // Will return all Springfields
+ Query query1 = db.collection("cities")
+ .orderBy("name")
+ .orderBy("state")
+ .startAt("Springfield");
+
+ // Will return "Springfield, Missouri" and "Springfield, Wisconsin"
+ Query query2 = db.collection("cities")
+ .orderBy("name")
+ .orderBy("state")
+ .startAt("Springfield", "Missouri");
+ // [END fs_multiple_cursor_conditions]
+ }
+}
diff --git a/firestore/src/main/java/com/example/firestore/snippets/References.java b/firestore/src/main/java/com/example/firestore/snippets/References.java
new file mode 100644
index 00000000000..52c4df728a0
--- /dev/null
+++ b/firestore/src/main/java/com/example/firestore/snippets/References.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore.snippets;
+
+import com.google.cloud.firestore.CollectionReference;
+import com.google.cloud.firestore.DocumentReference;
+import com.google.cloud.firestore.Firestore;
+
+/** Examples of references to a collection, document in a collection and subcollection. */
+public class References {
+
+ private final Firestore db;
+
+ public References(Firestore db) {
+ this.db = db;
+ }
+
+ /**
+ * Return a reference to collection.
+ *
+ * @return collection reference
+ */
+ public CollectionReference getACollectionRef() {
+ // [START fs_collection_ref]
+ // Reference to the collection "users"
+ CollectionReference collection = db.collection("users");
+ // [END fs_collection_ref]
+ return collection;
+ }
+
+ /**
+ * Return a reference to a document.
+ *
+ * @return document reference
+ */
+ public DocumentReference getADocumentRef() {
+ // [START fs_document_ref]
+ // Reference to a document with id "alovelace" in the collection "employees"
+ DocumentReference document = db.collection("users").document("alovelace");
+ // [END fs_document_ref]
+ return document;
+ }
+
+ /**
+ * Return a reference to a document using path.
+ *
+ * @return document reference
+ */
+ public DocumentReference getADocumentRefUsingPath() {
+ // [START fs_document_path_ref]
+ // Reference to a document with id "alovelace" in the collection "employees"
+ DocumentReference document = db.document("users/alovelace");
+ // [END fs_document_path_ref]
+ return document;
+ }
+
+ /**
+ * Return a reference to a document in a sub-collection.
+ *
+ * @return document reference in a subcollection
+ */
+ public DocumentReference getASubCollectionDocumentRef() {
+ // [START fs_subcollection_ref]
+ // Reference to a document in subcollection "messages"
+ DocumentReference document =
+ db.collection("rooms").document("roomA").collection("messages").document("message1");
+ // [END fs_subcollection_ref]
+ return document;
+ }
+}
diff --git a/firestore/src/main/java/com/example/firestore/snippets/RetrieveDataSnippets.java b/firestore/src/main/java/com/example/firestore/snippets/RetrieveDataSnippets.java
new file mode 100644
index 00000000000..e3c7515f841
--- /dev/null
+++ b/firestore/src/main/java/com/example/firestore/snippets/RetrieveDataSnippets.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore.snippets;
+
+import com.example.firestore.snippets.model.City;
+
+import com.google.api.core.ApiFuture;
+import com.google.api.core.ApiFutures;
+import com.google.cloud.firestore.CollectionReference;
+import com.google.cloud.firestore.DocumentReference;
+import com.google.cloud.firestore.DocumentSnapshot;
+import com.google.cloud.firestore.Firestore;
+import com.google.cloud.firestore.QuerySnapshot;
+import com.google.cloud.firestore.WriteResult;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/** Snippets to demonstrate Firestore data retrieval operations. */
+public class RetrieveDataSnippets {
+
+ private final Firestore db;
+
+ RetrieveDataSnippets(Firestore db) {
+ this.db = db;
+ }
+
+ /** Create cities collection and add sample documents. */
+ void prepareExamples() throws Exception {
+ // [START fs_retrieve_create_examples]
+ CollectionReference cities = db.collection("cities");
+ List> futures = new ArrayList<>();
+ futures.add(cities.document("SF").set(new City("San Francisco", "CA", "USA", false, 860000L)));
+ futures.add(cities.document("LA").set(new City("Los Angeles", "CA", "USA", false, 3900000L)));
+ futures.add(cities.document("DC").set(new City("Washington D.C.", null, "USA", true, 680000L)));
+ futures.add(cities.document("TOK").set(new City("Tokyo", null, "Japan", true, 9000000L)));
+ futures.add(cities.document("BJ").set(new City("Beijing", null, "China", true, 21500000L)));
+ // (optional) block on operation
+ ApiFutures.allAsList(futures).get();
+ // [END fs_retrieve_create_examples]
+ }
+
+ /**
+ * Retrieves document in collection as map.
+ *
+ * @return map (string => object)
+ */
+ public Map getDocumentAsMap() throws Exception {
+ // [START fs_get_doc_as_map]
+ DocumentReference docRef = db.collection("cities").document("SF");
+ // asynchronously retrieve the document
+ ApiFuture future = docRef.get();
+ // ...
+ // future.get() blocks on response
+ DocumentSnapshot document = future.get();
+ if (document.exists()) {
+ System.out.println("Document data: " + document.getData());
+ } else {
+ System.out.println("No such document!");
+ }
+ // [END fs_get_doc_as_map]
+ return (document.exists()) ? document.getData() : null;
+ }
+
+ /**
+ * Retrieves document in collection as a custom object.
+ *
+ * @return document data as City object
+ */
+ public City getDocumentAsEntity() throws Exception {
+ // [START fs_get_doc_as_entity]
+ DocumentReference docRef = db.collection("cities").document("BJ");
+ // asynchronously retrieve the document
+ ApiFuture future = docRef.get();
+ // block on response
+ DocumentSnapshot document = future.get();
+ City city = null;
+ if (document.exists()) {
+ // convert document to POJO
+ city = document.toObject(City.class);
+ System.out.println(city);
+ } else {
+ System.out.println("No such document!");
+ }
+ // [END fs_get_doc_as_entity]
+ return city;
+ }
+
+ /**
+ * Return multiple documents from a collection based on a query.
+ *
+ * @return list of documents of capital cities.
+ */
+ public List getQueryResults() throws Exception {
+ // [START fs_get_multiple_docs]
+ //asynchronously retrieve multiple documents
+ ApiFuture future =
+ db.collection("cities").whereEqualTo("capital", true).get();
+ // future.get() blocks on response
+ List documents = future.get().getDocuments();
+ for (DocumentSnapshot document : documents) {
+ System.out.println(document.getId() + " => " + document.toObject(City.class));
+ }
+ // [END fs_get_multiple_docs]
+ return documents;
+ }
+
+ /**
+ * Return all documents in the cities collection.
+ *
+ * @return list of documents
+ */
+ public List getAllDocuments() throws Exception {
+ // [START fs_get_all_docs]
+ //asynchronously retrieve all documents
+ ApiFuture future = db.collection("cities").get();
+ // future.get() blocks on response
+ List documents = future.get().getDocuments();
+ for (DocumentSnapshot document : documents) {
+ System.out.println(document.getId() + " => " + document.toObject(City.class));
+ }
+ // [END fs_get_all_docs]
+ return documents;
+ }
+}
diff --git a/firestore/src/main/java/com/example/firestore/snippets/model/City.java b/firestore/src/main/java/com/example/firestore/snippets/model/City.java
new file mode 100644
index 00000000000..c3cc3ebcd5e
--- /dev/null
+++ b/firestore/src/main/java/com/example/firestore/snippets/model/City.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore.snippets.model;
+
+import java.util.Objects;
+
+/** Represents a city : name, weather, population, country, capital, geo coordinates. */
+public class City {
+
+ private String name;
+ private String state;
+ private String country;
+ private Boolean capital;
+ private Long population;
+
+ // [START fs_class_definition]
+ public City() {
+ // Must have a public no-argument constructor
+ }
+
+ // Initialize all fields of a city
+ public City(String name, String state, String country, Boolean capital, Long population) {
+ this.name = name;
+ this.state = state;
+ this.country = country;
+ this.capital = capital;
+ this.population = population;
+ }
+ // [END fs_class_definition]
+
+ public City(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public Boolean getCapital() {
+ return capital;
+ }
+
+ public void setCapital(Boolean capital) {
+ this.capital = capital;
+ }
+
+ public Long getPopulation() {
+ return population;
+ }
+
+ public void setPopulation(Long population) {
+ this.population = population;
+ }
+
+ private String getDefinedValue(String s) {
+ if (s != null) {
+ return s;
+ } else {
+ return "";
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if (name != null) {
+ sb.append(name);
+ }
+ if (state != null) {
+ sb.append(" state : ");
+ sb.append(state);
+ sb.append(",");
+ }
+ if (country != null) {
+ sb.append(", ");
+ sb.append(country);
+ }
+ sb.append(" : [");
+ if (population != null) {
+ sb.append(" population : ");
+ sb.append(population);
+ sb.append(",");
+ }
+ if (capital != null) {
+ sb.append(" capital : ");
+ sb.append(capital);
+ sb.append(",");
+ }
+ //remove trailing comma
+ if (sb.lastIndexOf(",") >= sb.length() - 1) {
+ sb.deleteCharAt(sb.length() - 1);
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof City)) {
+ return false;
+ }
+ City city = (City) obj;
+ return Objects.equals(name, city.name)
+ && Objects.equals(state, city.state)
+ && Objects.equals(country, city.country)
+ && Objects.equals(population, city.population)
+ && Objects.equals(capital, city.capital);
+
+ }
+}
diff --git a/firestore/src/test/java/com/example/firestore/QuickstartIT.java b/firestore/src/test/java/com/example/firestore/QuickstartIT.java
new file mode 100644
index 00000000000..a84d45ce1ad
--- /dev/null
+++ b/firestore/src/test/java/com/example/firestore/QuickstartIT.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore;
+
+import static org.junit.Assert.assertTrue;
+
+import com.google.api.core.ApiFuture;
+
+import com.google.cloud.firestore.DocumentReference;
+import com.google.cloud.firestore.DocumentSnapshot;
+import com.google.cloud.firestore.Firestore;
+import com.google.cloud.firestore.QuerySnapshot;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class QuickstartIT {
+
+ private Quickstart quickstart;
+ private Firestore db;
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+ private String projectId = "java-docs-samples-firestore";
+
+ @Before
+ public void setUp() throws Exception {
+ quickstart = new Quickstart(projectId);
+ db = quickstart.getDb();
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ deleteAllDocuments();
+ }
+
+ @Test
+ public void testQuickstart() throws Exception {
+ addData();
+
+ bout.reset();
+ quickstart.runAQuery();
+ String output = bout.toString();
+ // confirm that results do not contain aturing
+ assertTrue(output.contains("alovelace"));
+ assertTrue(output.contains("cbabbage"));
+ assertTrue(!output.contains("aturing"));
+
+ bout.reset();
+ quickstart.retrieveAllDocuments();
+ output = bout.toString();
+ // confirm that all documents are retrieved
+ assertTrue(output.contains("alovelace"));
+ assertTrue(output.contains("aturing"));
+ assertTrue(output.contains("cbabbage"));
+ }
+
+ private void validate(DocumentReference docRef, Map data) throws Exception {
+ DocumentSnapshot documentSnapshot = docRef.get().get();
+ assertTrue(Objects.equals(documentSnapshot.getData(), data));
+ }
+
+ private void addData() throws Exception {
+ Map expectedData = new HashMap<>();
+
+ quickstart.addDocument("alovelace");
+ expectedData.put("first", "Ada");
+ expectedData.put("last", "Lovelace");
+ expectedData.put("born", 1815L);
+ validate(db.document("users/alovelace"), expectedData);
+
+ expectedData.clear();
+ expectedData.put("first", "Alan");
+ expectedData.put("middle", "Mathison");
+ expectedData.put("last", "Turing");
+ expectedData.put("born", 1912L);
+ quickstart.addDocument("aturing");
+ validate(db.document("users/aturing"), expectedData);
+
+ expectedData.clear();
+ expectedData.put("first", "Charles");
+ expectedData.put("last", "Babbage");
+ expectedData.put("born", 1791L);
+ quickstart.addDocument("cbabbage");
+ validate(db.document("users/cbabbage"), expectedData);
+ }
+
+ private void deleteAllDocuments() throws Exception {
+ ApiFuture future = db.collection("users").get();
+ QuerySnapshot querySnapshot = future.get();
+ for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
+ // block on delete operation
+ db.document("users/" + doc.getId()).delete().get();
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ deleteAllDocuments();
+ }
+}
diff --git a/firestore/src/test/java/com/example/firestore/snippets/ManageDataSnippetsIT.java b/firestore/src/test/java/com/example/firestore/snippets/ManageDataSnippetsIT.java
new file mode 100644
index 00000000000..c0a95fdd651
--- /dev/null
+++ b/firestore/src/test/java/com/example/firestore/snippets/ManageDataSnippetsIT.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore.snippets;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.example.firestore.snippets.model.City;
+import com.google.api.core.ApiFuture;
+import com.google.cloud.firestore.CollectionReference;
+import com.google.cloud.firestore.DocumentReference;
+import com.google.cloud.firestore.DocumentSnapshot;
+import com.google.cloud.firestore.Firestore;
+import com.google.cloud.firestore.FirestoreOptions;
+import com.google.cloud.firestore.QuerySnapshot;
+import java.util.Date;
+import java.util.Map;
+import java.util.Objects;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class ManageDataSnippetsIT {
+
+ private static Firestore db;
+ private static ManageDataSnippets manageDataSnippets;
+ private static String projectId = "java-docs-samples-firestore";
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder()
+ .setProjectId(projectId)
+ .build();
+ db = firestoreOptions.getService();
+ deleteAllDocuments();
+ manageDataSnippets = new ManageDataSnippets(db);
+ }
+
+ @Test
+ public void testAddDatasMap() throws Exception {
+ Map expectedData = manageDataSnippets.addSimpleDocumentAsMap();
+ DocumentReference docRef = db.collection("cities").document("LA");
+ assertTrue(Objects.equals(expectedData, getDocumentDataAsMap(docRef)));
+ }
+
+ @Test
+ public void testAddDataWithDifferentDataTypes() throws Exception {
+ Map expectedData = manageDataSnippets.addDocumentWithDifferentDataTypes();
+ DocumentReference docRef = db.collection("data").document("one");
+ assertEquals(expectedData, getDocumentDataAsMap(docRef));
+ }
+
+ @Test
+ public void testAddDataAsEntity() throws Exception {
+ City city = manageDataSnippets.addSimpleDocumentAsEntity();
+ DocumentReference docRef = db.collection("cities").document("LA");
+ assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
+ }
+
+ @Test
+ public void testAddDocWithAutoGenId() throws Exception {
+ String autoId = manageDataSnippets.addDocumentDataWithAutoGeneratedId();
+ City city = new City("Tokyo");
+ city.setCountry("Japan");
+ DocumentReference docRef = db.collection("cities").document(autoId);
+ assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
+ }
+
+ @Test
+ public void testAddDocAfterAutoGenId() throws Exception {
+ String autoId = manageDataSnippets.addDocumentDataAfterAutoGeneratingId();
+ City city = new City();
+ DocumentReference docRef = db.collection("cities").document(autoId);
+ assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
+ }
+
+ @Test
+ public void testUpdateSimpleDocument() throws Exception {
+ manageDataSnippets.updateSimpleDocument();
+ DocumentReference docRef = db.collection("cities").document("DC");
+ City city = new City("Washington D.C.");
+ city.setCapital(true);
+ assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
+ }
+
+ @Test
+ public void testUpdateUsingMap() throws Exception {
+ manageDataSnippets.updateUsingMap();
+ DocumentReference docRef = db.collection("cities").document("DC");
+ City city = new City("Washington D.C.");
+ city.setCapital(true);
+ city.setCountry("USA");
+ assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
+ }
+
+ @Test
+ public void testUpdateAndCreateIfMissing() throws Exception {
+ manageDataSnippets.updateAndCreateIfMissing();
+ DocumentReference docRef = db.collection("cities").document("BJ");
+ assertTrue(getDocumentDataAsCity(docRef).getCapital());
+ }
+
+ @Test
+ public void testUpdateNestedFields() throws Exception {
+ manageDataSnippets.updateNestedFields();
+ DocumentReference docRef = db.collection("users").document("frank");
+
+ DocumentSnapshot snapshot = getDocumentData(docRef);
+ assertEquals((long) snapshot.getLong("age"), 13);
+ assertEquals(snapshot.getString("favorites.color"), "Red");
+ assertEquals(snapshot.getString("favorites.food"), "Pizza");
+ }
+
+ @Test
+ public void testUpdateServerTimestamp() throws Exception {
+ manageDataSnippets.updateServerTimestamp();
+ DocumentReference docRef = db.collection("objects").document("some-id");
+ Map data = getDocumentDataAsMap(docRef);
+ assertTrue(data.get("timestamp") instanceof Date);
+ }
+
+ @Test
+ public void testDeleteFields() throws Exception {
+ manageDataSnippets.deleteFields();
+ DocumentReference docRef = db.collection("cities").document("BJ");
+ Map data = getDocumentDataAsMap(docRef);
+ assertFalse(data.containsKey("capital"));
+ }
+
+ @Test(expected = Exception.class)
+ public void testDeleteDocument() throws Exception {
+ manageDataSnippets.deleteDocument();
+ getDocumentDataAsMap(db.collection("cities").document("DC"));
+ }
+
+ @Test
+ public void testSimpleTransaction() throws Exception {
+ DocumentReference docRef = db.collection("cities").document("SF");
+ ApiFuture future = manageDataSnippets.runSimpleTransaction();
+ future.get();
+ Map data = getDocumentDataAsMap(docRef);
+ assertEquals(data.get("population"), 860000L + 1L);
+ }
+
+ @Test
+ public void testTransactionReturnsInfo() throws Exception {
+ String info = manageDataSnippets.returnInfoFromTransaction(50L);
+ assertEquals(info, "Population increased to 51");
+ try {
+ info = manageDataSnippets.returnInfoFromTransaction(5000001L);
+ assertTrue("Should never get here", false);
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("Sorry! Population is too big."));
+ }
+ }
+
+ @Test
+ public void testWriteBatchIsSuccessful() throws Exception {
+ manageDataSnippets.writeBatch();
+ CollectionReference collection = db.collection("cities");
+ ApiFuture document = collection.document("NYC").get();
+ assertTrue(document.get().exists());
+ DocumentReference documentReference = collection.document("SF");
+ Map data = getDocumentDataAsMap(documentReference);
+ assertTrue(data.containsKey("population"));
+ document = collection.document("LA").get();
+ assertFalse(document.get().exists());
+ }
+
+ private DocumentSnapshot getDocumentData(DocumentReference docRef) throws Exception {
+ return docRef.get().get();
+ }
+
+ private Map getDocumentDataAsMap(DocumentReference docRef) throws Exception {
+ return docRef.get().get().getData();
+ }
+
+ private City getDocumentDataAsCity(DocumentReference docRef) throws Exception {
+ return docRef.get().get().toObject(City.class);
+ }
+
+ private static void deleteAllDocuments() throws Exception {
+ ApiFuture future = db.collection("cities").get();
+ QuerySnapshot querySnapshot = future.get();
+ for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
+ // block on delete operation
+ db.collection("cities").document(doc.getId()).delete().get();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ manageDataSnippets.deleteCollection(db.collection("cities"), 10);
+ manageDataSnippets.deleteCollection(db.collection("users"), 10);
+ }
+}
diff --git a/firestore/src/test/java/com/example/firestore/snippets/QueryDataSnippetsIT.java b/firestore/src/test/java/com/example/firestore/snippets/QueryDataSnippetsIT.java
new file mode 100644
index 00000000000..3b93a38bac9
--- /dev/null
+++ b/firestore/src/test/java/com/example/firestore/snippets/QueryDataSnippetsIT.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore.snippets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.google.api.core.ApiFuture;
+import com.google.cloud.firestore.DocumentSnapshot;
+import com.google.cloud.firestore.Firestore;
+import com.google.cloud.firestore.FirestoreOptions;
+import com.google.cloud.firestore.Query;
+import com.google.cloud.firestore.QuerySnapshot;
+import com.google.common.collect.ImmutableMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class QueryDataSnippetsIT {
+
+ private static Firestore db;
+ private static QueryDataSnippets queryDataSnippets;
+ private static String projectId = "java-docs-samples-firestore";
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder()
+ .setProjectId(projectId)
+ .build();
+ db = firestoreOptions.getService();
+ deleteAllDocuments();
+ queryDataSnippets = new QueryDataSnippets(db);
+ queryDataSnippets.prepareExamples();
+ }
+
+ @Test
+ public void testCreateAQuery() throws Exception {
+ Query q = queryDataSnippets.createAQuery();
+ Set result = getResultsAsSet(q);
+ Set expectedResults = new HashSet<>(Arrays.asList("DC", "TOK", "BJ"));
+ assertTrue(Objects.equals(result, expectedResults));
+ }
+
+ @Test
+ public void testSimpleQueryReturnsExpectedResults() throws Exception {
+ List> expectedResults = new ArrayList<>();
+
+ expectedResults.add(new HashSet<>(Arrays.asList("SF", "LA")));
+ expectedResults.add(new HashSet<>(Arrays.asList("SF", "DC")));
+ expectedResults.add(new HashSet<>(Arrays.asList("SF", "DC", "TOK")));
+
+ List queries = queryDataSnippets.createSimpleQueries();
+ for (int i = 0; i < queries.size(); i++) {
+ Set results = getResultsAsSet(queries.get(i));
+ assertTrue(Objects.equals(results, expectedResults.get(i)));
+ }
+ }
+
+ @Test
+ public void testChainedQuery() throws Exception {
+ Query q = queryDataSnippets.createChainedQuery();
+ Set result = getResultsAsSet(q);
+ Set expectedResults = new HashSet<>();
+ assertTrue(Objects.equals(result, expectedResults));
+ }
+
+ @Test
+ public void testRangeQuery() throws Exception {
+ Query q = queryDataSnippets.createRangeQuery();
+ Set result = getResultsAsSet(q);
+ Set expectedResults = new HashSet<>(Arrays.asList("SF", "LA"));
+ assertTrue(Objects.equals(result, expectedResults));
+ }
+
+ @Test(expected = Exception.class)
+ public void testInvalidRangeQueryThrowsException() throws Exception {
+ Query q = queryDataSnippets.createInvalidRangeQuery();
+ getResults(q);
+ }
+
+ @Test
+ public void testOrderByNameWithLimitQuery() throws Exception {
+ Query q = queryDataSnippets.createOrderByNameWithLimitQuery();
+ List result = getResults(q);
+ List expectedResults = Arrays.asList("BJ", "LA", "SF");
+ assertEquals(result, expectedResults);
+ }
+
+ @Test
+ public void testOrderByNameDescWithLimitQuery() throws Exception {
+ Query q = queryDataSnippets.createOrderByNameDescWithLimitQuery();
+ List result = getResults(q);
+ List expectedResults = Arrays.asList("DC", "TOK", "SF");
+ assertTrue(Objects.equals(result, expectedResults));
+ }
+
+ @Test
+ public void testWhereWithOrderByAndLimitQuery() throws Exception {
+ Query q = queryDataSnippets.createWhereWithOrderByAndLimitQuery();
+ List result = getResults(q);
+ List expectedResults = Arrays.asList("LA", "TOK");
+ assertEquals(result, expectedResults);
+ }
+
+ @Test
+ public void testRangeWithOrderByQuery() throws Exception {
+ Query q = queryDataSnippets.createRangeWithOrderByQuery();
+ List result = getResults(q);
+ List expectedResults = Arrays.asList("LA", "TOK", "BJ");
+ assertEquals(result, expectedResults);
+ }
+
+ @Test(expected = Exception.class)
+ public void testInvalidRangeWithOrderByQuery() throws Exception {
+ Query q = queryDataSnippets.createInvalidRangeWithOrderByQuery();
+ getResults(q);
+ }
+
+ @Test
+ public void testStartAtFieldQueryCursor() throws Exception {
+ Query q = queryDataSnippets.createStartAtFieldQueryCursor();
+ List expectedResults = Arrays.asList("TOK", "BJ");
+ List result = getResults(q);
+ assertTrue(Objects.equals(result, expectedResults));
+ }
+
+ @Test
+ public void testEndAtFieldQueryCursor() throws Exception {
+ Query q = queryDataSnippets.createEndAtFieldQueryCursor();
+ List expectedResults = Arrays.asList("DC", "SF", "LA");
+ List result = getResults(q);
+ assertEquals(result, expectedResults);
+ }
+
+ @Test
+ public void testMultipleCursorConditions() throws Exception {
+ // populate us_cities collection
+ Map city1 = new ImmutableMap.Builder()
+ .put("name", "Springfield").put("state", "Massachusetts").build();
+ Map city2 = new ImmutableMap.Builder()
+ .put("name", "Springfield").put("state", "Missouri").build();
+ Map city3 = new ImmutableMap.Builder()
+ .put("name", "Springfield").put("state", "Wisconsin").build();
+
+ db.collection("us_cities").document("Massachusetts").set(city1).get();
+ db.collection("us_cities").document("Missouri").set(city2).get();
+ db.collection("us_cities").document("Wisconsin").set(city3).get();
+
+ Query query1 = db.collection("us_cities")
+ .orderBy("name")
+ .orderBy("state")
+ .startAt("Springfield");
+
+ // all documents are retrieved
+ QuerySnapshot querySnapshot = query1.get().get();
+ List docs = querySnapshot.getDocuments();
+ assertEquals(3, docs.size());
+
+
+ // Will return "Springfield, Missouri" and "Springfield, Wisconsin"
+ Query query2 = db.collection("us_cities")
+ .orderBy("name")
+ .orderBy("state")
+ .startAt("Springfield", "Missouri");
+
+ // only Missouri and Wisconsin are retrieved
+ List expectedResults = Arrays.asList("Missouri", "Wisconsin");
+ List result = getResults(query2);
+ assertTrue(Objects.equals(result, expectedResults));
+ }
+
+ private Set getResultsAsSet(Query query) throws Exception {
+ List docIds = getResults(query);
+ return new HashSet<>(docIds);
+ }
+
+ private List getResults(Query query) throws Exception {
+ // asynchronously retrieve query results
+ ApiFuture future = query.get();
+ // block on response
+ QuerySnapshot querySnapshot = future.get();
+ List docIds = new ArrayList<>();
+ for (DocumentSnapshot document : querySnapshot.getDocuments()) {
+ docIds.add(document.getId());
+ }
+ return docIds;
+ }
+
+ private static void deleteAllDocuments() throws Exception {
+ ApiFuture future = db.collection("cities").get();
+ QuerySnapshot querySnapshot = future.get();
+ for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
+ // block on delete operation
+ db.collection("cities").document(doc.getId()).delete().get();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ deleteAllDocuments();
+ }
+}
diff --git a/firestore/src/test/java/com/example/firestore/snippets/RetrieveDataSnippetsIT.java b/firestore/src/test/java/com/example/firestore/snippets/RetrieveDataSnippetsIT.java
new file mode 100644
index 00000000000..455733d29d3
--- /dev/null
+++ b/firestore/src/test/java/com/example/firestore/snippets/RetrieveDataSnippetsIT.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.example.firestore.snippets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.example.firestore.snippets.model.City;
+
+import com.google.api.core.ApiFuture;
+import com.google.cloud.firestore.DocumentSnapshot;
+import com.google.cloud.firestore.Firestore;
+import com.google.cloud.firestore.FirestoreOptions;
+import com.google.cloud.firestore.QuerySnapshot;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class RetrieveDataSnippetsIT {
+ private static Firestore db;
+ private static RetrieveDataSnippets retrieveDataSnippets;
+ private static String projectId = "java-docs-samples-firestore";
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder()
+ .setProjectId(projectId)
+ .build();
+ db = firestoreOptions.getService();
+ deleteAllDocuments();
+ retrieveDataSnippets = new RetrieveDataSnippets(db);
+ retrieveDataSnippets.prepareExamples();
+ }
+
+ @Test
+ public void testRetrievalAsMap() throws Exception {
+ Map data = retrieveDataSnippets.getDocumentAsMap();
+ assertEquals(data.get("name"), "San Francisco");
+ assertEquals(data.get("country"), "USA");
+ assertEquals(data.get("capital"), false);
+ assertEquals(data.get("population"), 860000L);
+ }
+
+ @Test
+ public void testRetrieveAsEntity() throws Exception {
+ City city = retrieveDataSnippets.getDocumentAsEntity();
+ assertEquals(city.getName(), "Beijing");
+ assertEquals(city.getCountry(), "China");
+ assertEquals(city.getCapital(), true);
+ assertEquals((long) city.getPopulation(), 21500000L);
+ }
+
+ @Test
+ public void testRetrieveQueryResults() throws Exception {
+ List docs = retrieveDataSnippets.getQueryResults();
+ assertEquals(docs.size(), 3);
+ Set docIds = new HashSet<>();
+ for (DocumentSnapshot doc : docs) {
+ docIds.add(doc.getId());
+ }
+ assertTrue(docIds.contains("BJ") && docIds.contains("TOK") && docIds.contains("DC"));
+ }
+
+ @Test
+ public void testRetrieveAllDocuments() throws Exception {
+ List docs = retrieveDataSnippets.getAllDocuments();
+ assertEquals(docs.size(), 5);
+ Set docIds = new HashSet<>();
+ for (DocumentSnapshot doc : docs) {
+ docIds.add(doc.getId());
+ }
+ assertTrue(
+ docIds.contains("SF")
+ && docIds.contains("LA")
+ && docIds.contains("DC")
+ && docIds.contains("TOK")
+ && docIds.contains("BJ"));
+ }
+
+ private static void deleteAllDocuments() throws Exception {
+ ApiFuture future = db.collection("cities").get();
+ QuerySnapshot querySnapshot = future.get();
+ for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
+ // block on delete operation
+ db.collection("cities").document(doc.getId()).delete().get();
+ }
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ deleteAllDocuments();
+ }
+}
diff --git a/flexible/cloudsql/pom.xml b/flexible/cloudsql/pom.xml
index a73b21ab685..d3bb61ef7f9 100644
--- a/flexible/cloudsql/pom.xml
+++ b/flexible/cloudsql/pom.xml
@@ -53,17 +53,17 @@
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.api-client
google-api-client-appengine
- 1.22.0
+ 1.23.0
com.google.api-client
google-api-client-servlet
- 1.22.0
+ 1.23.0
javax.servlet
diff --git a/flexible/cloudstorage/pom.xml b/flexible/cloudstorage/pom.xml
index 53ae959e11e..e7ed2c91796 100644
--- a/flexible/cloudstorage/pom.xml
+++ b/flexible/cloudstorage/pom.xml
@@ -49,7 +49,7 @@
com.google.cloud
google-cloud-storage
- 1.6.0
+ 1.7.0
diff --git a/flexible/datastore/pom.xml b/flexible/datastore/pom.xml
index f6642e2199b..20bf263adf9 100644
--- a/flexible/datastore/pom.xml
+++ b/flexible/datastore/pom.xml
@@ -49,7 +49,7 @@
com.google.cloud
google-cloud-datastore
- 1.6.0
+ 1.7.0
diff --git a/flexible/errorreporting/pom.xml b/flexible/errorreporting/pom.xml
index 6d4ea073bc9..1f0d1593e0e 100644
--- a/flexible/errorreporting/pom.xml
+++ b/flexible/errorreporting/pom.xml
@@ -47,7 +47,7 @@
com.google.cloud
google-cloud-errorreporting
- 0.24.0-alpha
+ 0.25.0-alpha
diff --git a/flexible/gaeinfo/pom.xml b/flexible/gaeinfo/pom.xml
index 893a573be90..d5366272421 100644
--- a/flexible/gaeinfo/pom.xml
+++ b/flexible/gaeinfo/pom.xml
@@ -39,7 +39,7 @@ Copyright 2017 Google Inc.
com.google.appengine
appengine-api-1.0-sdk
- 1.9.56
+ 1.9.57
@@ -65,7 +65,7 @@ Copyright 2017 Google Inc.
org.thymeleaf
thymeleaf
- 3.0.7.RELEASE
+ 3.0.8.RELEASE
diff --git a/flexible/postgres/pom.xml b/flexible/postgres/pom.xml
index aa3085af3f5..cce8a01d129 100644
--- a/flexible/postgres/pom.xml
+++ b/flexible/postgres/pom.xml
@@ -53,17 +53,17 @@
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.api-client
google-api-client-appengine
- 1.22.0
+ 1.23.0
com.google.api-client
google-api-client-servlet
- 1.22.0
+ 1.23.0
javax.servlet
diff --git a/flexible/pubsub/pom.xml b/flexible/pubsub/pom.xml
index 21adb792d4e..db5f1ab6b8a 100644
--- a/flexible/pubsub/pom.xml
+++ b/flexible/pubsub/pom.xml
@@ -63,12 +63,12 @@
com.google.cloud
google-cloud-pubsub
- 0.24.0-beta
+ 0.25.0-beta
com.google.cloud
google-cloud-datastore
- 1.6.0
+ 1.7.0
@@ -76,13 +76,13 @@
com.google.appengine
appengine-api-stubs
- 1.9.56
+ 1.9.57
test
com.google.appengine
appengine-tools-sdk
- 1.9.56
+ 1.9.57
test
diff --git a/flexible/sparkjava/pom.xml b/flexible/sparkjava/pom.xml
index 01b0f802a5a..a579479342a 100644
--- a/flexible/sparkjava/pom.xml
+++ b/flexible/sparkjava/pom.xml
@@ -61,7 +61,7 @@ limitations under the License.
com.google.cloud
google-cloud-datastore
- 1.6.0
+ 1.7.0
diff --git a/kms/pom.xml b/kms/pom.xml
index c5193aed442..239cf330284 100644
--- a/kms/pom.xml
+++ b/kms/pom.xml
@@ -16,7 +16,7 @@
com.google.apis
google-api-services-cloudkms
- v1-rev20-1.22.0
+ v1-rev22-1.23.0
com.google.guava
@@ -32,12 +32,12 @@
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.http-client
google-http-client-jackson2
- 1.22.0
+ 1.23.0
args4j
diff --git a/language/analysis/pom.xml b/language/analysis/pom.xml
index ffb33e7e931..395bd628f7b 100644
--- a/language/analysis/pom.xml
+++ b/language/analysis/pom.xml
@@ -32,7 +32,7 @@ limitations under the License.
com.google.cloud
google-cloud-language
- 0.24.0-beta
+ 0.25.0-beta
com.google.guava
diff --git a/language/cloud-client/pom.xml b/language/cloud-client/pom.xml
index a05355673d2..4478ed31c64 100644
--- a/language/cloud-client/pom.xml
+++ b/language/cloud-client/pom.xml
@@ -38,7 +38,7 @@
com.google.cloud
google-cloud-language
- 0.24.0-beta
+ 0.25.0-beta
com.google.guava
diff --git a/logging/cloud-client/pom.xml b/logging/cloud-client/pom.xml
index d913f7923f2..3a47ca2fe18 100644
--- a/logging/cloud-client/pom.xml
+++ b/logging/cloud-client/pom.xml
@@ -37,7 +37,7 @@
com.google.cloud
google-cloud-logging
- 1.6.0
+ 1.7.0
diff --git a/mlengine/online-prediction/README.md b/mlengine/online-prediction/README.md
new file mode 100644
index 00000000000..2723b8ceb8c
--- /dev/null
+++ b/mlengine/online-prediction/README.md
@@ -0,0 +1,18 @@
+# Cloud Machine Learning Engine - Online Prediction with Java
+
+## Setup
+This sample demonstrates how to send online prediction requests to your deployed
+model on CMLE.
+Follow the [tutorial](https://cloud.google.com/ml-engine/docs/how-tos/deploying-models)
+to deploy your model first.
+
+This sample is using the [Application Default Credential](https://developers.google.com/identity/protocols/application-default-credentials). You can install the Google Cloud SDK and run:
+gcloud auth application-default login
+
+## Run
+Modify the OnlinePredictionSample.java with your project/model/version information.
+
+Compile the sample code using Maven by running the following command:
+mvn compile
+Execute the sample code using Maven by running the following command:
+mvn -q exec:java
diff --git a/mlengine/online-prediction/input.txt b/mlengine/online-prediction/input.txt
new file mode 100644
index 00000000000..19eb80fdd15
--- /dev/null
+++ b/mlengine/online-prediction/input.txt
@@ -0,0 +1 @@
+{"instances": ["YOUR_INPUT_INSTANCE1", "YOUR_INPUT_INSTANCE2"]}
diff --git a/mlengine/online-prediction/pom.xml b/mlengine/online-prediction/pom.xml
new file mode 100644
index 00000000000..c7e87f0c740
--- /dev/null
+++ b/mlengine/online-prediction/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+ 4.0.0
+ com.google.cloud.samples
+ mlengine-online-prediction
+ 1
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.4.0
+
+
+
+ java
+
+
+
+
+ OnlinePredictionSample
+
+
+ java.util.logging.config.file
+ logging.properties
+
+
+
+
+
+
+
+
+ joda-time
+ joda-time
+ 2.2
+
+
+ com.google.api-client
+ google-api-client
+ 1.22.0
+
+
+ com.google.apis
+ google-api-services-discovery
+ v1-rev58-1.22.0
+
+
+
diff --git a/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java b/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java
new file mode 100644
index 00000000000..6f70dad7009
--- /dev/null
+++ b/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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.
+ */
+
+import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
+import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
+import com.google.api.client.http.FileContent;
+import com.google.api.client.http.GenericUrl;
+import com.google.api.client.http.HttpContent;
+import com.google.api.client.http.HttpRequest;
+import com.google.api.client.http.HttpRequestFactory;
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.http.UriTemplate;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.jackson2.JacksonFactory;
+import com.google.api.services.discovery.Discovery;
+import com.google.api.services.discovery.model.JsonSchema;
+import com.google.api.services.discovery.model.RestDescription;
+import com.google.api.services.discovery.model.RestMethod;
+import java.io.File;
+
+/*
+ * Sample code for doing Cloud Machine Learning Engine online prediction in Java.
+ */
+
+public class OnlinePredictionSample {
+ public static void main(String[] args) throws Exception {
+ HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
+ JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
+ Discovery discovery = new Discovery.Builder(httpTransport, jsonFactory, null).build();
+
+ RestDescription api = discovery.apis().getRest("ml", "v1").execute();
+ RestMethod method = api.getResources().get("projects").getMethods().get("predict");
+
+ JsonSchema param = new JsonSchema();
+ String projectId = "YOUR_PROJECT_ID";
+ // You should have already deployed a model and a version.
+ // For reference, see https://cloud.google.com/ml-engine/docs/how-tos/deploying-models.
+ String modelId = "YOUR_MODEL_ID";
+ String versionId = "YOUR_VERSION_ID";
+ param.set(
+ "name", String.format("projects/%s/models/%s/versions/%s", projectId, modelId, versionId));
+
+ GenericUrl url =
+ new GenericUrl(UriTemplate.expand(api.getBaseUrl() + method.getPath(), param, true));
+ System.out.println(url);
+
+ String contentType = "application/json";
+ File requestBodyFile = new File("input.txt");
+ HttpContent content = new FileContent(contentType, requestBodyFile);
+ System.out.println(content.getLength());
+
+ GoogleCredential credential = GoogleCredential.getApplicationDefault();
+ HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
+ HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
+
+ String response = request.execute().parseAsString();
+ System.out.println(response);
+ }
+}
+
diff --git a/monitoring/cloud-client/pom.xml b/monitoring/cloud-client/pom.xml
index d75958f180e..f1454ba0793 100644
--- a/monitoring/cloud-client/pom.xml
+++ b/monitoring/cloud-client/pom.xml
@@ -54,7 +54,7 @@
com.google.cloud
google-cloud-monitoring
- 0.24.0-alpha
+ 0.25.0-alpha
com.google.guava
diff --git a/pom.xml b/pom.xml
index d14b425184c..07e7db7bc59 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,8 @@
errorreporting
+ firestore
+
iap
kms
diff --git a/pubsub/cloud-client/pom.xml b/pubsub/cloud-client/pom.xml
index 44f33890831..06252004a4b 100644
--- a/pubsub/cloud-client/pom.xml
+++ b/pubsub/cloud-client/pom.xml
@@ -37,7 +37,7 @@
com.google.cloud
google-cloud-pubsub
- 0.24.0-beta
+ 0.25.0-beta
diff --git a/spanner/cloud-client/pom.xml b/spanner/cloud-client/pom.xml
index b983d68fd65..9fe177c8587 100644
--- a/spanner/cloud-client/pom.xml
+++ b/spanner/cloud-client/pom.xml
@@ -52,7 +52,7 @@ limitations under the License.
com.google.cloud
google-cloud-spanner
- 0.24.0-beta
+ 0.25.0-beta
com.google.guava
diff --git a/speech/cloud-client/pom.xml b/speech/cloud-client/pom.xml
index dfc3c122e0b..22efed49ef1 100644
--- a/speech/cloud-client/pom.xml
+++ b/speech/cloud-client/pom.xml
@@ -38,7 +38,7 @@
com.google.cloud
google-cloud-speech
- 0.24.0-alpha
+ 0.25.0-alpha
diff --git a/storage/cloud-client/pom.xml b/storage/cloud-client/pom.xml
index a67b45efd19..b2a876ac2e0 100644
--- a/storage/cloud-client/pom.xml
+++ b/storage/cloud-client/pom.xml
@@ -37,7 +37,7 @@
com.google.cloud
google-cloud-storage
- 1.6.0
+ 1.7.0
diff --git a/storage/json-api/pom.xml b/storage/json-api/pom.xml
index 42f2a4ecc1b..4c1e4718880 100644
--- a/storage/json-api/pom.xml
+++ b/storage/json-api/pom.xml
@@ -38,7 +38,7 @@
com.google.apis
google-api-services-storage
- v1-rev111-1.22.0
+ v1-rev112-1.23.0
com.google.guava
@@ -54,7 +54,7 @@
com.google.oauth-client
google-oauth-client-jetty
- 1.22.0
+ 1.23.0
diff --git a/storage/storage-transfer/pom.xml b/storage/storage-transfer/pom.xml
index 2f15f2c1fc8..4d475296783 100644
--- a/storage/storage-transfer/pom.xml
+++ b/storage/storage-transfer/pom.xml
@@ -38,7 +38,7 @@
com.google.apis
google-api-services-storagetransfer
- v1-rev24-1.22.0
+ v1-rev26-1.23.0
com.google.guava
diff --git a/storage/xml-api/cmdline-sample/pom.xml b/storage/xml-api/cmdline-sample/pom.xml
index 2b4c6a6943a..b221ffb0da1 100644
--- a/storage/xml-api/cmdline-sample/pom.xml
+++ b/storage/xml-api/cmdline-sample/pom.xml
@@ -27,7 +27,7 @@
- 1.22.0
+ 1.23.0
UTF-8
1.6.0
3.7.0
@@ -66,7 +66,7 @@
com.google.apis
google-api-services-storage
- v1-rev111-1.22.0
+ v1-rev112-1.23.0
com.google.guava
diff --git a/storage/xml-api/serviceaccount-appengine-sample/pom.xml b/storage/xml-api/serviceaccount-appengine-sample/pom.xml
index 8c7264deebf..9cc4dc733a1 100644
--- a/storage/xml-api/serviceaccount-appengine-sample/pom.xml
+++ b/storage/xml-api/serviceaccount-appengine-sample/pom.xml
@@ -33,8 +33,8 @@
1.7
1.7
- 1.9.56
- 1.22.0
+ 1.9.57
+ 1.23.0
${project.build.directory}/${project.build.finalName}
UTF-8
diff --git a/taskqueue/deferred/pom.xml b/taskqueue/deferred/pom.xml
index 92c78cb3071..9da47ae996e 100644
--- a/taskqueue/deferred/pom.xml
+++ b/taskqueue/deferred/pom.xml
@@ -31,7 +31,7 @@
1.7
1.7
- 1.9.56
+ 1.9.57
2.5
3.1.0
diff --git a/translate/cloud-client/pom.xml b/translate/cloud-client/pom.xml
index 100d7c69fb4..d4204584d17 100644
--- a/translate/cloud-client/pom.xml
+++ b/translate/cloud-client/pom.xml
@@ -37,7 +37,7 @@
com.google.cloud
google-cloud-translate
- 1.6.0
+ 1.7.0
diff --git a/translate/pom.xml b/translate/pom.xml
index f4285eeb8e3..ad72a020860 100644
--- a/translate/pom.xml
+++ b/translate/pom.xml
@@ -38,7 +38,7 @@ limitations under the License.
com.google.cloud
google-cloud-translate
- 1.6.0
+ 1.7.0
junit
diff --git a/unittests/pom.xml b/unittests/pom.xml
index 896f2e170d1..61d3f52caf8 100644
--- a/unittests/pom.xml
+++ b/unittests/pom.xml
@@ -19,11 +19,11 @@
1.7
1.7
- 1.9.56
+ 1.9.57
UTF-8
3.1.0
2.5.1
- 1.22.0
+ 1.23.0
diff --git a/video/cloud-client/pom.xml b/video/cloud-client/pom.xml
index acbdbee5021..5efca7d0e95 100644
--- a/video/cloud-client/pom.xml
+++ b/video/cloud-client/pom.xml
@@ -43,7 +43,7 @@
com.google.cloud
google-cloud-video-intelligence
- 0.24.0-alpha
+ 0.25.0-beta
diff --git a/vision/cloud-client/pom.xml b/vision/cloud-client/pom.xml
index da08ea9414b..8ae30704938 100644
--- a/vision/cloud-client/pom.xml
+++ b/vision/cloud-client/pom.xml
@@ -38,7 +38,7 @@
com.google.cloud
google-cloud-vision
- 0.24.0-beta
+ 0.25.0-beta
diff --git a/vision/face-detection/pom.xml b/vision/face-detection/pom.xml
index 9b03e7fde5d..cf9902da065 100644
--- a/vision/face-detection/pom.xml
+++ b/vision/face-detection/pom.xml
@@ -39,12 +39,12 @@
com.google.apis
google-api-services-vision
- v1-rev361-1.22.0
+ v1-rev363-1.23.0
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.guava
diff --git a/vision/label/pom.xml b/vision/label/pom.xml
index b861b0a9a0b..6970c5ed49e 100644
--- a/vision/label/pom.xml
+++ b/vision/label/pom.xml
@@ -38,12 +38,12 @@
com.google.apis
google-api-services-vision
- v1-rev361-1.22.0
+ v1-rev363-1.23.0
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.guava
diff --git a/vision/landmark-detection/pom.xml b/vision/landmark-detection/pom.xml
index f6c7445e73f..dee4868732f 100644
--- a/vision/landmark-detection/pom.xml
+++ b/vision/landmark-detection/pom.xml
@@ -38,12 +38,12 @@
com.google.apis
google-api-services-vision
- v1-rev361-1.22.0
+ v1-rev363-1.23.0
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.guava
diff --git a/vision/text/pom.xml b/vision/text/pom.xml
index b74b3286e2f..94e54560076 100644
--- a/vision/text/pom.xml
+++ b/vision/text/pom.xml
@@ -38,12 +38,12 @@
com.google.apis
google-api-services-vision
- v1-rev361-1.22.0
+ v1-rev363-1.23.0
com.google.api-client
google-api-client
- 1.22.0
+ 1.23.0
com.google.guava