package net.w_horse.excelpojo.annotation;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

import test.annotation.ReservedWordTest;
import net.w_horse.excelpojo.AbstractTest;
import net.w_horse.excelpojo.ExcelPOJOBridge;
import net.w_horse.excelpojo.ExcelPOJOException;

public class ConstatntValueTest extends AbstractTest {
	/**
	 * 予約語のテスト
	 *
	 * @throws ExcelPOJOException
	 * @throws IOException
	 * @throws ParseException
	 */
	@Test
	public void testConstantValueReservedWord() throws ExcelPOJOException, IOException, ParseException {
		ExcelPOJOBridge bridge = new ExcelPOJOBridge(ReservedWordTest.class);

		String beforeLoad = (new SimpleDateFormat("HHmmss")).format(new Date());
		// シートはどこれを読んでも同じ
		ReservedWordTest targetBean = (ReservedWordTest) bridge.load("./files/upload/ParserTest.xls", "ラベル読み込み位置");
		String afterLoad = (new SimpleDateFormat("HHmmss")).format(new Date());

		String todayYYYYMMDD = (new SimpleDateFormat("yyyyMMdd")).format(new Date());
		assertEquals("ConstantValue yyyyMMdd", todayYYYYMMDD, targetBean.getYyyyMMdd());

		String todaySL_YMD = (new SimpleDateFormat("yyyy/MM/dd")).format(new Date());
		assertEquals("ConstantValue yyyy/MM/dd", todaySL_YMD, targetBean.getSl_ymd());

		String todayHP_YMD = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
		assertEquals("ConstantValue yyyy-MM-dd", todayHP_YMD, targetBean.getHp_ymd());

		String todayHHMMSS = targetBean.getHhmmss();	// 実行がミリ秒で終了し実行の前後で同じ値になる可能性がある
		assertEquals("ConstantValue HHmmss", true, todayHHMMSS.compareTo(beforeLoad) >= 0);
		assertEquals("ConstantValue HHmmss", true, todayHHMMSS.compareTo(afterLoad) <= 0);
	}

}
