package com.eactive.eai.common.b2badaptermapping;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.jdbc.Sql;

import com.eactive.eai.common.server.EAIServerManager;
import com.eactive.eai.data.CommonJPATestConfiguration;
import com.eactive.eai.data.jpa.BaseRepositoryImpl;

@DataJpaTest
@ContextConfiguration(classes = { CommonJPATestConfiguration.class, EAIServerManager.class })
@ComponentScan({ "com.eactive.eai.common.b2badaptermapping" })
@EnableJpaRepositories(repositoryBaseClass = BaseRepositoryImpl.class, basePackages = {
		"com.eactive.eai.common.b2badaptermapping" })
@EntityScan({ "com.eactive.eai.data.entity.onl.b2badaptermapping" })
@Sql({ "/com/eactive/eai/common/b2badaptermapping/init_tseaifr07.sql" })
class B2BAdapterMapDAOTest {

	@SpyBean
	B2BAdapterMapDAO b2bAdapterMapDAO;

	@MockBean
	private EAIServerManager eaiServerManager;

	@Test
	void getAllB2BAdapterMapsTest() throws Exception {
		// given
		String eaiInstCd = "fepOnlSvr12";

		// when
		b2bAdapterMapDAO.getAllB2BAdapterMaps(eaiInstCd);

		// then
		assertNotNull(b2bAdapterMapDAO.getAllB2BAdapterMaps(eaiInstCd));
		assertTrue(b2bAdapterMapDAO.getAllB2BAdapterMaps(eaiInstCd).size() > 0);
	}

	@Test
	void getB2BAdapterMapTest() throws Exception {
		// given
		String eaiInstCd = "fepOnlSvr22";
		String eaiSvcCd = "ATS0210012270R2";

		// when
		b2bAdapterMapDAO.getB2BAdapterMap(eaiInstCd, eaiSvcCd);

		// then
		assertNotNull(b2bAdapterMapDAO.getB2BAdapterMap(eaiInstCd, eaiSvcCd));
		assertTrue(b2bAdapterMapDAO.getB2BAdapterMap(eaiInstCd, eaiSvcCd).size() > 0);
	}
}
