Search in sources :

Example 61 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredSinglePath.

@Test
public void testUploadRecordsWithNotExistentPreconfiguredSinglePath() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    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);
    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);
    // e1 root category
    RecordCategory mockedE1FilePlanComponent = mock(RecordCategory.class);
    when(mockedE1FilePlanComponent.getId()).thenReturn("e1Id");
    when(mockedRecordCategoryAPI.getRecordCategory("e1Id")).thenReturn(mockedE1FilePlanComponent);
    when(mockedFilePlanAPI.createRootRecordCategory(any(RecordCategory.class), eq("filePlanId"))).thenReturn(mockedE1FilePlanComponent);
    String e1Path = RECORD_CONTAINER_PATH + "/e1";
    FolderData mockedE1 = mock(FolderData.class);
    when(mockedE1.getId()).thenReturn("e1Id");
    when(mockedE1.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedE1.getPath()).thenReturn(e1Path);
    when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
    when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
    // e2 child category
    RecordCategory mockedE2childRecordCategory = mock(RecordCategory.class);
    when(mockedE2childRecordCategory.getId()).thenReturn("e2Id");
    RecordCategoryChild mockedE2RecordCategoryChild = mock(RecordCategoryChild.class);
    when(mockedE2RecordCategoryChild.getId()).thenReturn("e2Id");
    when(mockedRecordCategoryAPI.getRecordCategory("e2Id")).thenReturn(mockedE2childRecordCategory);
    when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e1Id"))).thenReturn(mockedE2RecordCategoryChild);
    String e2Path = RECORD_CONTAINER_PATH + "/e1/e2";
    FolderData mockedE2 = mock(FolderData.class);
    when(mockedE2.getId()).thenReturn("e2Id");
    when(mockedE2.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedE2.getPath()).thenReturn(e2Path);
    when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
    when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
    // e3 record folder
    RecordCategoryChild mockedE3RecordFolder = mock(RecordCategoryChild.class);
    when(mockedE3RecordFolder.getId()).thenReturn("e3Id");
    String e3Path = RECORD_CONTAINER_PATH + "/e1/e2/e3";
    FolderData mockedE3 = mock(FolderData.class);
    when(mockedE3.getId()).thenReturn("e3Id");
    when(mockedE3.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedE3.getPath()).thenReturn(e3Path);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
    when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
    when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e2Id"))).thenReturn(mockedE3RecordFolder);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
    EventResult result = scheduleRecordLoaders.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(mockedFileFolderService, times(3)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(3)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
    verify(mockedFileFolderService, times(3)).getFolder(any(String.class));
    verify(mockedSessionService, times(recordsNumber)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    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());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) RecordCategoryChild(org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) RecordCategory(org.alfresco.rest.rm.community.model.recordcategory.RecordCategory) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 62 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithExistentPreconfiguredPaths.

@Test
public void testUploadRecordsWithExistentPreconfiguredPaths() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String configuredPath2 = "/e1/e2/e4";
    String entirePath1 = RECORD_CONTAINER_PATH + configuredPath1;
    String entirePath2 = RECORD_CONTAINER_PATH + configuredPath2;
    String paths = configuredPath1 + "," + configuredPath2;
    scheduleRecordLoaders.setUploadRecords(true);
    scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleRecordLoaders.setRecordsNumber(recordsNumber);
    scheduleRecordLoaders.setRecordFolderPaths(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);
    FolderData mockedRecordFolder2 = mock(FolderData.class);
    when(mockedRecordFolder2.getId()).thenReturn("recordFolder2Id");
    when(mockedRecordFolder2.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder2.getPath()).thenReturn(entirePath2);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, entirePath2)).thenReturn(mockedRecordFolder2);
    when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
    when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
    EventResult result = scheduleRecordLoaders.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(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());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 63 with FolderData

use of org.alfresco.bm.cm.FolderData 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());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 64 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithSuccess.

