package com.expidev.gcmapp.db;

import android.content.Context;
import android.test.InstrumentationTestCase;
import android.test.RenamingDelegatingContext;
import android.util.Log;

import com.expidev.gcmapp.model.Assignment;
import com.expidev.gcmapp.model.AssociatedMinistry;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by William.Randall on 1/26/2015.
 */
public class MinistriesDaoTest extends InstrumentationTestCase
{
    private final String TAG = getClass().getSimpleName();

    private MinistriesDao ministriesDao;

    @Override
    public void setUp() throws Exception
    {
        super.setUp();
        Context context = new RenamingDelegatingContext(getInstrumentation().getTargetContext().getApplicationContext(), "test_");
        ministriesDao = MinistriesDao.getInstance(context);
    }

    private void cleanupDatabase()
    {
        Log.i(TAG, "Cleaning up database");
        ministriesDao.deleteAllData();
    }

    private ArrayList<Assignment> getTestAssignments()
    {
        ArrayList<Assignment> assignments = new ArrayList<Assignment>();

        Assignment assignemnt1 = new Assignment();
        assignemnt1.setId("A1");
        assignemnt1.setMinistry(mockMinistry());
        assignemnt1.setMinistryId(assignemnt1.getMinistry().getMinistryId());
        assignemnt1.setRole(Assignment.Role.SELF_ASSIGNED);

        assignments.add(assignemnt1);

        return assignments;
    }

    /**
     * Mock Ministry
     *   - Sub Ministry 1
     *     - Sub Ministry 2
     *       - Sub Ministry 3
     *     - Sub Ministry 4
     *       - Sub Ministry 5
     */
    private AssociatedMinistry mockMinistry()
    {
        AssociatedMinistry mockMinistry = new AssociatedMinistry();
        AssociatedMinistry subMinistry1 = new AssociatedMinistry();
        AssociatedMinistry subMinistry2 = new AssociatedMinistry();
        AssociatedMinistry subMinistry3 = new AssociatedMinistry();
        AssociatedMinistry subMinistry4 = new AssociatedMinistry();
        AssociatedMinistry subMinistry5 = new AssociatedMinistry();

        mockMinistry.setName("Mock Ministry");
        subMinistry1.setName("Sub Ministry 1");
        subMinistry2.setName("Sub Ministry 2");
        subMinistry3.setName("Sub Ministry 3");
        subMinistry4.setName("Sub Ministry 4");
        subMinistry5.setName("Sub Ministry 5");

        mockMinistry.setMinistryId("M0");
        subMinistry1.setMinistryId("M1");
        subMinistry2.setMinistryId("M2");
        subMinistry3.setMinistryId("M3");
        subMinistry4.setMinistryId("M4");
        subMinistry5.setMinistryId("M5");

        mockMinistry.setMinistryCode("MOCK");
        subMinistry1.setMinistryCode("MIN_1");
        subMinistry2.setMinistryCode("MIN_2");
        subMinistry3.setMinistryCode("MIN_3");
        subMinistry4.setMinistryCode("MIN_4");
        subMinistry5.setMinistryCode("MIN_5");

        List<AssociatedMinistry> subMinistryList1 = new ArrayList<AssociatedMinistry>();
        List<AssociatedMinistry> subMinistryList2 = new ArrayList<AssociatedMinistry>();
        List<AssociatedMinistry> subMinistryList3 = new ArrayList<AssociatedMinistry>();
        List<AssociatedMinistry> subMinistryList4 = new ArrayList<AssociatedMinistry>();

        subMinistryList1.add(subMinistry1);
        subMinistryList2.add(subMinistry2);
        subMinistryList3.add(subMinistry3);
        subMinistryList2.add(subMinistry4);
        subMinistryList4.add(subMinistry5);

        return mockMinistry;
    }
}

@@ -251,26 +251,16 @@
 p.model.
-Associated
 Ministry
@@ -1618,26 +1618,16 @@
 private 
-Associated
 Ministry
@@ -1652,34 +1652,24 @@
   %7B%0A        
-Associated
 Ministry moc
@@ -1680,34 +1680,24 @@
 istry = new 
-Associated
 Ministry();%0A
@@ -1700,34 +1700,24 @@
 ();%0A        
-Associated
 Ministry sub
@@ -1728,34 +1728,24 @@
 stry1 = new 
-Associated
 Ministry();%0A
@@ -1748,34 +1748,24 @@
 ();%0A        
-Associated
 Ministry sub
@@ -1776,34 +1776,24 @@
 stry2 = new 
-Associated
 Ministry();%0A
@@ -1796,34 +1796,24 @@
 ();%0A        
-Associated
 Ministry sub
@@ -1824,34 +1824,24 @@
 stry3 = new 
-Associated
 Ministry();%0A
@@ -1844,34 +1844,24 @@
 ();%0A        
-Associated
 Ministry sub
@@ -1872,34 +1872,24 @@
 stry4 = new 
-Associated
 Ministry();%0A
@@ -1896,26 +1896,16 @@
         
-Associated
 Ministry
@@ -1924,26 +1924,16 @@
 5 = new 
-Associated
 Ministry
@@ -2769,34 +2769,24 @@
        List%3C
-Associated
 Ministry%3E su
@@ -2816,34 +2816,16 @@
 rayList%3C
-AssociatedMinistry
 %3E();%0A   
@@ -2830,34 +2830,24 @@
        List%3C
-Associated
 Ministry%3E su
@@ -2877,34 +2877,16 @@
 rayList%3C
-AssociatedMinistry
 %3E();%0A   
@@ -2891,34 +2891,24 @@
        List%3C
-Associated
 Ministry%3E su
@@ -2938,34 +2938,16 @@
 rayList%3C
-AssociatedMinistry
 %3E();%0A   
@@ -2952,34 +2952,24 @@
        List%3C
-Associated
 Ministry%3E su
@@ -3003,26 +3003,8 @@
 ist%3C
-AssociatedMinistry
 %3E();

update Dao test to use base object