package eic.beike.projectx.network.projectXServer;

import junit.framework.TestCase;

/**
 * Test the database interaction. As of now this is against the live server.
 * Created by alex on 10/1/15.
 */
public class DatabaseTest extends TestCase {
    private Database db;

    /**
     * We use a fresh object for every test.
     * @throws Exception
     */
    public void setUp() throws Exception {
        super.setUp();
        db = new Database();

    }

    public void testRegister() throws Exception {
        String id = "test" + Long.toString(System.currentTimeMillis());
        //Should be able to register.
        boolean success = db.register(id, "alex");
        assertTrue(success);
        //Should not be able to register twice.
        success = db.register(id, "alex");
        assertFalse(success);
    }

    public void testRecordScore() throws Exception {
        //Create two users.
        String id1 = "test" + Long.toString(System.currentTimeMillis());
        String id2 = "test" + Long.toString(System.currentTimeMillis() + 10);
        //Register one of them.
        if(db.register(id1, "alex")) {
            //Record a valid score.
            long t = System.currentTimeMillis();
            boolean success = db.recordScore(id1,10,t,"Ericsson$100020");
            assertTrue(success);
            //Try again. This should not be allowed.
            success = db.recordScore(id1,10,t,"Ericsson$100020");
            assertFalse(success);
            //Try with unknown player, should not be allowed.
            success = db.recordScore(id2,10,System.currentTimeMillis(),"Ericsson$100020");
            assertFalse(success);
        }
    }

    public void testGetTopTen() throws Exception {

    }

    public void testGetPlayerTopTen() throws Exception {

    }
}
@@ -45,16 +45,59 @@
 erver;%0A%0A
+import eic.beike.projectx.util.ScoreEntry;%0A
 import j
@@ -122,16 +122,40 @@
 tCase;%0A%0A
+import java.util.List;%0A%0A
 /**%0A * T
@@ -227,16 +227,75 @@
 server.%0A
+ * TODO: Setup test database that resets after every test.%0A
  * Creat
@@ -1856,73 +1856,1018 @@
 n %7B%0A
-%0A    %7D%0A%0A    public void testGetPlayerTopTen() throws Exception %7B%0A
+        //Get the high score%0A        List%3CScoreEntry%3E results = db.getTopTen();%0A        //We should get ten entries%0A        assertTrue(results.size() == 10 );%0A        //All entries should be filled.%0A        for(ScoreEntry entry : results)%7B%0A            assertTrue(entry.getName() != null);%0A            assertTrue(entry.getScore() != null);%0A        %7D%0A%0A    %7D%0A%0A    public void testGetPlayerTopTen() throws Exception %7B%0A%0A        //Get the high score for existing player%0A        List%3CScoreEntry%3E results = db.getPlayerTopTen(%22alex%22);%0A        //We should get ten entries%0A        assertTrue(results.size() != 0 );%0A        //All entries should be filled.%0A        for(ScoreEntry entry : results)%7B%0A            assertTrue(entry.getName() != null);%0A            assertTrue(entry.getScore() != null);%0A        %7D%0A%0A        //Try to get for player with no recorded scores.%0A        results = db.getPlayerTopTen(Long.toString(System.currentTimeMillis()));%0A        //We should get no results.%0A        assertTrue(results.size() == 0);
 %0A   

Add high score tests.