package org.jerrymouse.chineseCalendar.service.impl;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jerrymouse.chineseCalendar.model.atom.BirthdayEntity;
import org.jerrymouse.chineseCalendar.model.birthday.Birthday;
import org.jerrymouse.chineseCalendar.model.birthday.SimpleCalendar;
import org.jerrymouse.chineseCalendar.test.TestInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedOutput;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { TestInfo.ApplicationContentPath })
public class AtomServiceImplTest {

	@Autowired
	AtomServiceImpl atomServiceImpl;

	Log logger = LogFactory.getLog(AtomServiceImplTest.class);

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testcreatWeekFeed() throws Exception {
		List<Birthday> birthdays = generateBirthdayData();
		List<BirthdayEntity> birthdayEntities = generateBirthdayEntityData();
		SyndFeed feed = atomServiceImpl.creatWeekFeed(new SimpleCalendar(),
				birthdayEntities, birthdays);
		SyndFeedOutput output = new SyndFeedOutput();
		logger.debug(output.outputString(feed));
	}

	private List<Birthday> generateBirthdayData() {
		List<Birthday> birthdays = new ArrayList<Birthday>();
		birthdays.add(new Birthday("颜开", new SimpleCalendar("2008-7-1")));
		birthdays.add(new Birthday("颜澍", new SimpleCalendar("2006-6-25")));
		return birthdays;
	}

	private List<Birthday> generateBirthdayData2() {
		List<Birthday> birthdays = new ArrayList<Birthday>();
		birthdays.add(new Birthday("颜开", new SimpleCalendar("2009-7-19")));
		birthdays.add(new Birthday("颜澍", new SimpleCalendar("2009-7-25")));
		return birthdays;
	}

	private List<BirthdayEntity> generateBirthdayEntityData() {
		List<BirthdayEntity> birthdays = new ArrayList<BirthdayEntity>();
		birthdays.add(new BirthdayEntity(new SimpleCalendar(),
				generateBirthdayData2()));
		List<Birthday> birthdays2 = new ArrayList<Birthday>();
		birthdays2.add(new Birthday("桃子", new SimpleCalendar("2009-7-30")));

		birthdays.add(new BirthdayEntity(new SimpleCalendar("2009-7-26"),
				birthdays2));
		return birthdays;
	}
}
