Java Code Examples for com.google.firebase.auth.FirebaseAuth#signInWithEmailAndPassword()

The following examples show how to use com.google.firebase.auth.FirebaseAuth#signInWithEmailAndPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void getShouldReturnNewlyPutData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseStorage storage = FirebaseStorage.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  StorageReference blob = storage.getReference("restaurants").child(TestId.create());

  byte[] data = "Google NYC".getBytes(StandardCharsets.UTF_8);

  try {
    Task<?> putTask = blob.putBytes(Arrays.copyOf(data, data.length));
    Tasks2.waitForSuccess(putTask);

    Task<byte[]> getTask = blob.getBytes(128);
    Tasks2.waitForSuccess(getTask);

    byte[] result = getTask.getResult();
    assertThat(result).isEqualTo(data);
  } finally {
    Tasks2.waitBestEffort(blob.delete());
  }
}
 
Example 2
Source File: DatabaseTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void setValueShouldTriggerListenerWithNewlySetData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseDatabase database = FirebaseDatabase.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DatabaseReference doc = database.getReference("restaurants").child(TestId.create());
  SnapshotListener listener = new SnapshotListener();
  doc.addListenerForSingleValueEvent(listener);

  HashMap<String, Object> data = new HashMap<>();
  data.put("location", "Google NYC");

  try {
    Task<?> setTask = doc.setValue(new HashMap<>(data));
    Task<DataSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(setTask);
    Tasks2.waitForSuccess(snapshotTask);

    DataSnapshot result = snapshotTask.getResult();
    assertThat(result.getValue()).isEqualTo(data);
  } finally {
    Tasks2.waitBestEffort(doc.removeValue());
  }
}
 
Example 3
Source File: DatabaseTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void updateChildrenShouldTriggerListenerWithUpdatedData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseDatabase database = FirebaseDatabase.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DatabaseReference doc = database.getReference("restaurants").child(TestId.create());
  HashMap<String, Object> originalData = new HashMap<>();
  originalData.put("location", "Google NYC");

  try {
    Task<?> setTask = doc.setValue(new HashMap<>(originalData));
    Tasks2.waitForSuccess(setTask);
    SnapshotListener listener = new SnapshotListener();
    doc.addListenerForSingleValueEvent(listener);

    HashMap<String, Object> updateData = new HashMap<>();
    updateData.put("count", 412L);

    Task<?> updateTask = doc.updateChildren(new HashMap<>(updateData));
    Task<DataSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(updateTask);
    Tasks2.waitForSuccess(snapshotTask);

    DataSnapshot result = snapshotTask.getResult();
    HashMap<String, Object> finalData = new HashMap<>();
    finalData.put("location", "Google NYC");
    finalData.put("count", 412L);
    assertThat(result.getValue()).isEqualTo(finalData);
  } finally {
    Tasks2.waitBestEffort(doc.removeValue());
  }
}
 
Example 4
Source File: FirestoreTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void setShouldTriggerListenerWithNewlySetData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseFirestore firestore = FirebaseFirestore.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DocumentReference doc = firestore.collection("restaurants").document(TestId.create());
  SnapshotListener listener = new SnapshotListener();
  ListenerRegistration registration = doc.addSnapshotListener(listener);

  try {
    HashMap<String, Object> data = new HashMap<>();
    data.put("location", "Google NYC");

    Task<?> setTask = doc.set(new HashMap<>(data));
    Task<DocumentSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(setTask);
    Tasks2.waitForSuccess(snapshotTask);

    DocumentSnapshot result = snapshotTask.getResult();
    assertThat(result.getData()).isEqualTo(data);
  } finally {
    registration.remove();
    Tasks2.waitBestEffort(doc.delete());
  }
}
 
Example 5
Source File: FirestoreTest.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void updateShouldTriggerListenerWithUpdatedData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseFirestore firestore = FirebaseFirestore.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DocumentReference doc = firestore.collection("restaurants").document(TestId.create());
  try {
    HashMap<String, Object> originalData = new HashMap<>();
    originalData.put("location", "Google NYC");

    Task<?> setTask = doc.set(new HashMap<>(originalData));
    Tasks2.waitForSuccess(setTask);

    SnapshotListener listener = new SnapshotListener(2);
    ListenerRegistration registration = doc.addSnapshotListener(listener);

    try {
      HashMap<String, Object> updateData = new HashMap<>();
      updateData.put("priority", 5L);

      Task<?> updateTask = doc.update(new HashMap<>(updateData));
      Task<DocumentSnapshot> snapshotTask = listener.toTask();
      Tasks2.waitForSuccess(updateTask);
      Tasks2.waitForSuccess(snapshotTask);

      DocumentSnapshot result = snapshotTask.getResult();
      HashMap<String, Object> finalData = new HashMap<>();
      finalData.put("location", "Google NYC");
      finalData.put("priority", 5L);
      assertThat(result.getData()).isEqualTo(finalData);
    } finally {
      registration.remove();
    }
  } finally {
    Tasks2.waitBestEffort(doc.delete());
  }
}