刘光辉
117 分钟以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package jnpf.dmsController.filecenter;
 
import jnpf.dmsController.DmsControllerTestSupport;
import jnpf.dmsEntity.operationlog.vo.DmsFileOperationLogPageVO;
import jnpf.dmsEntity.permission.vo.DmsCursorPageVO;
import jnpf.dmsEntity.permission.vo.DmsFileCenterItemVO;
import jnpf.dmsEntity.permission.vo.DmsFolderTreeNodeVO;
import jnpf.dmsService.DmsFileCenterService;
import jnpf.dmsService.DmsFileOperationLogService;
import org.junit.jupiter.api.Test;
 
import java.util.UUID;
 
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class FileCenterControllerTest extends DmsControllerTestSupport {
    private final DmsFileCenterService fileCenterService = mock(DmsFileCenterService.class);
    private final DmsFileOperationLogService operationLogService = mock(DmsFileOperationLogService.class);
    private final FileCenterController controller =
            new FileCenterController(fileCenterService, operationLogService);
 
    @Test
    void delegatesTreeRootAndNodeExpansion() {
        UUID parentId = UUID.randomUUID();
        DmsCursorPageVO<DmsFolderTreeNodeVO> page = new DmsCursorPageVO<>();
        when(fileCenterService.folderTree(null, null, null)).thenReturn(page);
        when(fileCenterService.folderTree(parentId, "cursor", 50)).thenReturn(page);
        assertSame(page, controller.folderTree(null, null, null).getData());
        assertSame(page, controller.folderTree(parentId, "cursor", 50).getData());
        verify(fileCenterService).folderTree(null, null, null);
        verify(fileCenterService).folderTree(parentId, "cursor", 50);
    }
 
    @Test
    void delegatesEveryPermissionFilteredFileCenterApi() {
        UUID folderId = UUID.randomUUID();
        UUID documentId = UUID.randomUUID();
        UUID fileVersionId = UUID.randomUUID();
        DmsCursorPageVO<DmsFileCenterItemVO> rootPage = new DmsCursorPageVO<>();
        DmsCursorPageVO<DmsFileCenterItemVO> childPage = new DmsCursorPageVO<>();
        DmsCursorPageVO<DmsFileCenterItemVO> currentPage = new DmsCursorPageVO<>();
        DmsCursorPageVO<DmsFileCenterItemVO> historyPage = new DmsCursorPageVO<>();
        DmsCursorPageVO<DmsFileCenterItemVO> versionsPage = new DmsCursorPageVO<>();
        DmsCursorPageVO<DmsFileCenterItemVO> sharedPage = new DmsCursorPageVO<>();
        DmsFileOperationLogPageVO logPage = mock(DmsFileOperationLogPageVO.class);
        when(fileCenterService.rootFolders("root-cursor", 20)).thenReturn(rootPage);
        when(fileCenterService.childFolders(folderId, "child-cursor", 21)).thenReturn(childPage);
        when(fileCenterService.currentDocuments(folderId, "current-cursor", 22, "manual"))
                .thenReturn(currentPage);
        when(fileCenterService.historicalVersions(folderId, "history-cursor", 23, "obsolete"))
                .thenReturn(historyPage);
        when(fileCenterService.documentVersions(documentId, "historical", "version-cursor", 24, "v1"))
                .thenReturn(versionsPage);
        when(operationLogService.page(fileVersionId, "viewer", 2, 25)).thenReturn(logPage);
        when(fileCenterService.sharedDocuments("current", "shared-cursor", 26)).thenReturn(sharedPage);
 
        assertSame(rootPage, controller.rootFolders("root-cursor", 20).getData());
        assertSame(childPage, controller.childFolders(folderId, "child-cursor", 21).getData());
        assertSame(currentPage,
                controller.currentDocuments(folderId, "current-cursor", 22, "manual").getData());
        assertSame(historyPage,
                controller.historicalVersions(folderId, "history-cursor", 23, "obsolete").getData());
        assertSame(versionsPage, controller.documentVersions(
                documentId, "historical", "version-cursor", 24, "v1").getData());
        assertSame(logPage, controller.fileOperationLogs(fileVersionId, "viewer", 2, 25).getData());
        assertSame(sharedPage, controller.sharedDocuments("current", "shared-cursor", 26).getData());
 
        verify(fileCenterService).rootFolders("root-cursor", 20);
        verify(fileCenterService).childFolders(folderId, "child-cursor", 21);
        verify(fileCenterService).currentDocuments(folderId, "current-cursor", 22, "manual");
        verify(fileCenterService).historicalVersions(folderId, "history-cursor", 23, "obsolete");
        verify(fileCenterService).documentVersions(
                documentId, "historical", "version-cursor", 24, "v1");
        verify(operationLogService).page(fileVersionId, "viewer", 2, 25);
        verify(fileCenterService).sharedDocuments("current", "shared-cursor", 26);
    }
 
    @Test
    void delegatesFileNameExistenceCheck() {
        UUID folderId = UUID.randomUUID();
        when(fileCenterService.fileNameExists(folderId, "report.pdf", "V2")).thenReturn(true);
 
        assertTrue(controller.fileNameExists(folderId, "report.pdf", "V2").getData());
        verify(fileCenterService).fileNameExists(folderId, "report.pdf", "V2");
    }
}