use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithExistentPreconfiguredPaths.
@Test
public void testUploadRecordsWithExistentPreconfiguredPaths() throws Exception {
int maxActiveLoaders = 8;
int unfiledRecordsNumber = 4;
String configuredPath1 = "e1/e2/e3";
String configuredPath2 = "/e1/e2/e4";
String entirePath1 = UNFILED_RECORD_CONTAINER_PATH + configuredPath1;
String entirePath2 = UNFILED_RECORD_CONTAINER_PATH + configuredPath2;
String paths = configuredPath1 + "," + configuredPath2;
scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
scheduleUnfiledRecordLoaders.setUnfiledRecordFolderPaths(paths);
FolderData mockedUnfiledRecordFolder = mock(FolderData.class);
when(mockedUnfiledRecordFolder.getId()).thenReturn("folderId1");
when(mockedUnfiledRecordFolder.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordFolder.getPath()).thenReturn(entirePath1);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, entirePath1)).thenReturn(mockedUnfiledRecordFolder);
FolderData mockedUnfiledRecordFolder1 = mock(FolderData.class);
when(mockedUnfiledRecordFolder1.getId()).thenReturn("newfolderId2");
when(mockedUnfiledRecordFolder1.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordFolder1.getPath()).thenReturn(entirePath2);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, entirePath2)).thenReturn(mockedUnfiledRecordFolder1);
when(mockedRestApiFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
when(mockedRestApiFactory.getUnfiledRecordFoldersAPI()).thenReturn(mockedUnfiledRecorFolderAPI);
EventResult result = scheduleUnfiledRecordLoaders.processEvent(null, new StopWatch());
verify(mockedFileFolderService, never()).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 4 events and rescheduled self.", result.getData());
assertEquals(5, 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(4).getName());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadRecordFolderUnitTest method testLoadRecordFolderOperation.
@Test
public void testLoadRecordFolderOperation() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_RECORD_FOLDER_LOADED);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn(FILEPLAN_CONTEXT);
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_RECORD_FOLDER_OPERATION);
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, "/aPath")).thenReturn(mockedFolder);
loadSingleComponent.setFileFolderService(mockedFileFolderService);
when(mockedEvent.getSessionId()).thenReturn("someId");
when(mockedRestApiFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
when(mockedRestApiFactory.getRecordCategoryAPI(any(UserModel.class))).thenReturn(mockedRecordCategoryAPI);
RecordCategory mockedFilePlanComponent = mock(RecordCategory.class);
when(mockedFilePlanComponent.getId()).thenReturn("folderId");
when(mockedRecordCategoryAPI.getRecordCategory("folderId")).thenReturn(mockedFilePlanComponent);
RecordCategoryChild mockedChildFilePlanComponent = mock(RecordCategoryChild.class);
when(mockedChildFilePlanComponent.getId()).thenReturn(UUID.randomUUID().toString());
when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("folderId"))).thenReturn(mockedChildFilePlanComponent);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, times(1)).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, times(1)).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
assertEquals(true, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertEquals("Created 1 record folder.", 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_RECORD_FOLDER_LOADED, event.getName());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadRootCategoryUnitTest method testLoadRootCategoryOperationWithExceptionOnRestApi.
@Test
public void testLoadRootCategoryOperationWithExceptionOnRestApi() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_ROOT_RECORD_CATEGORY_LOADED);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn(FILEPLAN_CONTEXT);
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_ROOT_CATEGORY_OPERATION);
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, "/aPath")).thenReturn(mockedFolder);
loadSingleComponent.setFileFolderService(mockedFileFolderService);
when(mockedEvent.getSessionId()).thenReturn("someId");
when(mockedRestApiFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
Mockito.doThrow(new Exception("someError")).when(mockedFilePlanAPI).createRootRecordCategory(any(RecordCategory.class), any(String.class));
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, never()).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, never()).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
assertEquals(false, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertNotNull(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 LoadRootCategoryUnitTest method testLoadRootCategoryOperation.
@Test
public void testLoadRootCategoryOperation() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_ROOT_RECORD_CATEGORY_LOADED);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn(FILEPLAN_CONTEXT);
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_ROOT_CATEGORY_OPERATION);
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, "/aPath")).thenReturn(mockedFolder);
loadSingleComponent.setFileFolderService(mockedFileFolderService);
when(mockedEvent.getSessionId()).thenReturn("someId");
when(mockedRestApiFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
when(mockedRestApiFactory.getRecordCategoryAPI(any(UserModel.class))).thenReturn(mockedRecordCategoryAPI);
FilePlan mockedFilePlanComponent = mock(FilePlan.class);
when(mockedFilePlanComponent.getId()).thenReturn("folderId");
when(mockedFilePlanAPI.getFilePlan("folderId")).thenReturn(mockedFilePlanComponent);
RecordCategory mockedChildFilePlanComponent = mock(RecordCategory.class);
when(mockedChildFilePlanComponent.getId()).thenReturn(UUID.randomUUID().toString());
when(mockedFilePlanAPI.createRootRecordCategory(any(RecordCategory.class), eq("folderId"))).thenReturn(mockedChildFilePlanComponent);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, times(1)).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, times(1)).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
assertEquals(true, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertEquals("Created 1 root category.", 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_ROOT_RECORD_CATEGORY_LOADED, event.getName());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledContainerWithNoFileException.
@Test
public void testLoadUnfiledRecordOperationInUnfiledContainerWithNoFileException() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
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(LOAD_UNFILED_RECORD_OPERATION);
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");
when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
when(mockedRestApiFactory.getUnfiledRecordFoldersAPI(any(UserModel.class))).thenReturn(mockedUnfiledRecordFolderAPI);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder);
UnfiledContainer mockedFilePlanComponent = mock(UnfiledContainer.class);
when(mockedUnfiledContainerAPI.getUnfiledContainer("folderId")).thenReturn(mockedFilePlanComponent);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, never()).deleteFolder(mockedFolder.getContext(), mockedFolder.getPath() + "/locked", false);
verify(mockedTestFileService, times(1)).getFile();
verify(mockedUnfiledContainerAPI, never()).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
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("No test files exist for upload: mockedTestFileService", data.get("error"));
assertEquals("aUser", data.get("username"));
assertEquals(mockedFolder.getPath(), data.get("path"));
assertNotNull(data.get("stack"));
assertEquals(0, result.getNextEvents().size());
}
Aggregations