package umm3601.plant;

import com.mongodb.util.JSON;
import org.junit.Before;
import org.junit.Test;
import umm3601.digitalDisplayGarden.PlantController;

import java.io.IOException;

import static junit.framework.TestCase.assertEquals;

public class TestUploadIds {

    private final static String databaseName = "data-for-testing-only";
    private PlantController plantController;

    @Before
    public void populateDB() throws IOException {
        PopulateMockDatabase db = new PopulateMockDatabase();
        db.clearAndPopulateDBAgain();
        plantController = new PlantController(databaseName);
    }

    @Test
    public void testListingOfUploadIds() throws IOException {
        String uploadid = plantController.getLiveUploadId();
        assertEquals("Incorrect uploadID in config", "second uploadId", uploadid);
    }

    @Test
    public void testGetLiveUploadId() throws IOException {
        String expect = "[ \"first uploadId\" , \"second uploadId\"]";
        String uploadArr = JSON.serialize(plantController.listUploadIds());

        assertEquals("Incorrect distinct uploadIDs", expect, uploadArr);
    }
}

@@ -47,16 +47,42 @@
 l.JSON;%0A
+import org.bson.Document;%0A
 import o
@@ -98,16 +98,16 @@
 Before;%0A
-
 import o
@@ -256,16 +256,103 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apublic
@@ -1163,16 +1163,16 @@
 ds());%0A%0A
-
         
@@ -1241,11 +1241,692 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testDeleteUploadFailsProperly() %7B%0A        Document result = plantController.deleteUploadID(%22foobar doesn't exist%22);%0A        assertFalse(result.getBoolean(%22success%22));%0A        String expectedIDs = %22%5B %5C%22first uploadId%5C%22 , %5C%22second uploadId%5C%22%5D%22;%0A        assertEquals(expectedIDs, JSON.serialize(result.get(%22uploadIds%22)));%0A    %7D%0A%0A    @Test%0A    public void testDeleteUploadIdSucceedsProperly() %7B%0A        Document result = plantController.deleteUploadID(%22first uploadId%22);%0A        assertTrue(result.getBoolean(%22success%22));%0A        String expectedIDs = %22%5B %5C%22second uploadId%5C%22%5D%22;%0A        assertEquals(expectedIDs, JSON.serialize(result.get(%22uploadIds%22)));%0A    %7D
 %0A%7D%0A

Add tests for deleteUploadID()