com.google.firebase.database.ChildEventListener Java Examples

The following examples show how to use com.google.firebase.database.ChildEventListener. 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: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Cancelled() {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onCancelled(DatabaseError.fromCode(DatabaseError.DISCONNECTED));

    testSubscriber.assertError(RxFirebaseDataException.class);
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example #2
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Moved() {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildMoved(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventMoved));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example #3
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Removed() {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildRemoved(mockFirebaseDataSnapshot);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventRemoved));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example #4
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Changed() {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildChanged(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventChanged));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example #5
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Added() {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildAdded(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventAdded));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example #6
Source File: OrderByTestIT.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testChildAddedEvents() throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  Map<String, Object> initial =
      new MapBuilder()
          .put("a", MapBuilder.of("value", 5L))
          .put("c", MapBuilder.of("value", 3L))
          .build();

  final List<String> snapshotNames = new ArrayList<>();
  final List<String> prevNames = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  final ChildEventListener testListener =
      ref.orderByChild("value")
          .addChildEventListener(
              new TestChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot snap, String prevName) {
                  snapshotNames.add(snap.getKey());
                  prevNames.add(prevName);
                  semaphore.release();
                }
              });

  ref.setValueAsync(initial);
  TestHelpers.waitFor(semaphore, 2);
  Assert.assertEquals(Arrays.asList("c", "a"), snapshotNames);
  Assert.assertEquals(Arrays.asList(null, "c"), prevNames);

  Map<String, Object> updates = new HashMap<>();
  updates.put("b", MapBuilder.of("value", 4));
  updates.put("d", MapBuilder.of("value", 2));
  ref.updateChildrenAsync(updates);

  TestHelpers.waitFor(semaphore, 2);
  Assert.assertEquals(Arrays.asList("c", "a", "d", "b"), snapshotNames);
  Assert.assertEquals(Arrays.asList(null, "c", null, "c"), prevNames);
  ref.removeEventListener(testListener);
}
 
Example #7
Source File: RxDatabaseReferenceTest.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    childEventListener = ArgumentCaptor.forClass(ChildEventListener.class);
    valueEventListener = ArgumentCaptor.forClass(ValueEventListener.class);
    transactionHandler = ArgumentCaptor.forClass(Transaction.Handler.class);
    onCompleteListener = ArgumentCaptor.forClass(OnCompleteListener.class);
}
 
Example #8
Source File: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    childEventListener = ArgumentCaptor.forClass(ChildEventListener.class);
    valueEventListener = ArgumentCaptor.forClass(ValueEventListener.class);
    transactionHandler = ArgumentCaptor.forClass(Transaction.Handler.class);
    onCompleteListener = ArgumentCaptor.forClass(OnCompleteListener.class);
}
 
Example #9
Source File: ConversationsHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener getConversationsChildEventListener() {
    return conversationsChildEventListener;
}
 
Example #10
Source File: FirebaseArray.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    mQuery.removeEventListener((ValueEventListener) this);
    mQuery.removeEventListener((ChildEventListener) this);
}
 
Example #11
Source File: QueryOnChildChange.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
private CancelListenerAction(ChildEventListener listener, Query query) {
    this.listener = listener;
    this.query = query;
}
 
Example #12
Source File: ChildEventRegistration.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public ChildEventRegistration(
    @NotNull Repo repo, @NotNull ChildEventListener eventListener, @NotNull QuerySpec spec) {
  this.repo = repo;
  this.eventListener = eventListener;
  this.spec = spec;
}
 
Example #13
Source File: ConversationsHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener connect(ConversationsListener conversationsListener) {
    this.upsertConversationsListener(conversationsListener);
    return connect();
}
 
Example #14
Source File: ArchivedConversationsHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener getConversationsChildEventListener() {
    return conversationsChildEventListener;
}
 
Example #15
Source File: ArchivedConversationsHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener connect(ConversationsListener conversationsListener) {
    this.upsertConversationsListener(conversationsListener);
    return connect();
}
 
Example #16
Source File: ConversationMessagesHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener getConversationMessagesChildEventListener() {
    return conversationMessagesChildEventListener;
}
 
Example #17
Source File: ConversationMessagesHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener connect(ConversationMessagesListener conversationMessagesListener) {
    this.upsertConversationMessagesListener(conversationMessagesListener);

    return connect();
}
 
Example #18
Source File: GroupsSyncronizer.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener getGroupsChildEventListener() {
    return groupsChildEventListener;
}
 
Example #19
Source File: GroupsSyncronizer.java    From chat21-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChildEventListener connect(ChatGroupsListener chatGroupsListener) {
    this.upsertGroupsListener(chatGroupsListener);
    return connect();
}
 
Example #20
Source File: ChildEventRegistration.java    From firebase-admin-java with Apache License 2.0 4 votes vote down vote up
public ChildEventRegistration(
    @NotNull Repo repo, @NotNull ChildEventListener eventListener, @NotNull QuerySpec spec) {
  this.repo = repo;
  this.eventListener = eventListener;
  this.spec = spec;
}