Search in sources :

Example 21 with BoardDTO

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);
}
Also used : HashMap(java.util.HashMap) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) ArrayList(java.util.ArrayList) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with BoardDTO

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);
    }
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with BoardDTO

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;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO)

Example 24 with BoardDTO

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);
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with BoardDTO

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;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) HashMap(java.util.HashMap) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BoardDTO (com.worksmobile.Assignment.Domain.BoardDTO)28 NodePtrDTO (com.worksmobile.Assignment.Domain.NodePtrDTO)13 Test (org.junit.Test)13 BoardHistoryDTO (com.worksmobile.Assignment.Domain.BoardHistoryDTO)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Before (org.junit.Before)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 FileDTO (com.worksmobile.Assignment.Domain.FileDTO)2 Paging (com.worksmobile.Assignment.Service.Paging)1