From 2c25792c48bbbb1c0b4ce6176e629daa84c8b012 Mon Sep 17 00:00:00 2001 From: dasomel Date: Thu, 28 May 2026 00:36:50 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Lombok=20annotationProcessorPaths=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EB=B9=8C=EB=93=9C=20=EC=8B=A4=ED=8C=A8=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20SampleMapper=20CRUD=20=EB=8B=A8=EC=9C=84=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=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 Lombok @Getter/@Setter 적용 후 maven-compiler-plugin에 annotationProcessorPaths가 누락되어 컴파일 오류가 발생하는 문제를 수정한다. skipTests 설정을 property로 외부화하여 CLI에서 -DskipTests=false로 테스트 실행 가능하게 한다. SampleMapper의 selectSample, updateSample, deleteSample, selectSampleList/selectSampleListTotCnt 4가지 DAO 메서드에 대한 단위 테스트를 추가한다. --- pom.xml | 13 ++- .../SampleMapperTestDeleteSampleTest.java | 87 +++++++++++++++++ .../SampleMapperTestSelectSampleListTest.java | 95 +++++++++++++++++++ .../SampleMapperTestSelectSampleTest.java | 85 +++++++++++++++++ .../SampleMapperTestUpdateSampleTest.java | 95 +++++++++++++++++++ 5 files changed, 374 insertions(+), 1 deletion(-) 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/SampleMapperTestSelectSampleTest.java create mode 100644 src/test/java/egovframework/example/sample/service/impl/SampleMapperTestUpdateSampleTest.java diff --git a/pom.xml b/pom.xml index 076f810..cc3289c 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,10 @@ + + true + + @@ -160,6 +164,13 @@ maven-compiler-plugin ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + @@ -179,7 +190,7 @@ org.apache.maven.plugins maven-surefire-plugin - true + ${skipTests} xml **/Abstract*.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..7d605f0 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestDeleteSampleTest.java @@ -0,0 +1,87 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ImportResource; +import org.springframework.test.context.ContextConfiguration; + +import egovframework.example.sample.service.SampleVO; +import egovframework.test.EgovTestAbstractSpring; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.deleteSample] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-21 + * + */ + +@ContextConfiguration(classes = { SampleMapperTestDeleteSampleTest.class, EgovTestAbstractSpring.class }) + +@Configuration + +@ImportResource({ "classpath*:egovframework/spring/context-idgen.xml", }) + +@ComponentScan(useDefaultFilters = false, basePackages = { + "egovframework.example.sample.service.impl", }, includeFilters = { + @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SampleMapper.class, }) }) + +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestDeleteSampleTest extends EgovTestAbstractSpring { + + /** + * sample에 관한 데이터처리 매퍼 클래스 + */ + @Autowired + private SampleMapper sampleMapper; + + /** + * + */ + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + + sampleVO.setId(egovIdGnrService.getNextStringId()); + sampleVO.setName("test 이백행 삭제 카테고리명"); + sampleVO.setUseYn("Y"); + sampleVO.setDescription("test 이백행 삭제 설명"); + sampleVO.setRegUser("test"); + + sampleMapper.insertSample(sampleVO); + + // when + final SampleVO deleteVO = new SampleVO(); + deleteVO.setId(sampleVO.getId()); + + sampleMapper.deleteSample(deleteVO); + + // then + final SampleVO queryVO = new SampleVO(); + queryVO.setId(sampleVO.getId()); + + final SampleVO resultSampleVO = sampleMapper.selectSample(queryVO); + + if (log.isDebugEnabled()) { + log.debug("sampleVO.getId={}", sampleVO.getId()); + 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..ae76118 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleListTest.java @@ -0,0 +1,95 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +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.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ImportResource; +import org.springframework.test.context.ContextConfiguration; + +import egovframework.example.sample.service.SampleVO; +import egovframework.test.EgovTestAbstractSpring; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.selectSampleList / selectSampleListTotCnt] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-21 + * + */ + +@ContextConfiguration(classes = { SampleMapperTestSelectSampleListTest.class, EgovTestAbstractSpring.class }) + +@Configuration + +@ImportResource({ "classpath*:egovframework/spring/context-idgen.xml", }) + +@ComponentScan(useDefaultFilters = false, basePackages = { + "egovframework.example.sample.service.impl", }, includeFilters = { + @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SampleMapper.class, }) }) + +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestSelectSampleListTest extends EgovTestAbstractSpring { + + /** + * sample에 관한 데이터처리 매퍼 클래스 + */ + @Autowired + private SampleMapper sampleMapper; + + /** + * + */ + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO1 = new SampleVO(); + sampleVO1.setId(egovIdGnrService.getNextStringId()); + sampleVO1.setName("test 이백행 목록조회1"); + sampleVO1.setUseYn("Y"); + sampleVO1.setDescription("test 이백행 목록조회 설명1"); + sampleVO1.setRegUser("test"); + sampleMapper.insertSample(sampleVO1); + + final SampleVO sampleVO2 = new SampleVO(); + sampleVO2.setId(egovIdGnrService.getNextStringId()); + sampleVO2.setName("test 이백행 목록조회2"); + sampleVO2.setUseYn("Y"); + sampleVO2.setDescription("test 이백행 목록조회 설명2"); + sampleVO2.setRegUser("test"); + sampleMapper.insertSample(sampleVO2); + + // when + final SampleVO searchVO = new SampleVO(); + searchVO.setFirstIndex(0); + searchVO.setRecordCountPerPage(10); + + final List resultList = sampleMapper.selectSampleList(searchVO); + final int totCnt = sampleMapper.selectSampleListTotCnt(searchVO); + + // then + if (log.isDebugEnabled()) { + log.debug("resultList.size={}", resultList.size()); + log.debug("totCnt={}", totCnt); + } + + assertNotNull(resultList, "목록 결과가 null이 아니어야 한다."); + assertTrue(resultList.size() >= 2, "등록한 건수 이상이어야 한다."); + assertTrue(totCnt >= 2, "전체 건수가 등록한 건수 이상이어야 한다."); + } + +} diff --git a/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleTest.java b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleTest.java new file mode 100644 index 0000000..e9529a2 --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestSelectSampleTest.java @@ -0,0 +1,85 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ImportResource; +import org.springframework.test.context.ContextConfiguration; + +import egovframework.example.sample.service.SampleVO; +import egovframework.test.EgovTestAbstractSpring; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.selectSample] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-21 + * + */ + +@ContextConfiguration(classes = { SampleMapperTestSelectSampleTest.class, EgovTestAbstractSpring.class }) + +@Configuration + +@ImportResource({ "classpath*:egovframework/spring/context-idgen.xml", }) + +@ComponentScan(useDefaultFilters = false, basePackages = { + "egovframework.example.sample.service.impl", }, includeFilters = { + @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SampleMapper.class, }) }) + +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestSelectSampleTest extends EgovTestAbstractSpring { + + /** + * sample에 관한 데이터처리 매퍼 클래스 + */ + @Autowired + private SampleMapper sampleMapper; + + /** + * + */ + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + + sampleVO.setId(egovIdGnrService.getNextStringId()); + sampleVO.setName("test 이백행 조회 카테고리명"); + sampleVO.setUseYn("Y"); + sampleVO.setDescription("test 이백행 조회 설명"); + sampleVO.setRegUser("test"); + + sampleMapper.insertSample(sampleVO); + + // when + final SampleVO queryVO = new SampleVO(); + queryVO.setId(sampleVO.getId()); + + final SampleVO resultSampleVO = sampleMapper.selectSample(queryVO); + + // then + if (log.isDebugEnabled()) { + log.debug("sampleVO.getId={}", sampleVO.getId()); + log.debug("resultSampleVO={}", resultSampleVO); + } + + assertNotNull(resultSampleVO, "조회 결과가 null이 아니어야 한다."); + assertEquals(sampleVO.getId(), resultSampleVO.getId(), "글을 조회한다."); + assertEquals(sampleVO.getName(), resultSampleVO.getName(), "이름이 일치해야 한다."); + } + +} 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..379ae6c --- /dev/null +++ b/src/test/java/egovframework/example/sample/service/impl/SampleMapperTestUpdateSampleTest.java @@ -0,0 +1,95 @@ +package egovframework.example.sample.service.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.egovframe.rte.fdl.idgnr.EgovIdGnrService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ImportResource; +import org.springframework.test.context.ContextConfiguration; + +import egovframework.example.sample.service.SampleVO; +import egovframework.test.EgovTestAbstractSpring; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * [게시판][SampleMapper.updateSample] DAO 단위 테스트 + * + * @author 이백행 + * @since 2024-09-21 + * + */ + +@ContextConfiguration(classes = { SampleMapperTestUpdateSampleTest.class, EgovTestAbstractSpring.class }) + +@Configuration + +@ImportResource({ "classpath*:egovframework/spring/context-idgen.xml", }) + +@ComponentScan(useDefaultFilters = false, basePackages = { + "egovframework.example.sample.service.impl", }, includeFilters = { + @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SampleMapper.class, }) }) + +@RequiredArgsConstructor +@Slf4j +class SampleMapperTestUpdateSampleTest extends EgovTestAbstractSpring { + + /** + * sample에 관한 데이터처리 매퍼 클래스 + */ + @Autowired + private SampleMapper sampleMapper; + + /** + * + */ + @Autowired + private EgovIdGnrService egovIdGnrService; + + @Test + void test() throws Exception { + // given + final SampleVO sampleVO = new SampleVO(); + + sampleVO.setId(egovIdGnrService.getNextStringId()); + sampleVO.setName("test 이백행 등록명"); + sampleVO.setUseYn("Y"); + sampleVO.setDescription("test 이백행 등록 설명"); + sampleVO.setRegUser("test"); + + sampleMapper.insertSample(sampleVO); + + final String id = sampleVO.getId(); + + // when + final SampleVO updateVO = new SampleVO(); + updateVO.setId(id); + updateVO.setName("test 이백행 수정명"); + updateVO.setUseYn("N"); + updateVO.setDescription("test 이백행 수정 설명"); + updateVO.setRegUser("test"); + + sampleMapper.updateSample(updateVO); + + // then + final SampleVO queryVO = new SampleVO(); + queryVO.setId(id); + + final SampleVO resultSampleVO = sampleMapper.selectSample(queryVO); + + if (log.isDebugEnabled()) { + log.debug("id={}", id); + log.debug("resultSampleVO={}", resultSampleVO); + log.debug("getName={}", resultSampleVO.getName()); + } + + assertEquals("test 이백행 수정명", resultSampleVO.getName(), "글을 수정한다."); + assertEquals("N", resultSampleVO.getUseYn(), "사용여부를 수정한다."); + } + +}