Search in sources :

Example 11 with DocumentReference

use of com.google.cloud.firestore.DocumentReference in project java-docs-samples by GoogleCloudPlatform.

the class ManageDataSnippetsIT method testAddDataAsEntity.

@Test
public void testAddDataAsEntity() throws Exception {
    City city = manageDataSnippets.addSimpleDocumentAsEntity();
    DocumentReference docRef = db.collection("cities").document("LA");
    assertTrue(Objects.equals(city, getDocumentDataAsCity(docRef)));
}
Also used : City(com.example.firestore.snippets.model.City) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 12 with DocumentReference

use of com.google.cloud.firestore.DocumentReference in project java-docs-samples by GoogleCloudPlatform.

the class ManageDataSnippetsIT method testUpdateUsingMap.

@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)));
}
Also used : City(com.example.firestore.snippets.model.City) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 13 with DocumentReference

use of com.google.cloud.firestore.DocumentReference in project java-docs-samples by GoogleCloudPlatform.

the class ManageDataSnippetsIT method testAddDocAfterAutoGenId.

@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)));
}
Also used : City(com.example.firestore.snippets.model.City) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 14 with DocumentReference

use of com.google.cloud.firestore.DocumentReference in project java-docs-samples by GoogleCloudPlatform.

the class ManageDataSnippetsIT method testUpdateNestedFields.

@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");
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 15 with DocumentReference

use of com.google.cloud.firestore.DocumentReference in project java-docs-samples by GoogleCloudPlatform.

the class ManageDataSnippetsIT method testDeleteFields.

@Test
public void testDeleteFields() throws Exception {
    manageDataSnippets.deleteFields();
    DocumentReference docRef = db.collection("cities").document("BJ");
    Map<String, Object> data = getDocumentDataAsMap(docRef);
    assertFalse(data.containsKey("capital"));
}
Also used : DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Aggregations

DocumentReference (com.google.cloud.firestore.DocumentReference)26 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)14 Test (org.junit.Test)14 City (com.example.firestore.snippets.model.City)12 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)7 WriteResult (com.google.cloud.firestore.WriteResult)7 HashMap (java.util.HashMap)5 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)4 Transaction (com.google.cloud.firestore.Transaction)2 CollectionReference (com.google.cloud.firestore.CollectionReference)1 FirestoreException (com.google.cloud.firestore.FirestoreException)1 WriteBatch (com.google.cloud.firestore.WriteBatch)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1