use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.
the class ScheduleFilingUnfiledRecordsUnitTest method testFileRecordsWithExistentFilingFromPaths.
@Test
public void testFileRecordsWithExistentFilingFromPaths() throws Exception {
int maxActiveLoaders = 8;
String configuredPath1 = "/e1/e2/e3";
String entirePath1 = RECORD_CONTAINER_PATH + configuredPath1;
String paths = configuredPath1;
String recordId1 = "recordId1";
String recordParentPath1 = "recordParentPath1";
String recordParentFullPath1 = UNFILED_RECORD_CONTAINER_PATH + "/" + recordParentPath1;
String recordId2 = "recordId2";
String recordParentPath2 = "/recordParentPath2";
String recordParentFullPath2 = UNFILED_RECORD_CONTAINER_PATH + recordParentPath2;
String recordId3 = "recordId3";
String recordParentPath3 = "/recordParentPath3";
String recordParentFullPath3 = UNFILED_RECORD_CONTAINER_PATH + recordParentPath3;
String recordId4 = "recordId4";
String recordParentPath4 = "/recordParentPath4";
String recordParentFullPath4 = UNFILED_RECORD_CONTAINER_PATH + recordParentPath4;
String fileFromPathsStr = recordParentPath1 + "," + recordParentPath2 + "," + recordParentPath3 + "," + recordParentPath4;
scheduleFilingUnfiledRecords.setFileUnfiledRecords(true);
scheduleFilingUnfiledRecords.setMaxActiveLoaders(maxActiveLoaders);
scheduleFilingUnfiledRecords.setRecordFilingLimit("4");
scheduleFilingUnfiledRecords.setFileToRecordFolderPaths(paths);
scheduleFilingUnfiledRecords.setFileFromUnfiledPaths(fileFromPathsStr);
FolderData mockedRecordFolder1 = mock(FolderData.class);
when(mockedRecordFolder1.getId()).thenReturn("recordFolder1Id");
when(mockedRecordFolder1.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedRecordFolder1.getPath()).thenReturn(entirePath1);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, entirePath1)).thenReturn(mockedRecordFolder1);
RecordData mockedRecordData1 = mock(RecordData.class);
when(mockedRecordData1.getId()).thenReturn(recordId1);
when(mockedRecordData1.getParentPath()).thenReturn(recordParentFullPath1);
RecordData mockedRecordData2 = mock(RecordData.class);
when(mockedRecordData2.getId()).thenReturn(recordId2);
when(mockedRecordData2.getParentPath()).thenReturn(recordParentFullPath2);
RecordData mockedRecordData3 = mock(RecordData.class);
when(mockedRecordData3.getId()).thenReturn(recordId3);
when(mockedRecordData3.getParentPath()).thenReturn(recordParentFullPath3);
RecordData mockedRecordData4 = mock(RecordData.class);
when(mockedRecordData4.getId()).thenReturn(recordId4);
when(mockedRecordData4.getParentPath()).thenReturn(recordParentFullPath4);
when(mockedRecordService.getRecordsInPaths(ExecutionState.UNFILED_RECORD_DECLARED.name(), null, 0, 100)).thenReturn(Arrays.asList(mockedRecordData1, mockedRecordData2, mockedRecordData3, mockedRecordData4));
when(mockedRecordService.getRecordsInPaths(ExecutionState.UNFILED_RECORD_DECLARED.name(), null, 100, 100)).thenReturn(new ArrayList<>());
when(mockedRecordService.getRandomRecord(ExecutionState.UNFILED_RECORD_DECLARED.name(), Arrays.asList(recordParentFullPath1, recordParentFullPath2, recordParentFullPath3))).thenReturn(mockedRecordData1).thenReturn(mockedRecordData2).thenReturn(mockedRecordData3).thenReturn(null);
FolderData mockedUnfiledRecordFolder = mock(FolderData.class);
when(mockedUnfiledRecordFolder.getId()).thenReturn("folderId1");
when(mockedUnfiledRecordFolder.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordFolder.getPath()).thenReturn(recordParentFullPath1);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, recordParentFullPath1)).thenReturn(mockedUnfiledRecordFolder);
FolderData mockedUnfiledRecordFolder1 = mock(FolderData.class);
when(mockedUnfiledRecordFolder1.getId()).thenReturn("newfolderId2");
when(mockedUnfiledRecordFolder1.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordFolder1.getPath()).thenReturn(recordParentFullPath2);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, recordParentFullPath2)).thenReturn(mockedUnfiledRecordFolder1);
FolderData mockedUnfiledRecordFolder2 = mock(FolderData.class);
when(mockedUnfiledRecordFolder2.getId()).thenReturn("newfolderId3");
when(mockedUnfiledRecordFolder2.getContext()).thenReturn(UNFILED_CONTEXT);
when(mockedUnfiledRecordFolder2.getPath()).thenReturn(recordParentFullPath3);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, recordParentFullPath3)).thenReturn(mockedUnfiledRecordFolder2);
EventResult result = scheduleFilingUnfiledRecords.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(mockedRecordService, times(3)).updateRecord(any(RecordData.class));
assertEquals(true, result.isSuccess());
verify(mockedSessionService, times(3)).startSession(any(DBObject.class));
assertEquals("Raised further " + (3) + " events and rescheduled self.", result.getData());
assertEquals(4, result.getNextEvents().size());
List<String> listOfIds = Arrays.asList(recordId1, recordId2, recordId3, recordId4);
for (int i = 0; i < 3; i++) {
Event event = result.getNextEvents().get(i);
assertEquals(TEST_EVENT_FILE_UNFILED_RECORDS, event.getName());
DBObject dataObj = (DBObject) event.getData();
assertNotNull(dataObj);
assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
assertEquals(FILE_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
assertEquals(listOfIds.get(i), dataObj.get(FIELD_RECORD_ID));
}
assertEquals(TEST_EVENT_RESCHEDULE_SELF, result.getNextEvents().get(3).getName());
}
use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.
the class ScheduleFilingUnfiledRecordsUnitTest method testFileRecordsWithLessRecordsThanRequestedInDb.
@Test
public void testFileRecordsWithLessRecordsThanRequestedInDb() throws Exception {
int maxActiveLoaders = 8;
String recordId1 = "recordId1";
String recordId2 = "recordId2";
String configuredPath1 = "/e1/e2/e3";
String entirePath1 = RECORD_CONTAINER_PATH + configuredPath1;
String paths = configuredPath1;
scheduleFilingUnfiledRecords.setFileUnfiledRecords(true);
scheduleFilingUnfiledRecords.setMaxActiveLoaders(maxActiveLoaders);
scheduleFilingUnfiledRecords.setRecordFilingLimit("4");
scheduleFilingUnfiledRecords.setFileToRecordFolderPaths(paths);
FolderData mockedRecordFolder1 = mock(FolderData.class);
when(mockedRecordFolder1.getId()).thenReturn("recordFolder1Id");
when(mockedRecordFolder1.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedRecordFolder1.getPath()).thenReturn(entirePath1);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, entirePath1)).thenReturn(mockedRecordFolder1);
RecordData mockedRecordData1 = mock(RecordData.class);
when(mockedRecordData1.getId()).thenReturn(recordId1);
RecordData mockedRecordData2 = mock(RecordData.class);
when(mockedRecordData2.getId()).thenReturn(recordId2);
when(mockedRecordService.getRandomRecord(ExecutionState.UNFILED_RECORD_DECLARED.name(), null)).thenReturn(mockedRecordData1).thenReturn(mockedRecordData2).thenReturn(null);
EventResult result = scheduleFilingUnfiledRecords.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));
assertEquals(true, result.isSuccess());
verify(mockedSessionService, times(2)).startSession(any(DBObject.class));
assertEquals("Raised further " + (2) + " events and rescheduled self.", result.getData());
assertEquals(3, result.getNextEvents().size());
List<String> listOfIds = Arrays.asList(recordId1, recordId2);
for (int i = 0; i < 2; i++) {
Event event = result.getNextEvents().get(i);
assertEquals(TEST_EVENT_FILE_UNFILED_RECORDS, event.getName());
DBObject dataObj = (DBObject) event.getData();
assertNotNull(dataObj);
assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
assertEquals(FILE_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
assertEquals(listOfIds.get(i), dataObj.get(FIELD_RECORD_ID));
}
assertEquals(TEST_EVENT_RESCHEDULE_SELF, result.getNextEvents().get(2).getName());
}
use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsFromDocumentLibrary.
@Test
public void testDeclareRecordsFromDocumentLibrary() throws Exception {
String numberOfRecordsToDeclare = "2";
int maxActiveLoaders = 8;
String siteId = "testSiteId";
String documentLibraryId = UUID.randomUUID().toString();
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
Site mockedSite = mock(Site.class);
when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK));
SiteData mockedSiteData = mock(SiteData.class);
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
when(mockedPagination.isHasMoreItems()).thenReturn(false);
RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
when(mockedCollection.getPagination()).thenReturn(mockedPagination);
String childFileId1 = "childFileId1";
RestNodeModel mockedOnModel1 = mock(RestNodeModel.class);
when(mockedOnModel1.getIsFile()).thenReturn(true);
when(mockedOnModel1.getId()).thenReturn(childFileId1);
when(mockedOnModel1.getName()).thenReturn("fileName1");
RestNodeModel mockedFile1 = mock(RestNodeModel.class);
when(mockedFile1.onModel()).thenReturn(mockedOnModel1);
String childFileId2 = "childFileId2";
RestNodeModel mockedOnModel2 = mock(RestNodeModel.class);
when(mockedOnModel2.getIsFile()).thenReturn(true);
when(mockedOnModel2.getId()).thenReturn(childFileId2);
when(mockedOnModel2.getName()).thenReturn("fileName2");
RestNodeModel mockedFile2 = mock(RestNodeModel.class);
when(mockedFile2.onModel()).thenReturn(mockedOnModel2);
when(mockedCollection.getEntries()).thenReturn(Arrays.asList(mockedFile1, mockedFile2));
Node mockedNode = mock(Node.class);
when(mockedNode.listChildren()).thenReturn(mockedCollection);
RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
verify(mockedSite, never()).createSite();
verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
String template = "Preparing files to declare: \nSheduled file to be declared as record: {0}. Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
assertEquals(MessageFormat.format(template, childFileId1, childFileId2, 2), result.getData());
assertEquals(3, result.getNextEvents().size());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(1).getName());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(2).getName());
}
use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteDoesNotExistsAndLoadedInDb.
@Test
public void testDeclareRecordsColabSiteDoesNotExistsAndLoadedInDb() throws Exception {
String numberOfRecordsToDeclare = "1";
int maxActiveLoaders = 8;
String siteId = "testSiteId";
String documentLibraryId = UUID.randomUUID().toString();
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
Site mockedSite = mock(Site.class);
when(mockedSite.getSite()).thenReturn(null);
when(mockedSite.createSite()).thenReturn(mockedRestSiteModel);
when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_NOT_FOUND));
SiteData mockedSiteData = mock(SiteData.class);
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
when(mockedPagination.isHasMoreItems()).thenReturn(false);
RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
when(mockedCollection.getPagination()).thenReturn(mockedPagination);
Node mockedNode = mock(Node.class);
when(mockedNode.listChildren()).thenReturn(mockedCollection);
RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
// for creating files
NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
NodeDetail mockedFile = mock(NodeDetail.class);
String fileID = UUID.randomUUID().toString();
when(mockedFile.getId()).thenReturn(fileID);
when(mockedFile.getName()).thenReturn("fileName");
when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
verify(mockedSite, times(1)).createSite();
verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
String template = "Preparing files to declare: \nCreated file {0}.Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
assertEquals(MessageFormat.format(template, fileID, fileID, 1), result.getData());
assertEquals(2, result.getNextEvents().size());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(1).getName());
}
use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareAllExistingFiles.
/**
* Given the collaboration site exists and contains undeclared files with the following structure
* - documentLibrary
* - file1
* - file2
* - folder
* - file3
* - file4
* When running the scheduler with numberOfRecordsToDeclare=0
* Then all existing files should be scheduled for declaring
*
* @throws Exception
*/
@Test
public void testDeclareAllExistingFiles() throws Exception {
String file1Id = "file1_id";
String file2Id = "file2_id";
String folderId = "folder_id";
String file3Id = "file3_id";
String file4Id = "file4_id";
/*
* Given
*/
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(8);
scheduleInPlaceRecordLoaders.setCollabSiteId(DEFAULT_COLLABORATION_SITE_ID);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit("0");
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
// mock the collaboration site
RestCoreAPI mockedCoreApi = mockCoreApi();
Site collabSite = mockSitesEndpoint(mockedCoreApi, DEFAULT_COLLABORATION_SITE_ID);
String documentLibrary = mockExistingCollaborationSite(collabSite, DEFAULT_COLLABORATION_SITE_ID, true);
// mock listing the document library
Node doclibNode = mockNodesEndpoint(mockedCoreApi, documentLibrary);
List<RestNodeModel> level0Nodes = Arrays.asList(mockNodeModel(file1Id, true), mockNodeModel(file2Id, true), mockNodeModel(folderId, false));
mockListChildren(doclibNode, false, level0Nodes);
// mock listing the folder
Node folderNode = mockNodesEndpoint(mockedCoreApi, folderId);
List<RestNodeModel> level1Nodes = Arrays.asList(mockNodeModel(file3Id, true), mockNodeModel(file4Id, true));
mockListChildren(folderNode, false, level1Nodes);
/*
* When
*/
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
/*
* Then
*/
assertEquals(true, result.isSuccess());
List<String> scheduledFiles = Arrays.asList(file1Id, file2Id, file3Id, file4Id);
validateScheduleFilesOutputMessage(new ArrayList<String>(), scheduledFiles, (String) result.getData());
validateFiredEvents(true, scheduledFiles, result.getNextEvents());
}
Aggregations