package com.eactive.eai.transformer.dao.excel;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.transformer.dao.jdbc.FunctionJdbcDao;
import com.eactive.eai.transformer.function.FunctionManager;
import com.eactive.eai.transformer.function.jpa.TransformJPATestConfiguration;
import com.eactive.eai.transformer.layout.LayoutManager;
import com.eactive.eai.transformer.layout.LayoutTypeManager;

@DataJpaTest
@Transactional(readOnly = false)
@ContextConfiguration(classes = { TransformJPATestConfiguration.class })

class ExcelLoaderTest {

	@BeforeAll
	public static void setup() {
		System.setProperty("module", "EXCEL_LOADER");
	}

	@Autowired
	FunctionExcelDao functionExcelDao;

	@Autowired
	FunctionJdbcDao functionJdbcDao;

	@Autowired
	FunctionManager functionManager;

	@Autowired
	LayoutTypeExcelDao layoutTypeExcelDao;

	@Autowired
	LayoutTypeManager layoutTypeManager;

	@Autowired
	LayoutExcelDao layoutExcelDao;

	@Autowired
	Layout2ExcelDao layout2ExcelDao;

	@Autowired
	TransformExcelDao transformExcelDao;

	@Autowired
	LayoutManager layoutManager;

	@Configuration
	class Config {

	}

	@Test
	void testLoad() throws Exception {
		// function
		functionExcelDao.save(functionExcelDao.load());
		functionExcelDao.save(functionExcelDao.load());
		functionManager.reload();

		// layout type
		layoutTypeExcelDao.save(layoutTypeExcelDao.load());
		layoutTypeExcelDao.save(layoutTypeExcelDao.load());
		layoutTypeManager.reload();

		layoutExcelDao.save(layoutExcelDao.load());
		layoutExcelDao.save(layoutExcelDao.load());
		layoutManager.reload();

		transformExcelDao.save(transformExcelDao.load());
		;

	}

}
