package com.gmscheduler.unittests;

import junit.framework.TestCase;
import junit.framework.Assert;
import com.gmscheduler.model.Person;
import com.gmscheduler.model.Timeframe;
import com.gmscheduler.model.Schedule;
import com.gmscheduler.model.DatabaseManager;
import java.util.List;
import java.util.ListIterator;

public class DatabaseManagerTest extends TestCase {
	private DatabaseManager dm = new DatabaseManager();
	private Person p,lp;
	private Timeframe t;
	private Schedule s,ls;
	private Long id;
	
	protected void setUp() throws Exception {
		p = new Person ("Fillo-Dough");
		t = new Timeframe ("Su","11:00","14:00");
	}
	
	
	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	public void testPersonStoreAndLoad() {
		//System.out.println(p.toString());
		p = dm.storePerson(p);
		id = p.getId();
		//System.out.println(id);
		Assert.assertTrue(!id.equals(null));
		
		lp = dm.loadPersonById(id);
		//System.out.println(lp.toString());
		Assert.assertEquals(p.toString(),lp.toString());
	}

	public void testScheduleStoreAndLoad() {
		
		p = dm.storePerson(p);
		
		s = new Schedule(p,t);
		//System.out.println(p.toString());

		s = dm.storeSchedule(s);
		id = s.getId();
		//System.out.println(id);
		Assert.assertTrue(!id.equals(null));
		
		ls = dm.loadScheduleById(id);
		//System.out.println(lp.toString());
		Assert.assertEquals(s.toString(),ls.toString());
		System.out.println("SchedStoreAndLoad: " + ls.toString());
	}
	
	public void testAllPersonSchedule() {
		List stuff = dm.loadScheduleByPersonName("atoy");
		ListIterator lr = stuff.listIterator();
		
		while(lr.hasNext()) {
			System.out.println(((Schedule)lr.next()).toString());
		}
		Assert.assertTrue(true);
	}
	
	public void testAllSchedule() {
		List stuff = dm.loadAllSchedules();
		ListIterator lr = stuff.listIterator();
		
		while(lr.hasNext()) {
			System.out.println(((Schedule)lr.next()).toString());
		}
		Assert.assertTrue(true);
	}
}