use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class ScheduleUnfiledRecordFolderLoadersUnitTest method testScheduleUnfiledRecordFoldersChildrenWithDepthLessThan2.
@Test
public void testScheduleUnfiledRecordFoldersChildrenWithDepthLessThan2() throws Exception {
int maxActiveLoaders = 8;
int rootUnfiledRecordFolderNumber = 0;
int unfiledRecordFolderChildrenNumber = 2;
int unfiledRecordFolderDepth = 1;
scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFolderDepth);
scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderNumber(unfiledRecordFolderChildrenNumber);
FolderData mockedUnfiledRecordContainerFolder = mock(FolderData.class);
when(mockedUnfiledRecordContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordContainerFolder.getPath()).thenReturn("/a");
FolderData mockedUnfiledRecordContainerFolder2 = mock(FolderData.class);
when(mockedUnfiledRecordContainerFolder2.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordContainerFolder2.getPath()).thenReturn("/b");
List<FolderData> folders = Arrays.asList(mockedUnfiledRecordContainerFolder, mockedUnfiledRecordContainerFolder2);
when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, Long.valueOf(UNFILED_RECORD_CONTAINER_LEVEL + 1), Long.valueOf(scheduleUnfiledRecordFolderLoaders.getMaxLevel() - 1), 0L, Long.valueOf(unfiledRecordFolderChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
FolderData unfiledContainerFolder = mock(FolderData.class);
when(unfiledContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
when(unfiledContainerFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(unfiledContainerFolder);
EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
verify(mockedFileFolderService, never()).createNewFolder(any(FolderData.class));
verify(mockedSessionService, never()).startSession(any(DBObject.class));
assertEquals(true, result.isSuccess());
assertEquals("Loading completed. Raising 'done' event.", result.getData());
assertEquals(1, result.getNextEvents().size());
assertEquals(EVENT_COMPLETE, result.getNextEvents().get(0).getName());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class FileUnfiledRecordUnitTest method testFileRecordOperationWithEmptyRecordId.
@Test
public void testFileRecordOperationWithEmptyRecordId() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_FILED);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(FILE_RECORD_OPERATION);
when(mockedData.get(FIELD_RECORD_ID)).thenReturn("");
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFolder.getContext()).thenReturn("someContext");
when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
when(mockedEvent.getSessionId()).thenReturn("someId");
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
assertEquals(false, result.isSuccess());
assertEquals("Request data not complete for filing unfiled record: " + mockedData, result.getData());
assertEquals(0, result.getNextEvents().size());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class FileUnfiledRecordUnitTest method testFileRecordOperation.
@Test
public void testFileRecordOperation() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_FILED);
loadSingleComponent.setDelay(1L);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(FILE_RECORD_OPERATION);
when(mockedData.get(FIELD_RECORD_ID)).thenReturn("recordId1");
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFolder.getContext()).thenReturn("someContext");
when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
when(mockedEvent.getSessionId()).thenReturn("someId");
String recordId1 = "recordId1";
String recordParentPath1 = "/recordParentPath1";
RecordData mockedRecordData1 = mock(RecordData.class);
when(mockedRecordData1.getId()).thenReturn(recordId1);
when(mockedRecordData1.getParentPath()).thenReturn(recordParentPath1);
when(mockedRecordService.getRecord(recordId1)).thenReturn(mockedRecordData1);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, times(1)).incrementFileCount(mockedFolder.getContext(), mockedFolder.getPath(), 1);
verify(mockedFileFolderService, times(1)).incrementFileCount(UNFILED_CONTEXT, mockedRecordData1.getParentPath(), -1);
verify(mockedRecordService, times(1)).updateRecord(any(RecordData.class));
assertEquals(true, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertEquals("Filed record with id " + recordId1 + ".", data.get("msg"));
assertEquals("/aPath", data.get(FIELD_PATH));
assertEquals("aUser", data.get("username"));
assertEquals(1, result.getNextEvents().size());
Event event = result.getNextEvents().get(0);
assertEquals(EVENT_UNFILED_RECORD_FILED, event.getName());
DBObject eventData = (DBObject) event.getData();
assertEquals("someContext", eventData.get(FIELD_CONTEXT));
assertEquals("/aPath", eventData.get(FIELD_PATH));
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class FileUnfiledRecordUnitTest method testFileRecordOperationWithRestAPiException.
@Test
public void testFileRecordOperationWithRestAPiException() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_FILED);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(FILE_RECORD_OPERATION);
when(mockedData.get(FIELD_RECORD_ID)).thenReturn("recordId1");
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFolder.getContext()).thenReturn("someContext");
when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
when(mockedEvent.getSessionId()).thenReturn("someId");
RecordData mockedRecordData = mock(RecordData.class);
when(mockedRecordService.getRecord("recordId1")).thenReturn(mockedRecordData);
Mockito.doThrow(new Exception("someError")).when(mockedRecordsAPI).fileRecord(any(RecordBodyFile.class), any(String.class));
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, never()).deleteFolder(mockedFolder.getContext(), mockedFolder.getPath() + "/locked", false);
verify(mockedFileFolderService, never()).incrementFileCount(any(String.class), any(String.class), any(Long.class));
assertEquals(false, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertNotNull(data.get("error"));
assertEquals("someError", data.get("error"));
assertEquals("aUser", data.get("username"));
assertEquals(mockedFolder.getPath(), data.get("path"));
assertNotNull(data.get("stack"));
assertEquals(0, result.getNextEvents().size());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithNoPreconfiguredPaths.
@Test
public void testUploadRecordsWithNoPreconfiguredPaths() throws Exception {
int maxActiveLoaders = 8;
int unfiledRecordsNumber = 4;
String paths = "";
scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
scheduleUnfiledRecordLoaders.setUnfiledRecordFolderPaths(paths);
FolderData mockedUnfiledRecordContainer = mock(FolderData.class);
when(mockedUnfiledRecordContainer.getId()).thenReturn("unfiledRecordContainerId");
when(mockedUnfiledRecordContainer.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordContainer.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedUnfiledRecordContainer);
FolderData mockedUnfiledRecordFolder = mock(FolderData.class);
when(mockedUnfiledRecordFolder.getId()).thenReturn("folderId");
when(mockedUnfiledRecordFolder.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH + "/folder1");
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH + "/folder1")).thenReturn(mockedUnfiledRecordFolder);
when(mockedRestApiFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
when(mockedRestApiFactory.getUnfiledRecordFoldersAPI()).thenReturn(mockedUnfiledRecorFolderAPI);
// returns unfiled record container here, this is always available plus another unfiled record folder
when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, null, null, null, null, null, null, 0, 100)).thenReturn(Arrays.asList(mockedUnfiledRecordContainer, mockedUnfiledRecordFolder));
when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, null, null, null, null, null, null, 100, 100)).thenReturn(new ArrayList<FolderData>());
EventResult result = scheduleUnfiledRecordLoaders.processEvent(null, new StopWatch());
verify(mockedFileFolderService, times(2)).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
verify(mockedSessionService, times(4)).startSession(any(DBObject.class));
assertEquals(true, result.isSuccess());
assertEquals("Raised further " + (unfiledRecordsNumber) + " events and rescheduled self.", result.getData());
assertEquals(unfiledRecordsNumber + 1, result.getNextEvents().size());
for (int i = 0; i < unfiledRecordsNumber; i++) {
Event event = result.getNextEvents().get(0);
assertEquals(EVENT_LOAD_UNFILED_RECORD, event.getName());
DBObject dataObj = (DBObject) event.getData();
assertNotNull(dataObj);
assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
assertEquals(LOAD_UNFILED_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
}
assertEquals(EVENT_SCHEDULE_UNFILED_RECORD_LOADERS, result.getNextEvents().get(unfiledRecordsNumber).getName());
}
Aggregations