Merge pull request #68 from LeeBaekHaeng/2024/test/EgovBBSAttributeManageApiController
[게시판생성관리][BBSAttributeManageDAO.insertBBSMasterInf] DAO 단위 테스트main
commit
8cebcfbd40
@ -0,0 +1,67 @@
|
|||||||
|
package egovframework.let.cop.bbs.service.impl;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
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.let.cop.bbs.service.BoardMaster;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [게시판생성관리][BBSAttributeManageDAO.insertBBSMasterInf] DAO 단위 테스트
|
||||||
|
*
|
||||||
|
* @author 이백행
|
||||||
|
* @since 2024-09-20
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
class BBSAttributeManageDAOTestInsertBBSMasterInfTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 게시판 속성정보 관리를 위한 데이터 접근 클래스
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private BBSAttributeManageDAO bbsAttributeManageDAO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private EgovIdGnrService egovBBSMstrIdGnrService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() throws Exception {
|
||||||
|
// given
|
||||||
|
final BoardMaster boardMaster = new BoardMaster();
|
||||||
|
|
||||||
|
boardMaster.setBbsId(egovBBSMstrIdGnrService.getNextStringId());
|
||||||
|
|
||||||
|
final String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS"));
|
||||||
|
|
||||||
|
boardMaster.setBbsNm("test 이백행 게시판명 " + now);
|
||||||
|
|
||||||
|
boardMaster.setPosblAtchFileSize("0");
|
||||||
|
|
||||||
|
final int expected = 1;
|
||||||
|
|
||||||
|
// when
|
||||||
|
final int result = bbsAttributeManageDAO.insertBBSMasterInf(boardMaster);
|
||||||
|
|
||||||
|
// then
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("result={}, {}", expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(expected, result, "신규 게시판 속성정보를 등록한다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package egovframework.let.cop.bbs.service.impl;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import egovframework.let.cop.bbs.service.BoardMaster;
|
||||||
|
import egovframework.let.cop.bbs.service.BoardMasterVO;
|
||||||
|
import egovframework.let.cop.bbs.service.EgovBBSAttributeManageService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [게시판생성관리][EgovBBSUseInfoManageServiceImpl.insertBBSMastetInf] ServiceImpl 단위
|
||||||
|
* 테스트
|
||||||
|
*
|
||||||
|
* @author 이백행
|
||||||
|
* @since 2024-09-20
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
class EgovBBSUseInfoManageServiceImplTestInsertBBSMastetInfTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 게시판 속성정보 관리를 위한 데이터 접근 클래스
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private EgovBBSAttributeManageService egovBBSAttributeManageService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() throws Exception {
|
||||||
|
// given
|
||||||
|
final BoardMaster boardMaster = new BoardMaster();
|
||||||
|
|
||||||
|
final String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS"));
|
||||||
|
|
||||||
|
boardMaster.setBbsNm("test 이백행 게시판명 " + now);
|
||||||
|
|
||||||
|
boardMaster.setPosblAtchFileSize("0");
|
||||||
|
|
||||||
|
// when
|
||||||
|
final String result = egovBBSAttributeManageService.insertBBSMastetInf(boardMaster);
|
||||||
|
|
||||||
|
// then
|
||||||
|
final BoardMasterVO resultBoardMasterVO = egovBBSAttributeManageService.selectBBSMasterInf(boardMaster);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("result={}", result);
|
||||||
|
log.debug("resultBoardMasterVO={}", resultBoardMasterVO);
|
||||||
|
log.debug("getBbsId={}", resultBoardMasterVO.getBbsId());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(result, resultBoardMasterVO.getBbsId(), "신규 게시판 속성정보를 생성한다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,168 @@
|
|||||||
|
package egovframework.let.cop.bbs.web;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
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.web.client.TestRestTemplate;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import egovframework.let.cop.bbs.service.BoardMaster;
|
||||||
|
import egovframework.let.cop.bbs.service.EgovBBSAttributeManageService;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [게시판생성관리][EgovBBSAttributeManageApiController.insertBBSMasterInf] Controller
|
||||||
|
* 단위 테스트
|
||||||
|
*
|
||||||
|
* @author 이백행
|
||||||
|
* @since 2024-09-20
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//@SpringBootTest
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
//@AutoConfigureMockMvc(addFilters = false)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
class EgovBBSAttributeManageApiControllerTestInsertBBSMasterInfTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 게시판 속성정보 관리를 위한 데이터 접근 클래스
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private EgovBBSAttributeManageService egovBBSAttributeManageService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() throws Exception {
|
||||||
|
// testData
|
||||||
|
final BoardMaster boardMaster = new BoardMaster();
|
||||||
|
|
||||||
|
final String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS"));
|
||||||
|
|
||||||
|
boardMaster.setBbsNm("test 이백행 게시판명 " + now);
|
||||||
|
|
||||||
|
boardMaster.setPosblAtchFileSize("0");
|
||||||
|
|
||||||
|
final String resultBbsId = egovBBSAttributeManageService.insertBBSMastetInf(boardMaster);
|
||||||
|
|
||||||
|
// given
|
||||||
|
|
||||||
|
JwtResponse jwtResponse = getJwtResponse();
|
||||||
|
|
||||||
|
// when
|
||||||
|
mockMvc.perform(
|
||||||
|
|
||||||
|
get("/bbsMaster")
|
||||||
|
|
||||||
|
.param("searchCnd", "0")
|
||||||
|
|
||||||
|
.param("searchWrd", boardMaster.getBbsNm())
|
||||||
|
|
||||||
|
.header("Authorization", jwtResponse.getJToken())
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
.andDo(print())
|
||||||
|
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
|
||||||
|
// resultCode
|
||||||
|
.andExpect(jsonPath("$.resultCode").value(200))
|
||||||
|
|
||||||
|
.andExpect(jsonPath("$.resultCode").value(equalTo(200)))
|
||||||
|
|
||||||
|
// resultMessage
|
||||||
|
.andExpect(jsonPath("$.resultMessage").value("성공했습니다."))
|
||||||
|
|
||||||
|
.andExpect(jsonPath("$.resultMessage").value(equalTo("성공했습니다.")))
|
||||||
|
|
||||||
|
// resultCnt
|
||||||
|
.andExpect(jsonPath("$.result.resultCnt").value("1"))
|
||||||
|
|
||||||
|
.andExpect(jsonPath("$.result.resultCnt").value(equalTo("1")))
|
||||||
|
|
||||||
|
// bbsNm
|
||||||
|
.andExpect(jsonPath("$.result.resultList[0].bbsNm").value(boardMaster.getBbsNm()))
|
||||||
|
|
||||||
|
.andExpect(jsonPath("$.result.resultList[0].bbsNm").value(equalTo(boardMaster.getBbsNm())))
|
||||||
|
|
||||||
|
// bbsId
|
||||||
|
.andExpect(jsonPath("$.result.resultList[0].bbsId").value(resultBbsId))
|
||||||
|
|
||||||
|
.andExpect(jsonPath("$.result.resultList[0].bbsId").value(equalTo(resultBbsId)))
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
// then
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("resultBbsId={}", resultBbsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("", "", "게시판 마스터 목록을 조회한다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
static class JwtRequest {
|
||||||
|
private String userSe;
|
||||||
|
private String id;
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
static class JwtResponse {
|
||||||
|
private int resultCode;
|
||||||
|
private String jToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JwtResponse getJwtResponse() {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
final JwtRequest jwtRequest = new JwtRequest();
|
||||||
|
jwtRequest.setUserSe("USR");
|
||||||
|
jwtRequest.setId("admin");
|
||||||
|
jwtRequest.setPassword("1");
|
||||||
|
HttpEntity<JwtRequest> request = new HttpEntity<>(jwtRequest, headers);
|
||||||
|
// final JwtResponse jwtResponse = restTemplate.postForObject("/auth/login-jwt", request, JwtResponse.class);
|
||||||
|
final String content = restTemplate.postForObject("/auth/login-jwt", request, String.class);
|
||||||
|
final String content2 = content.substring(content.indexOf("\"jToken\":\"") + 10);
|
||||||
|
final String content3 = content2.substring(0, content2.indexOf("\""));
|
||||||
|
// final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
// mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
// final JwtResponse jwtResponse = mapper.readValue(content, JwtResponse.class);
|
||||||
|
final JwtResponse jwtResponse = new JwtResponse();
|
||||||
|
jwtResponse.setJToken(content3);
|
||||||
|
return jwtResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"resultCode": 200,
|
||||||
|
"resultMessage": "성공했습니다.",
|
||||||
|
"result": {
|
||||||
|
"resultCnt": "1",
|
||||||
|
"paginationInfo": {
|
||||||
|
"currentPageNo": 1,
|
||||||
|
"recordCountPerPage": 10,
|
||||||
|
"pageSize": 10,
|
||||||
|
"totalRecordCount": 1,
|
||||||
|
"totalPageCount": 1,
|
||||||
|
"firstPageNoOnPageList": 1,
|
||||||
|
"lastPageNoOnPageList": 1,
|
||||||
|
"firstRecordIndex": 0,
|
||||||
|
"lastRecordIndex": 10,
|
||||||
|
"firstPageNo": 1,
|
||||||
|
"lastPageNo": 1
|
||||||
|
},
|
||||||
|
"resultList": [
|
||||||
|
{
|
||||||
|
"bbsAttrbCode": " ",
|
||||||
|
"bbsId": "BBSMSTR_000000000001",
|
||||||
|
"bbsIntrcn": "",
|
||||||
|
"bbsNm": "test 이백행 게시판명 2024-09-20T21:31:36.026000000",
|
||||||
|
"bbsTyCode": " ",
|
||||||
|
"fileAtchPosblAt": "",
|
||||||
|
"frstRegisterId": "",
|
||||||
|
"frstRegisterPnttm": "2024-09-20",
|
||||||
|
"lastUpdusrId": "",
|
||||||
|
"lastUpdusrPnttm": "",
|
||||||
|
"posblAtchFileNumber": 0,
|
||||||
|
"posblAtchFileSize": "",
|
||||||
|
"replyPosblAt": "",
|
||||||
|
"tmplatId": " ",
|
||||||
|
"useAt": " ",
|
||||||
|
"bbsUseFlag": "",
|
||||||
|
"trgetId": "",
|
||||||
|
"registSeCode": "",
|
||||||
|
"uniqId": "",
|
||||||
|
"tmplatNm": "",
|
||||||
|
"option": "",
|
||||||
|
"commentAt": "",
|
||||||
|
"stsfdgAt": "",
|
||||||
|
"searchBgnDe": "",
|
||||||
|
"searchCnd": "",
|
||||||
|
"searchEndDe": "",
|
||||||
|
"searchWrd": "",
|
||||||
|
"sortOrdr": "",
|
||||||
|
"searchUseYn": "",
|
||||||
|
"pageIndex": 1,
|
||||||
|
"pageUnit": 10,
|
||||||
|
"pageSize": 10,
|
||||||
|
"firstIndex": 1,
|
||||||
|
"lastIndex": 1,
|
||||||
|
"recordCountPerPage": 10,
|
||||||
|
"rowNo": 0,
|
||||||
|
"frstRegisterNm": "",
|
||||||
|
"bbsTyCodeNm": "",
|
||||||
|
"bbsAttrbCodeNm": "",
|
||||||
|
"lastUpdusrNm": "",
|
||||||
|
"authFlag": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue