Search in sources :

Example 16 with DocumentReference

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

the class ManageDataSnippetsIT method testUpdateAndCreateIfMissing.

@Test
public void testUpdateAndCreateIfMissing() throws Exception {
    manageDataSnippets.updateAndCreateIfMissing();
    DocumentReference docRef = db.collection("cities").document("BJ");
    assertTrue(getDocumentDataAsCity(docRef).getCapital());
}
Also used : DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 17 with DocumentReference

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

the class ManageDataSnippetsIT method testAddDocWithAutoGenId.

@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)));
}
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 18 with DocumentReference

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

the class ManageDataSnippetsIT method testAddDataWithDifferentDataTypes.

@Test
public void testAddDataWithDifferentDataTypes() throws Exception {
    Map<String, Object> expectedData = manageDataSnippets.addDocumentWithDifferentDataTypes();
    DocumentReference docRef = db.collection("data").document("one");
    assertEquals(expectedData, getDocumentDataAsMap(docRef));
}
Also used : DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 19 with DocumentReference

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

the class ManageDataSnippetsIT method testUpdateSimpleDocument.

@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)));
}
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 20 with DocumentReference

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

the class ManageDataSnippetsIT method testUpdateServerTimestamp.

@Test
public void testUpdateServerTimestamp() throws Exception {
    manageDataSnippets.updateServerTimestamp();
    DocumentReference docRef = db.collection("objects").document("some-id");
    Map<String, Object> data = getDocumentDataAsMap(docRef);
    assertTrue(data.get("timestamp") instanceof Date);
}
Also used : DocumentReference(com.google.cloud.firestore.DocumentReference) Date(java.util.Date) 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