use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class CompressTest method testDBEquals.
@Test
public void testDBEquals() throws IOException {
HashMap<String, Integer> map = new HashMap<>();
map.put("offset", 0);
map.put("noOfRecords", 1000);
List<BoardDTO> boardList = boardMapper.articleList(map);
List<String> contentStrList = new ArrayList<>(boardList.size());
List<byte[]> historyContentList = new ArrayList<>(boardList.size());
List<Boolean> compressResult = new ArrayList<>(boardList.size());
List<Boolean> decompressResult = new ArrayList<>(boardList.size());
for (BoardDTO boardDTO : boardList) {
contentStrList.add(boardDTO.getContent());
BoardHistoryDTO historyDTO = boardHistoryMapper.getHistory(boardDTO);
assertNotNull(historyDTO);
historyContentList.add(historyDTO.getHistory_content());
}
for (int i = 0; i < boardList.size(); i++) {
byte[] compressedBytes = Compress.compress(contentStrList.get(i));
String deCompressed = Compress.deCompress(historyContentList.get(i));
compressResult.add(Arrays.equals(compressedBytes, historyContentList.get(i)));
decompressResult.add(deCompressed == null ? (contentStrList.get(i) == null ? true : false) : deCompressed.equals(contentStrList.get(i)));
}
boolean allResult = false;
for (int i = 0; i < boardList.size(); i++) {
if (!compressResult.get(i)) {
System.out.println(i + "에러 인가??");
// allResult = true;
}
if (!decompressResult.get(i)) {
System.out.println(i + "에러");
allResult = true;
}
}
assertFalse(allResult);
}
use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class VersionManagementServiceMultiThreadTest method testModifyAndDeleteVersion.
@Test
public void testModifyAndDeleteVersion() throws JsonProcessingException {
int generationCnt = THREAD_COUNT;
List<NodePtrDTO> generation = new ArrayList<>(generationCnt);
generation.add(defaultCreatedDTO);
for (int i = 1; i < generationCnt; i++) {
NodePtrDTO parentPtr = generation.get(i - 1);
NodePtrDTO child = VersionManagementServiceMultiThreadTest.makeChild(versionManagementService, boardMapper, parentPtr);
generation.add(child);
}
BoardDTO modifiedBoardDTO = new BoardDTO();
modifiedBoardDTO.setSubject("modifiedSub");
modifiedBoardDTO.setSubject("modifiedContent");
int i = 0;
for (; i < THREAD_COUNT / 2; i++) {
Thread thread = new Thread(() -> {
int randIdx = (int) (Math.random() * THREAD_COUNT);
NodePtrDTO nodePtrDTO = generation.get(randIdx);
versionManagementService.modifyVersion(modifiedBoardDTO, nodePtrDTO);
});
threadList.add(thread);
}
HashMap<String, Integer> articleListParams = new HashMap<>();
articleListParams.put("offset", 0);
articleListParams.put("noOfRecords", Integer.MAX_VALUE);
int root_board_id = defaultCreatedDTO.getRoot_board_id();
for (; i < THREAD_COUNT; i++) {
Thread thread = new Thread(() -> {
List<BoardDTO> sameRoot = boardMapper.articleList(articleListParams);
sameRoot.removeIf(item -> {
return item.getRoot_board_id() != root_board_id;
});
int maxIdx = sameRoot.size() - 1;
int randIdx = (int) (Math.random() * maxIdx);
NodePtrDTO deletePtrDTO = sameRoot.get(randIdx);
versionManagementService.deleteVersion(deletePtrDTO);
});
threadList.add(thread);
}
}
use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class VersionManagementServiceMultiThreadTest method makeChild.
public static NodePtrDTO makeChild(VersionManagementService versionManagementService, BoardMapper boardMapper, NodePtrDTO parentPtrDTO) throws JsonProcessingException {
BoardDTO child = new BoardDTO();
child.setSubject("childSub");
child.setContent("childCont");
NodePtrDTO childPtrDTO = versionManagementService.modifyVersion(child, parentPtrDTO);
child.setNodePtrDTO(childPtrDTO);
BoardDTO leapBoardDTO = boardMapper.viewDetail(childPtrDTO.toMap());
assertNotNull(leapBoardDTO);
int parentVersion = parentPtrDTO.getVersion() == null ? 0 : parentPtrDTO.getVersion();
assertEquals((Integer) (parentVersion + 1), childPtrDTO.getVersion());
Utils.assertConvertToJsonObject(child, leapBoardDTO);
return childPtrDTO;
}
use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class VersionManagementTest method testMakeLeapVersion.
@Test
public void testMakeLeapVersion() throws InterruptedException, ExecutionException, JsonProcessingException {
BoardDTO child = new BoardDTO();
child.setSubject("childSub");
child.setContent("childCont");
NodePtrDTO parentPtrDTO = defaultCreatedDTO;
NodePtrDTO resultPtrDTO = versionManagementService.modifyVersion(child, parentPtrDTO);
BoardDTO parentBoardDTO = boardMapper.viewDetail(parentPtrDTO.toMap());
assertNull(parentBoardDTO);
BoardDTO leapBoardDTO = boardMapper.viewDetail(resultPtrDTO.toMap());
assertNotNull(leapBoardDTO);
int defaultVersion = defaultBoardDTO.getVersion() == null ? 0 : defaultBoardDTO.getVersion();
assertEquals((Integer) (defaultVersion + 1), resultPtrDTO.getVersion());
child.setNodePtrDTO(resultPtrDTO);
Utils.assertConvertToJsonObject(child, leapBoardDTO);
}
use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class RestController method updateMaintainAttachment.
/**
* 게시물에 첨부파일을 유지하고 싶은 경우를 글수정 데이터를 받아 DB에 등록합니다.
* @param board 사용자가 수정한 board 데이터를 받습니다.
* 글 수정 전 자신의 첨부파일을 DB에서 가져와 새로운 게시물에 등록합니다.
*/
@RequestMapping(value = "/boards/update3", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateMaintainAttachment(BoardDTO board) {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
BoardDTO pastBoard = new BoardDTO();
HashMap<String, Integer> params = new HashMap<String, Integer>();
params.put("board_id", board.getBoard_id());
params.put("version", board.getVersion());
pastBoard = boardMapper.viewDetail(params);
if (pastBoard == null) {
String json = Utils.jsonStringIfExceptionToString(pastBoard);
throw new RuntimeException("update3 메소드에서 viewDetail 메소드 실행 에러" + json);
}
board.setFile_id(pastBoard.getFile_id());
NodePtrDTO leapPtrDTO = new NodePtrDTO(board.getBoard_id(), board.getVersion());
NodePtrDTO newNode = versionManagementService.modifyVersion(board, leapPtrDTO);
if (newNode == null) {
resultMap.put("result", "버전 수정 실패");
} else {
resultMap.put("result", "success");
}
} catch (Exception e) {
resultMap.put("result", e.getMessage());
return resultMap;
}
return resultMap;
}
Aggregations