package com.planimod.core;

import static org.junit.Assert.*;

import java.util.Calendar;
import java.util.Date;

import org.junit.Test;

import com.patrikdufresne.managers.ManagerEvent;
import com.patrikdufresne.managers.ManagerException;

/**
 * This class intend to test the functionnalities provided by the
 * {@link ApplicationSettingManager}.
 * 
 * @author ikus060
 * 
 */
public class ApplicationSettingManagerTest extends ManagerTestCase {

	@Test
	public void testSetByName() {
		addManagerObserver(ManagerEvent.ADD, ApplicationSetting.class);
		try {
			managers.getApplicationSettingManager().setByName("settings_name",
					"new_value");
		} catch (ManagerException e) {
			fail("Fail to sets the application settings.", e);
		}
		assertEquals("Wrong number of events.", 1, getManagerEvents().size());
		// assertManagerEvent(1, getManagerEvents(), ManagerEvent.ADD, entity);

		try {
			assertEquals("new_value", managers.getApplicationSettingManager()
					.getByName("settings_name"));
		} catch (ManagerException e) {
			fail("Fail to get the application settings.", e);
		}

	}

	@Test
	public void testSetFirstDayOfWeek() throws ManagerException {
		addManagerObserver(ManagerEvent.ADD, ApplicationSetting.class);
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.MILLISECOND, 0);
		managers.getApplicationSettingManager().setFirstDayOfWeek(
				cal.getFirstDayOfWeek());
		assertEquals("Wrong number of events.", 1, getManagerEvents().size());
		assertEquals(cal.getFirstDayOfWeek(), managers
				.getApplicationSettingManager().getFirstDayOfWeek());
	}

}