@Test
public void testDeclareAsRecordWithSuccess() throws Exception {
    String fileId = "testFileId";
    String username = "testUserName";
    String password = "testPassword";
    long delay = 10L;
    declareInPlaceRecords.setDeclareInPlaceRecordDelay(delay);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_ID)).thenReturn(fileId);
    when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
    when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
    when(mockedEvent.getData()).thenReturn(mockedData);
    RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
    when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
    FilesAPI mockedFilesAPI = mock(FilesAPI.class);
    when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
    Record record = mock(Record.class);
    when(record.getName()).thenReturn("newRecordName");
    when(record.getParentId()).thenReturn("unfiledContainerID");
    when(mockedFilesAPI.declareAsRecord(fileId)).thenReturn(record);
    RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
    when(mockedRmRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.CREATED.value()));
    when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
    UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
    when(mockedUnfiledContainer.getId()).thenReturn("unfiledContainerID");
    UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
    when(mockedUnfiledContainerAPI.getUnfiledContainer(FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledContainer);
    when(mockedRestAPIFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
    FolderData mockedParentFolder = mock(FolderData.class);
    when(mockedParentFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder("unfiledContainerID")).thenReturn(mockedParentFolder);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
    EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
    assertEquals(true, result.isSuccess());
    assertEquals("Declaring file as record: \nsuccess", result.getData());
    assertEquals(1, result.getNextEvents().size());
    assertEquals(declareInPlaceRecords.getEventNameInPlaceRecordsDeclared(), result.getNextEvents().get(0).getName());
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) UserModel(org.alfresco.utility.model.UserModel) UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) FilesAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) Record(org.alfresco.rest.rm.community.model.record.Record) RMRestWrapper(org.alfresco.rest.core.RMRestWrapper) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI) Test(org.junit.Test)

Example 65 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class ScheduleFilingUnfiledRecordsUnitTest method testFileRecordsFromUnfiledRecordContainer.

@Test
public void testFileRecordsFromUnfiledRecordContainer() throws Exception {
    int maxActiveLoaders = 8;
    String configuredPath1 = "/e1/e2/e3";
    String entirePath1 = RECORD_CONTAINER_PATH + configuredPath1;
    String paths = configuredPath1;
    String recordId1 = "recordId1";
    String recordParentPath1 = "/";
    String recordParentFullPath1 = UNFILED_RECORD_CONTAINER_PATH;
    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;
    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(recordParentFullPath2, recordParentFullPath3, recordParentFullPath4, recordParentFullPath1))).thenReturn(mockedRecordData1).thenReturn(mockedRecordData2).thenReturn(mockedRecordData3).thenReturn(mockedRecordData4).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);
    FolderData mockedUnfiledRecordFolder3 = mock(FolderData.class);
    when(mockedUnfiledRecordFolder3.getId()).thenReturn("newfolderId4");
    when(mockedUnfiledRecordFolder3.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordFolder3.getPath()).thenReturn(recordParentFullPath4);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, recordParentFullPath4)).thenReturn(mockedUnfiledRecordFolder3);
    when(mockedFileFolderService.getChildFolders(UNFILED_CONTEXT, recordParentFullPath1, 0, 100)).thenReturn(Arrays.asList(mockedUnfiledRecordFolder1, mockedUnfiledRecordFolder2, mockedUnfiledRecordFolder3)).thenReturn(new ArrayList<>());
    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(4)).updateRecord(any(RecordData.class));
    assertEquals(true, result.isSuccess());
    verify(mockedSessionService, times(4)).startSession(any(DBObject.class));
    assertEquals("Raised further " + (4) + " events and rescheduled self.", result.getData());
    assertEquals(5, result.getNextEvents().size());
    List<String> listOfIds = Arrays.asList(recordId1, recordId2, recordId3, recordId4);
    for (int i = 0; i < 4; 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(4).getName());
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

FolderData (org.alfresco.bm.cm.FolderData)94 DBObject (com.mongodb.DBObject)76 Event (org.alfresco.bm.event.Event)70 Test (org.junit.Test)69 EventResult (org.alfresco.bm.event.EventResult)68 StopWatch (org.apache.commons.lang3.time.StopWatch)68 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)21 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)14 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)10 File (java.io.File)9 RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)8 ArrayList (java.util.ArrayList)7 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)7 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)7 LinkedHashSet (java.util.LinkedHashSet)5 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)5 Record (org.alfresco.rest.rm.community.model.record.Record)4 RecordFolder (org.alfresco.rest.rm.community.model.recordfolder.RecordFolder)3 RecordCategoryAPI (org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI)2