From c92efa5f8d3fee28fb3af3a37a5839d3b291e2b4 Mon Sep 17 00:00:00 2001 From: dasomel Date: Thu, 28 May 2026 08:47:29 +0900 Subject: [PATCH] =?UTF-8?q?test:=20SampleMapper=20update/delete/selectList?= =?UTF-8?q?/selectListTotCnt=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit insertSample 테스트에 이어 나머지 CRUD 및 목록 조회 메서드에 대한 DAO 레이어 단위 테스트를 추가한다. - updateSample: 수정 후 name, description, useYn 변경 확인 - deleteSample: 삭제 후 selectSample 조회 결과 null 확인 - selectSampleList: 등록 후 키워드 검색으로 목록 조회 결과 확인 - selectSampleListTotCnt: 등록 후 키워드 검색으로 전체 건수 1 이상 확인 --- .../SampleMapperTestDeleteSampleTest.java | 63 +++++++++++++++ .../SampleMapperTestSelectSampleListTest.java | 70 ++++++++++++++++ ...eMapperTestSelectSampleListTotCntTest.java | 65 +++++++++++++++ .../SampleMapperTestUpdateSampleTest.java | 80 +++++++++++++++++++ 4 files changed, 278 insertions(+) create mode 100644 src/test/java/egovframework/example/sample/service/impl/SampleMapperTestDeleteSampleTest.java create mode 100644 src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTest.java create mode 100644 src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTotCntTest.java create mode 100644 src/test/java/egovframework/example/sample/service/impl/SampleMapperTestUpdateSampleTest.java 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(), "글을 수정한다. 사용여부"); + } + +}