From 872e6d9f8fcb13ea1ac3f0f8921dbe2730ffc35a Mon Sep 17 00:00:00 2001 From: wantaek Date: Wed, 9 Sep 2026 14:55:18 +0900 Subject: [PATCH] =?UTF-8?q?fix(sample):=20=EB=AA=A9=EB=A1=9D=20=ED=96=89?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=EA=B0=80=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=8B=B9=20=EA=B1=B4=EC=88=98=20=EB=8C=80=EC=8B=A0=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=A7=81=ED=81=AC=20=EA=B0=9C=EC=88=98?= =?UTF-8?q?=EB=A5=BC=20=EC=93=B0=EB=8D=98=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EgovSampleController 는 두 값을 다른 축으로 나눠 넣는다. 86행은 pageUnit 을 PaginationInfo.recordCountPerPage(페이지당 건수)로, 87행은 pageSize 를 PaginationInfo.pageSize 로 넣는다. PaginationInfo 에서 pageSize 는 getFirstPageNoOnPageList/getLastPageNoOnPageList 에서만 쓰이는 페이지 링크 묶음 크기이고, 레코드 오프셋은 recordCountPerPage 로 계산한다. EgovSample_Sample_SQL.xml 73행의 LIMIT #{recordCountPerPage} OFFSET #{firstIndex} 도 같은 축이다. 그런데 egovSampleList.html 98행의 행 번호 식만 페이지당 건수 자리에 sampleVO.pageSize 를 곱하고 있었다. EgovConfigProperties 가 두 값을 모두 10 으로 두고 있어 기본 설정에서는 결과가 우연히 같지만, 값을 다르게 잡으면 2페이지부터 번호가 어긋난다. pageUnit=10, pageSize=5, 총 114건이면 2페이지 첫 행이 104 가 아니라 109 로 찍혀 1페이지 6번째 행과 번호가 겹친다. 컨트롤러 91행이 sampleVO.recordCountPerPage 를 이미 채워 두므로 템플릿에서 그 값을 쓰도록 바꿨다. 두 값을 다르게 설정하고 2페이지 첫 행 번호를 확인하는 테스트를 추가했다. --- .../thymeleaf/sample/egovSampleList.html | 2 +- ...ControllerTestSelectListRowNumberTest.java | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/test/java/egovframework/example/sample/web/EgovSampleControllerTestSelectListRowNumberTest.java diff --git a/src/main/resources/templates/thymeleaf/sample/egovSampleList.html b/src/main/resources/templates/thymeleaf/sample/egovSampleList.html index 26441cb..613a29a 100644 --- a/src/main/resources/templates/thymeleaf/sample/egovSampleList.html +++ b/src/main/resources/templates/thymeleaf/sample/egovSampleList.html @@ -95,7 +95,7 @@

- + diff --git a/src/test/java/egovframework/example/sample/web/EgovSampleControllerTestSelectListRowNumberTest.java b/src/test/java/egovframework/example/sample/web/EgovSampleControllerTestSelectListRowNumberTest.java new file mode 100644 index 0000000..87bc6b7 --- /dev/null +++ b/src/test/java/egovframework/example/sample/web/EgovSampleControllerTestSelectListRowNumberTest.java @@ -0,0 +1,93 @@ +package egovframework.example.sample.web; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.egovframe.rte.fdl.property.impl.EgovPropertyServiceImpl; +import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +/** + * [게시판][EgovSampleController.selectList] 목록 행 번호 단위 테스트 + * + * 페이지당 건수(pageUnit)와 페이지 링크 묶음 크기(pageSize)를 다른 값으로 두고 + * 행 번호가 페이지당 건수를 따라가는지 확인한다. + * + * @author wantaek + * @since 2026-09-09 + */ +@SpringBootTest +@AutoConfigureMockMvc +class EgovSampleControllerTestSelectListRowNumberTest { + + private static final int PAGE_INDEX = 2; + + /** 목록 No 칸. 이름·설명 칸에는 숫자만 들어가는 값이 없어 이 칸만 잡힌다. */ + private static final Pattern ROW_NUMBER = Pattern.compile("(\\d+)"); + + @Autowired + private MockMvc mockMvc; + + /** + * 두 값이 같으면 행 번호 식이 어느 쪽을 쓰든 결과가 같아 검증이 되지 않으므로 + * pageUnit 과 pageSize 를 다르게 준다. + */ + @TestConfiguration + static class EgovConfigPropertiesTestConfig { + + @Bean(destroyMethod = "destroy") + EgovPropertyServiceImpl propertiesService() { + final Map properties = new HashMap<>(); + properties.put("pageUnit", "10"); + properties.put("pageSize", "5"); + + final EgovPropertyServiceImpl egovPropertyServiceImpl = new EgovPropertyServiceImpl(); + egovPropertyServiceImpl.setProperties(properties); + return egovPropertyServiceImpl; + } + + } + + @Test + @DisplayName("행 번호는 페이지 링크 묶음 크기가 아니라 페이지당 건수만큼 페이지마다 건너뛴다") + void test_행번호_페이지당건수() throws Exception { + // given + final MvcResult mvcResult = mockMvc + .perform(get("/egovSampleList.do").param("pageIndex", String.valueOf(PAGE_INDEX))) + .andExpect(status().isOk()) + .andReturn(); + + final PaginationInfo paginationInfo = (PaginationInfo) mvcResult.getModelAndView().getModel() + .get("paginationInfo"); + + assertThat(paginationInfo.getRecordCountPerPage()).isNotEqualTo(paginationInfo.getPageSize()); + assertThat(paginationInfo.getTotalRecordCount()).isGreaterThan(paginationInfo.getRecordCountPerPage()); + + // when + final String content = mvcResult.getResponse().getContentAsString(); + + // then + // 목록은 내림차순이므로 2페이지 첫 행 = 총건수 + 1 - ((2 - 1) * 페이지당건수 + 1) + final int expected = paginationInfo.getTotalRecordCount() + 1 + - ((PAGE_INDEX - 1) * paginationInfo.getRecordCountPerPage() + 1); + + final Matcher matcher = ROW_NUMBER.matcher(content); + assertThat(matcher.find()).isTrue(); + assertThat(Integer.parseInt(matcher.group(1))).isEqualTo(expected); + } + +}