package com.eactive.eai.common.b2badaptermapping;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;

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 B2BAdapterMapManagerTest {

	@SpyBean
	B2BAdapterMapManager b2bAdapterMapManager;

	@MockBean
	private EAIServerManager eaiServerManager;

	@Test
	void testStart() throws Exception {
		// given
		given(eaiServerManager.getLocalServerName()).willReturn("fepOnlSvr12");

		// when
		b2bAdapterMapManager.start();

		// then
		assertNotNull(b2bAdapterMapManager.getAllKeyNames());
		assertTrue(b2bAdapterMapManager.getAllKeyNames().length > 0);

	}

}
