use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class ScheduleFilingUnfiledRecordsUnitTest method testFileRecordsWithConfiguredInexistentFilingFromPaths.
@Test
public void testFileRecordsWithConfiguredInexistentFilingFromPaths() throws Exception {
int maxActiveLoaders = 3;
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 = "/inexisistingPath1,/inexisistingPath2,/inexisistingPath3";
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, recordParentFullPath4))).thenReturn(mockedRecordData1).thenReturn(mockedRecordData2).thenReturn(mockedRecordData3).thenReturn(mockedRecordData4);
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(maxActiveLoaders)).updateRecord(any(RecordData.class));
assertEquals(true, result.isSuccess());
verify(mockedSessionService, times(maxActiveLoaders)).startSession(any(DBObject.class));
assertEquals("Raised further " + (maxActiveLoaders) + " events and rescheduled self.", result.getData());
assertEquals(maxActiveLoaders + 1, result.getNextEvents().size());
List<String> listOfIds = Arrays.asList(recordId1, recordId2, recordId3, recordId4);
for (int i = 0; i < maxActiveLoaders; 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(maxActiveLoaders).getName());
}
use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteExistsNotLoadedInDb.
@Test
public void testDeclareRecordsColabSiteExistsNotLoadedInDb() throws Exception {
String numberOfRecordsToDeclare = "1";
int maxActiveLoaders = 8;
String siteId = "testSiteId";
String documentLibraryId = UUID.randomUUID().toString();
String siteTitle = "someTitle";
String guid = UUID.randomUUID().toString();
String description = "someDescription";
String preset = "somePreset";
Visibility visibility = Visibility.PUBLIC;
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
when(mockedRestSiteModel.getGuid()).thenReturn(guid);
when(mockedRestSiteModel.getDescription()).thenReturn(description);
when(mockedRestSiteModel.getPreset()).thenReturn(preset);
when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);
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));
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
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);
when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPI);
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(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
NodeDetail mockedFile = mock(NodeDetail.class);
String fileID = UUID.randomUUID().toString();
when(mockedFile.getId()).thenReturn(fileID);
when(mockedFile.getName()).thenReturn("recordName");
when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
verify(mockedSite, never()).createSite();
verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
assertEquals(MessageFormat.format(template, siteId.toLowerCase(), 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.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb.
@Test
public void testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb() throws Exception {
String numberOfRecordsToDeclare = "1";
int maxActiveLoaders = 8;
String siteId = "testSiteId";
String documentLibraryId = UUID.randomUUID().toString();
String siteTitle = "someTitle";
String guid = UUID.randomUUID().toString();
String description = "someDescription";
String preset = "somePreset";
Visibility visibility = Visibility.PUBLIC;
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
when(mockedRestSiteModel.getGuid()).thenReturn(guid);
when(mockedRestSiteModel.getDescription()).thenReturn(description);
when(mockedRestSiteModel.getPreset()).thenReturn(preset);
when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);
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));
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
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, times(1)).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
assertEquals(MessageFormat.format(template, siteId.toLowerCase(), 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.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testWithEnabledFalse.
@Test
public void testWithEnabledFalse() throws Exception {
scheduleInPlaceRecordLoaders.setEnabled(false);
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
assertEquals(true, result.isSuccess());
assertEquals(ScheduleInPlaceRecordLoaders.DECLARING_NOT_WANTED_MSG, result.getData());
assertEquals(1, result.getNextEvents().size());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameComplete(), result.getNextEvents().get(0).getName());
}
use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteExistsAndLoadedInDb.
/**
* Given the collaboration site already exists and is loaded in the database
* When running the scheduler with numberOfRecordsToDeclare=1
* Then we don't attempt to load or create the site and 1 file is created and scheduled to be declared
*
* @throws Exception
*/
@Test
public void testDeclareRecordsColabSiteExistsAndLoadedInDb() throws Exception {
String fileID = UUID.randomUUID().toString();
/*
* Given
*/
String numberOfRecordsToDeclare = "1";
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(DEFAULT_MAX_ACTIVE_LOADERS);
scheduleInPlaceRecordLoaders.setCollabSiteId(DEFAULT_COLLABORATION_SITE_ID);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestCoreAPI mockedRestCoreAPI = mockCoreApi();
Site mockedSitesEndpoint = mockSitesEndpoint(mockedRestCoreAPI, DEFAULT_COLLABORATION_SITE_ID);
String documentLibraryId = mockExistingCollaborationSite(mockedSitesEndpoint, DEFAULT_COLLABORATION_SITE_ID, true);
Node doclibNodesEndpoint = mockNodesEndpoint(mockedRestCoreAPI, documentLibraryId);
mockListChildren(doclibNodesEndpoint, false, new ArrayList<RestNodeModel>());
// mock node builder
NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
when(doclibNodesEndpoint.defineNodes()).thenReturn(mockedNodeBuilder);
// mock create folder helper method
NodeDetail mockedAutoGeneratedFolder = mock(NodeDetail.class);
when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedAutoGeneratedFolder);
// mock create file
NodeDetail mockedFile = mock(NodeDetail.class);
when(mockedFile.getId()).thenReturn(fileID);
when(mockedFile.getName()).thenReturn("fileName");
when(mockedAutoGeneratedFolder.file("recordToBe")).thenReturn(mockedFile);
/*
* When
*/
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
/*
* Then
*/
verify(mockedSitesEndpoint, never()).createSite();
verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
List<String> createdAndScheduledFiles = Arrays.asList(fileID);
validateScheduleFilesOutputMessage(createdAndScheduledFiles, createdAndScheduledFiles, (String) result.getData());
validateFiredEvents(true, Arrays.asList(fileID), result.getNextEvents());
}
Aggregations