Search in sources :

Example 6 with City

use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.

the class ManageDataSnippets method addSimpleDocumentAsEntity.

/**
 * Add a document to a collection as a custom object.
 *
 * @return entity added
 */
City addSimpleDocumentAsEntity() throws Exception {
    // [START fs_add_simple_doc_as_entity]
    City city = new City("Los Angeles", "CA", "USA", false, 3900000L);
    ApiFuture<WriteResult> future = db.collection("cities").document("LA").set(city);
    // block on response if required
    System.out.println("Update time : " + future.get().getUpdateTime());
    return city;
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult) City(com.example.firestore.snippets.model.City)

Example 7 with City

use of com.example.firestore.snippets.model.City 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 8 with City

use of com.example.firestore.snippets.model.City 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 9 with City

use of com.example.firestore.snippets.model.City 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 10 with City

use of com.example.firestore.snippets.model.City in project java-docs-samples by GoogleCloudPlatform.

the class RetrieveDataSnippetsIT method testRetrieveAsEntity.

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

Aggregations

City (com.example.firestore.snippets.model.City)16 DocumentReference (com.google.cloud.firestore.DocumentReference)12 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)6 WriteResult (com.google.cloud.firestore.WriteResult)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 ApiFuture (com.google.api.core.ApiFuture)2 CollectionReference (com.google.cloud.firestore.CollectionReference)2 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)2 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)2 HashMap (java.util.HashMap)2 Transaction (com.google.cloud.firestore.Transaction)1 WriteBatch (com.google.cloud.firestore.WriteBatch)1 List (java.util.List)1