package com.eactive.eai.authserver.dao;

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

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
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.dao.DAOException;
import com.eactive.eai.data.CommonJPATestConfiguration;
import com.eactive.eai.data.jpa.BaseRepositoryImpl;

@DataJpaTest
@ContextConfiguration(classes = { CommonJPATestConfiguration.class })
@ComponentScan({ "com.eactive.eai.authserver" })
@EnableJpaRepositories(repositoryBaseClass = BaseRepositoryImpl.class, basePackages = { "com.eactive.eai.authserver" })
@EntityScan({ "com.eactive.eai.data.entity.onl.authserver" })
@Sql({ "/com/eactive/eai/authserver/init_tseaiau01.sql" })
class ClientDAOTest {

	@Autowired
	ClientDAO clientDAO;

	@Test
	void testLoadClientDetails() throws DAOException {
		// given

		// when
		clientDAO.loadClientDetails();

		// then
		assertNotNull(clientDAO.loadClientDetails());
		assertTrue(clientDAO.loadClientDetails().size() > 0);
	}

	@Test
	void testGetClientByI() throws DAOException {
		// given
		String clientId = "R4v8qDMVOmLJ1X4yKQslrKmhVOu2TNb2";
		// when
		clientDAO.getClientById(clientId);

		// then
		assertNotNull(clientDAO.getClientById(clientId));
		assertTrue(clientDAO.getClientById(clientId).getClientId().length() > 0);
	}

}
