Search in sources :

Example 91 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.

the class AccountManagerTest method setUserLoggedInFalseTest.

/**
 * Tests that a user that has been authenticated is tagged as logged in
 *
 * Will pass if there exists a child node in the online_users reference equal to the users
 * username.
 *
 * @throws Exception
 */
@Test
public void setUserLoggedInFalseTest() throws Exception {
    // create a test user and set them as online
    User testUser = TestingHelper.createTestUser();
    // set the user as online then set them as offline
    AccountManager.setUserLoginState(testUser.getUsername(), false);
    // attempt to retrieve a reference to the logged in user
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference usersReference = database.getReference("online_users/" + testUser.getUsername());
    // attach a listener for data changes of the users reference.  this will occur when
    // the reference is populated
    usersReference.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // if the reference exists, then the user is tagged as logged in and we should fail
            // the test, otherwise it should succeed
            assertFalse("Expecting non-empty result from database, but no data returned...", dataSnapshot.exists());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) Test(org.junit.Test)

Example 92 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.

the class AccountManagerTest method toggleOnlineUserTest.

@Test
public void toggleOnlineUserTest() throws Exception {
    final User testUser = TestingHelper.createTestUser();
    AccountManager.createUser(testUser);
    sleep(1000);
    AccountManager.authenticate(testUser, TestingHelper.assertTrueBooleanResult());
    sleep(1000);
    AccountManager.setOnline(false);
    testUser.addUserExercise(TestingHelper.testExercise1);
    AccountManager.updateUser(testUser);
    AccountManager.setOnline(true);
    sleep(1000);
    // retrieve a reference to the users node
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference usersReference = database.getReference("users/" + testUser.getUsername());
    // attach a listener for data changes of the users reference.  this will occur when
    // the reference is populated
    usersReference.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            assertTrue(dataSnapshot.exists());
            if (dataSnapshot.exists()) {
                assertEquals(1, dataSnapshot.getValue(User.class).getUserExercises().size());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    sleep(1000);
    AccountManager.deleteUser(testUser, TestingHelper.assertTrueBooleanResult());
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) Test(org.junit.Test)

Example 93 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.

the class TestingHelper method addTestUserExercises.

/**
 * Test helper to add test exercises to testuser
 */
public static void addTestUserExercises() {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference usersReference = database.getReference("users/testuser");
    ArrayList<Exercise> testExercises = new ArrayList<>();
    testExercises.add(testExercise1);
    testExercises.add(testExercise2);
    testExercises.add(testExercise3);
    usersReference.child("userExercises").setValue(testExercises);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) Exercise(ca.dal.cs.athletemonitor.athletemonitor.Exercise) DatabaseReference(com.google.firebase.database.DatabaseReference) ArrayList(java.util.ArrayList)

Example 94 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.

the class TestingHelper method resetTestUserWorkouts.

/**
 * Test helper to reset the testuser's workout list
 */
public static void resetTestUserWorkouts() {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference usersReference = database.getReference("users/testuser");
    usersReference.child("userWorkouts").setValue(null);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Example 95 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.

the class TestingHelper method resetTestTeam.

public static void resetTestTeam() {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference teamsReference = database.getReference("teams");
    teamsReference.child("testteam").setValue(null);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Aggregations

DatabaseReference (com.google.firebase.database.DatabaseReference)157 DatabaseError (com.google.firebase.database.DatabaseError)95 DataSnapshot (com.google.firebase.database.DataSnapshot)87 ValueEventListener (com.google.firebase.database.ValueEventListener)61 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)50 HashMap (java.util.HashMap)24 View (android.view.View)18 MutableData (com.google.firebase.database.MutableData)17 Transaction (com.google.firebase.database.Transaction)17 Intent (android.content.Intent)16 FirebaseUser (com.google.firebase.auth.FirebaseUser)13 ArrayList (java.util.ArrayList)12 TextView (android.widget.TextView)11 Query (com.google.firebase.database.Query)11 Map (java.util.Map)11 ProgressDialog (android.app.ProgressDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 ChildEventListener (com.google.firebase.database.ChildEventListener)9 SharedPreferences (android.content.SharedPreferences)8 ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)8