use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class ScheduleRecordLoadersUnitTest method testUploadRecordsInNonExistentOnePathElCategory.
@Test
public void testUploadRecordsInNonExistentOnePathElCategory() throws Exception {
int maxActiveLoaders = 8;
int recordsNumber = 4;
String configuredPath1 = "/e1";
String paths = configuredPath1;
scheduleRecordLoaders.setUploadRecords(true);
scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleRecordLoaders.setRecordsNumber(recordsNumber);
scheduleRecordLoaders.setRecordFolderPaths(paths);
// file plan should be always there
FolderData mockedFilePlanContainer = mock(FolderData.class);
when(mockedFilePlanContainer.getId()).thenReturn("filePlanId");
when(mockedFilePlanContainer.getContext()).thenReturn(FILEPLAN_CONTEXT);
when(mockedFilePlanContainer.getPath()).thenReturn(RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(mockedFilePlanContainer);
// 2 existent record folders
String path1 = RECORD_CONTAINER_PATH + "/categ1/folder1";
FolderData mockedRecordFolder1 = mock(FolderData.class);
when(mockedRecordFolder1.getId()).thenReturn("recordFolder1Id");
when(mockedRecordFolder1.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedRecordFolder1.getPath()).thenReturn(path1);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path1)).thenReturn(mockedRecordFolder1);
String path2 = RECORD_CONTAINER_PATH + "/categ2/folder2";
FolderData mockedRecordFolder2 = mock(FolderData.class);
when(mockedRecordFolder2.getId()).thenReturn("recordFolder2Id");
when(mockedRecordFolder2.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedRecordFolder2.getPath()).thenReturn(path2);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path2)).thenReturn(mockedRecordFolder2);
// returns available record folders
when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 0, 100)).thenReturn(Arrays.asList(mockedRecordFolder1, mockedRecordFolder2));
when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 100, 100)).thenReturn(new ArrayList<FolderData>());
when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
FilePlan mockedFilePlan = mock(FilePlan.class);
when(mockedFilePlan.getId()).thenReturn("filePlanId");
when(mockedFilePlanAPI.getFilePlan("filePlanId")).thenReturn(mockedFilePlan);
String e1Path = RECORD_CONTAINER_PATH + "/e1";
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e1Path)).thenReturn(null);
EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
verify(mockedFileFolderService, never()).getFolder(any(String.class));
verify(mockedFileFolderService, never()).incrementFolderCount(any(String.class), any(String.class), eq(1L));
verify(mockedFileFolderService, never()).createNewFolder(any(String.class), any(String.class), any(String.class));
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));
assertEquals(true, result.isSuccess());
verify(mockedSessionService, times(recordsNumber)).startSession(any(DBObject.class));
assertEquals("Raised further " + (recordsNumber) + " events and rescheduled self.", result.getData());
assertEquals(recordsNumber + 1, result.getNextEvents().size());
for (int i = 0; i < recordsNumber; i++) {
Event event = result.getNextEvents().get(i);
assertEquals(EVENT_LOAD_RECORD, event.getName());
DBObject dataObj = (DBObject) event.getData();
assertNotNull(dataObj);
assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
}
assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(recordsNumber).getName());
}
use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class CreateRMSiteUnitTest method testLoadingInDbExistentRmSite.
@Test
public void testLoadingInDbExistentRmSite() throws Exception {
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
RMSiteAPI mockedRMSiteAPI = mock(RMSiteAPI.class);
RMSite mockedRMSite = mock(RMSite.class);
FilePlanAPI mockedFilePlanAPI = mock(FilePlanAPI.class);
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
TransferContainerAPI mockedTransferContainerAPI = mock(TransferContainerAPI.class);
FilePlan mockedFilePlan = mock(FilePlan.class);
UnfiledContainer mockedUnfiledRecordsContainer = mock(UnfiledContainer.class);
TransferContainer mockedTransfers = mock(TransferContainer.class);
String siteId = randomUUID().toString();
String siteManager = randomUUID().toString();
String password = "password";
when(mockedData.get(FIELD_SITE_ID)).thenReturn(siteId);
when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn(siteManager);
when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn(password);
when(mockedData.get(FIELD_ONLY_DB_LOAD)).thenReturn(true);
when(mockedEvent.getData()).thenReturn(mockedData);
when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
String guuid = randomUUID().toString();
when(mockedRMSite.getGuid()).thenReturn(guuid);
when(mockedRMSiteAPI.getSite()).thenReturn(mockedRMSite);
when(mockedRestAPIFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
when(mockedFilePlanAPI.getFilePlan(FILE_PLAN_ALIAS)).thenReturn(mockedFilePlan);
when(mockedFilePlan.getId()).thenReturn(randomUUID().toString());
when(mockedRestAPIFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
when(mockedUnfiledContainerAPI.getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledRecordsContainer);
when(mockedUnfiledRecordsContainer.getId()).thenReturn(randomUUID().toString());
when(mockedRestAPIFactory.getTransferContainerAPI(any(UserModel.class))).thenReturn(mockedTransferContainerAPI);
when(mockedTransferContainerAPI.getTransferContainer(TRANSFERS_ALIAS)).thenReturn(mockedTransfers);
when(mockedTransfers.getId()).thenReturn(randomUUID().toString());
EventResult result = createRMSite.processEvent(mockedEvent);
verify(mockedRMSiteAPI, never()).createRMSite(any(RMSite.class));
verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
verify(mockedSiteDataService, times(1)).addSiteMember(any(SiteMemberData.class));
verify(mockedFileFolderService, times(3)).createNewFolder(any(FolderData.class));
assertEquals(true, result.isSuccess());
assertEquals("RM site already exists, just loading it in the DB.", (String) result.getData());
List<Event> events = result.getNextEvents();
assertEquals(1, events.size());
Event event = events.get(0);
assertEquals(DEFAULT_EVENT_NAME_SITE_CREATED, event.getName());
DBObject data = (DBObject) event.getData();
assertEquals(null, data);
}
Aggregations