package com.eactive.eai.common.pushinfo;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;

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 com.eactive.eai.common.dao.DAOException;
import com.eactive.eai.common.pushinfo.PushInfoDetailVO.Result;
import com.eactive.eai.data.CommonJPATestConfiguration;
import com.eactive.eai.data.jpa.BaseRepositoryImpl;

@DataJpaTest
@ContextConfiguration(classes = { CommonJPATestConfiguration.class })
@ComponentScan({ "com.eactive.eai.common.pushinfo" })
@EnableJpaRepositories(repositoryBaseClass = BaseRepositoryImpl.class, basePackages = {
		"com.eactive.eai.common.pushinfo" })
@EntityScan({ "com.eactive.eai.data.entity.onl.pushinfo" })
class PushInfoDAOTest {
	@Autowired
	PushInfoDAO pushInfoDAO;

	@Test
	void test() throws DAOException {
		// given
		String guid = "guid001";
		int count = 2;
		PushInfoVO vo = new PushInfoVO();
		vo.setGuid(guid);
		vo.setPushTargetCount(count);
		vo.setPushTarget("0001,0002");
		// when
		pushInfoDAO.insertPushInfo(vo);

		List<PushInfoDetailVO> list = new ArrayList<>();
		for (int i = 0; i < count; i++) {
			PushInfoDetailVO detail = new PushInfoDetailVO();
			detail.setGuid("GUID" + i);
			detail.setPushResult(Result.success);
			list.add(detail);
		}
		pushInfoDAO.batchInsertPushInfoDetail(list);
		// then
		assertTrue(pushInfoDAO.getPushInfoDetailCount() == 2);
	}

}
