package com.eactive.eai.transformer.transform;

import org.junit.Assert;
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.test.context.ContextConfiguration;
import org.springframework.test.context.jdbc.Sql;

import com.eactive.eai.common.lifecycle.LifecycleException;
import com.eactive.eai.transformer.function.jpa.TransformJPATestConfiguration;
import com.eactive.eai.transformer.layout.LayoutManager;
import com.eactive.eai.transformer.layout.LayoutTypeManager;

@DataJpaTest
@ContextConfiguration(classes = { TransformJPATestConfiguration.class })
@Sql({ "/com/eactive/eai/transformer/init_tseaitr06.sql", "/com/eactive/eai/transformer/init_tseaitr07.sql",
		"/com/eactive/eai/transformer/init_tseaitr08.sql", "/com/eactive/eai/transformer/init_tseaitr01.sql",
		"/com/eactive/eai/transformer/init_tseaitr02.sql", "/com/eactive/eai/transformer/init_tseaitr03.sql" })
class TransformManagerTest {

	@Autowired
	TransformManager transformManager;

	@Autowired
	LayoutManager layoutManager;

	@Autowired
	LayoutTypeManager layoutTypeManager;

	@Test
	void testReload() throws LifecycleException {
		// given
		layoutTypeManager.start();
		layoutManager.start();
		// when
		transformManager.reload();

		// then
		Assert.assertTrue(transformManager.getAllTransformName().length > 0);
		for (String transformName : transformManager.getAllTransformName()) {
			System.out.println("====================================================================================");
			System.out.println(transformName);
			Transform transform = transformManager.getTransform(transformName);
			System.out.print("Source Layouts : ");
			transform.getSourceLayouts().forEachRemaining(System.out::print);
			System.out.println();

			System.out.println("Target Layout : " + transform.getTargetLayout());

			transform.getTransformItemList().forEach(System.out::println);
			System.out.println("====================================================================================");

			// then
			Assert.assertTrue(transformManager.getTransform(transformName).getTransformItemList().size() > 0);
		}
	}

}
