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(), "사용여부를 수정한다."); + } + +}