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 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 rootPage = new DmsCursorPageVO<>(); DmsCursorPageVO childPage = new DmsCursorPageVO<>(); DmsCursorPageVO currentPage = new DmsCursorPageVO<>(); DmsCursorPageVO historyPage = new DmsCursorPageVO<>(); DmsCursorPageVO versionsPage = new DmsCursorPageVO<>(); DmsCursorPageVO 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"); } }