package com.gmscheduler.unittests;

import org.hibernate.Session;

import junit.framework.TestCase;
import junit.framework.Assert;

import com.gmscheduler.model.HibernateUtil;
import com.gmscheduler.model.Timeframe;

public class TimeframeTest extends TestCase {

	private Timeframe t1;
	private Timeframe t2;
	private Timeframe t3;
	private Timeframe t4;
	private Timeframe st;
	private Timeframe lt;
	
	protected void setUp() throws Exception {
		super.setUp();
		t1 = new Timeframe("M","10:00am","1:00pm");
		t2 = new Timeframe(t1);
		t3 = new Timeframe("W","10:00am","1:00pm");
		t4 = new Timeframe(t3);
		st = new Timeframe(t3);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testTimeframeEquals() {
		Assert.assertEquals(t1.toString(),t2.toString());
		Assert.assertTrue(!t1.equals(t3));
	}
	
	public void testDay() {
		t4.setDay("F");
		// I think this will fail because I have to do .Equals("F")
		Assert.assertTrue(t4.getDay().equals("F"));	
	}
	
	
	public void testTimeframeSet() {
		t4.setStart("9:00am");
		Assert.assertEquals(t4.getStart(),"9:00am");
		t4.setEnd("2:00pm");
		Assert.assertEquals(t4.getEnd(),"2:00pm");
	}
	
	public void testTimeframeSaveAndLoad() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(st);
		session.getTransaction().commit();
		
		Long stid = new Long(st.getId());
		
		session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		lt = (Timeframe)session.load(Timeframe.class,stid);
		String lts = new String(lt.toString());
		session.getTransaction().commit();
		
		Assert.assertEquals(st.toString(),lts);
	}
}
