diff --git a/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestDeleteSampleTest.java b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestDeleteSampleTest.java new file mode 100644 index 0000000..1ad2009 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestDeleteSampleTest.java @@ -0,0 +1,63 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.time.LocalDateTime; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import egovframework.example.sample.service.SampleVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.deleteSample] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-19 + * + */ +@SpringBootTest +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestDeleteSampleTest { + + @Autowired + private SampleMapper sampleMapper; + + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + sampleVO.setId(egovIdGnrService.getNextStringId()); + + final String now = LocalDateTime.now().toString(); + + sampleVO.setName("test 이백행 카테고리명 " + now); + sampleVO.setDescription("test 이백행 설명 " + now); + sampleVO.setUseYn("Y"); + sampleVO.setRegUser("eGov"); + + sampleMapper.insertSample(sampleVO); + + // when + sampleMapper.deleteSample(sampleVO); + + // then + final SampleVO resultSampleVO = sampleMapper.selectSample(sampleVO); + + if (log.isDebugEnabled()) { + log.debug("sampleVO={}", sampleVO); + log.debug("resultSampleVO={}", resultSampleVO); + } + + assertNull(resultSampleVO, "글을 삭제한다. 삭제 후 조회 결과 없음"); + } + +} diff --git a/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTest.java b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTest.java new file mode 100644 index 0000000..13b7b08 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTest.java @@ -0,0 +1,70 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.time.LocalDateTime; +import java.util.List; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import egovframework.example.sample.service.SampleVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.selectSampleList] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-19 + * + */ +@SpringBootTest +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestSelectSampleListTest { + + @Autowired + private SampleMapper sampleMapper; + + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + sampleVO.setId(egovIdGnrService.getNextStringId()); + + final String now = LocalDateTime.now().toString(); + + sampleVO.setName("test 이백행 카테고리명 " + now); + sampleVO.setDescription("test 이백행 설명 " + now); + sampleVO.setUseYn("Y"); + sampleVO.setRegUser("eGov"); + + sampleMapper.insertSample(sampleVO); + + // when + final SampleVO searchVO = new SampleVO(); + searchVO.setRecordCountPerPage(10); + searchVO.setFirstIndex(0); + searchVO.setSearchCondition("1"); + searchVO.setSearchKeyword(sampleVO.getName()); + + final List resultList = sampleMapper.selectSampleList(searchVO); + + if (log.isDebugEnabled()) { + log.debug("searchVO={}", searchVO); + log.debug("resultList={}", resultList); + } + + // then + assertNotNull(resultList, "목록 조회 결과가 null이 아님"); + assertFalse(resultList.isEmpty(), "목록 조회 결과가 비어 있지 않음"); + } + +} diff --git a/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTotCntTest.java b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTotCntTest.java new file mode 100644 index 0000000..40c84b1 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTotCntTest.java @@ -0,0 +1,65 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.LocalDateTime; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import egovframework.example.sample.service.SampleVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.selectSampleListTotCnt] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-19 + * + */ +@SpringBootTest +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestSelectSampleListTotCntTest { + + @Autowired + private SampleMapper sampleMapper; + + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + sampleVO.setId(egovIdGnrService.getNextStringId()); + + final String now = LocalDateTime.now().toString(); + + sampleVO.setName("test 이백행 카테고리명 " + now); + sampleVO.setDescription("test 이백행 설명 " + now); + sampleVO.setUseYn("Y"); + sampleVO.setRegUser("eGov"); + + sampleMapper.insertSample(sampleVO); + + // when + final SampleVO searchVO = new SampleVO(); + searchVO.setSearchCondition("1"); + searchVO.setSearchKeyword(sampleVO.getName()); + + final int totCnt = sampleMapper.selectSampleListTotCnt(searchVO); + + if (log.isDebugEnabled()) { + log.debug("searchVO={}", searchVO); + log.debug("totCnt={}", totCnt); + } + + // then + assertTrue(totCnt > 0, "전체 건수가 1 이상임"); + } + +} diff --git a/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestUpdateSampleTest.java b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestUpdateSampleTest.java new file mode 100644 index 0000000..bd11246 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestUpdateSampleTest.java @@ -0,0 +1,80 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.time.LocalDateTime; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import egovframework.example.sample.service.SampleVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.updateSample] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-19 + * + */ +@SpringBootTest +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestUpdateSampleTest { + + @Autowired + private SampleMapper sampleMapper; + + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + sampleVO.setId(egovIdGnrService.getNextStringId()); + + final String now = LocalDateTime.now().toString(); + + sampleVO.setName("test 이백행 카테고리명 " + now); + sampleVO.setDescription("test 이백행 설명 " + now); + sampleVO.setUseYn("Y"); + sampleVO.setRegUser("eGov"); + + sampleMapper.insertSample(sampleVO); + + // when + final String updatedNow = LocalDateTime.now().toString(); + sampleVO.setName("test 이백행 수정 카테고리명 " + updatedNow); + sampleVO.setDescription("test 이백행 수정 설명 " + updatedNow); + sampleVO.setUseYn("N"); + + sampleMapper.updateSample(sampleVO); + + // then + final SampleVO resultSampleVO = sampleMapper.selectSample(sampleVO); + + if (log.isDebugEnabled()) { + log.debug("sampleVO={}", sampleVO); + log.debug("resultSampleVO={}", resultSampleVO); + + log.debug("getId={}, {}", sampleVO.getId(), resultSampleVO.getId()); + log.debug("getName={}, {}", sampleVO.getName(), resultSampleVO.getName()); + log.debug("getDescription={}, {}", sampleVO.getDescription(), resultSampleVO.getDescription()); + log.debug("getUseYn={}, {}", sampleVO.getUseYn(), resultSampleVO.getUseYn()); + } + + asserts(sampleVO, resultSampleVO); + } + + private void asserts(final SampleVO sampleVO, final SampleVO resultSampleVO) { + assertEquals(sampleVO.getId(), resultSampleVO.getId(), "글을 수정한다. getId"); + assertEquals(sampleVO.getName(), resultSampleVO.getName(), "글을 수정한다. 카테고리명"); + assertEquals(sampleVO.getDescription(), resultSampleVO.getDescription(), "글을 수정한다. 설명"); + assertEquals(sampleVO.getUseYn(), resultSampleVO.getUseYn(), "글을 수정한다. 사용여부"); + } + +}