Search in sources :

Example 16 with FolderData

use of org.alfresco.bm.cm.FolderData 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());
}
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)

Example 17 with FolderData

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

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testSchedule4UnfiledRecordFoldersWithMaxActiveLoaders3.

@Test
public void testSchedule4UnfiledRecordFoldersWithMaxActiveLoaders3() throws Exception {
    int maxActiveLoaders = 3;
    int rootUnfiledRecordFolderNumber = 0;
    int unfiledRecordFolderChildrenNumber = 2;
    int unfiledRecordFolderDepth = 4;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFolderDepth);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderNumber(unfiledRecordFolderChildrenNumber);
    FolderData unfiledContainerFolder = mock(FolderData.class);
    when(unfiledContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(unfiledContainerFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(unfiledContainerFolder);
    FolderData mockedUnfiledRecordFolder1 = mock(FolderData.class);
    when(mockedUnfiledRecordFolder1.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordFolder1.getPath()).thenReturn("/a");
    FolderData mockedUnfiledRecordFolder2 = mock(FolderData.class);
    when(mockedUnfiledRecordFolder2.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordFolder2.getPath()).thenReturn("/b");
    List<FolderData> folders = Arrays.asList(mockedUnfiledRecordFolder1, mockedUnfiledRecordFolder2);
    when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, Long.valueOf(UNFILED_RECORD_CONTAINER_LEVEL + 1), Long.valueOf(scheduleUnfiledRecordFolderLoaders.getMaxLevel() - 1), 0L, Long.valueOf(unfiledRecordFolderChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFolderCount()).thenReturn(2L).thenReturn(0L);
    when(mockedUnfiledRecordFolder1.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFolderCount()).thenReturn(2L).thenReturn(0L);
    when(mockedUnfiledRecordFolder2.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
    verify(mockedSessionService, times(3)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 3 events and rescheduled self.", result.getData());
    assertEquals(4, result.getNextEvents().size());
    for (int i = 0; i < 3; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_UNFILED_RECORD_FOLDER, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_UNFILED_RECORD_FOLDER_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
        if (i < 2) {
            assertEquals("/a", (String) dataObj.get(FIELD_PATH));
        } else {
            assertEquals("/b", (String) dataObj.get(FIELD_PATH));
        }
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(3).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 18 with FolderData

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

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testScheduleRootUnfiledRecordFoldersWithDepth0.

@Test
public void testScheduleRootUnfiledRecordFoldersWithDepth0() throws Exception {
    int maxActiveLoaders = 8;
    int rootUnfiledRecordFolderNumber = 4;
    int unfiledRecordFoldersDepth = 0;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFoldersDepth);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    FolderData mockedUnfiledRecordContainerFolder = mock(FolderData.class);
    when(mockedUnfiledRecordContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainerFolder.getPath()).thenReturn("/a");
    List<FolderData> folders = Arrays.asList(mockedUnfiledRecordContainerFolder);
    when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, 4L, 4L, 0L, Long.valueOf(rootUnfiledRecordFolderNumber - 1), null, null, 0, 100)).thenReturn(folders);
    EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).createNewFolder(any(FolderData.class));
    verify(mockedSessionService, never()).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Loading completed.  Raising 'done' event.", result.getData());
    assertEquals(1, result.getNextEvents().size());
    assertEquals(EVENT_COMPLETE, result.getNextEvents().get(0).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 19 with FolderData

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

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testScheduleRootUnfiledRecordFolders.

@Test
public void testScheduleRootUnfiledRecordFolders() throws Exception {
    int maxActiveLoaders = 8;
    int rootUnfiledRecordFolderNumber = 4;
    int unfiledRecordFoldersDepth = 1;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFoldersDepth);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    FolderData unfiledContainerFolder = mock(FolderData.class);
    when(unfiledContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(unfiledContainerFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(unfiledContainerFolder);
    EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
    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 < 4; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_ROOT_UNFILED_RECORD_FOLDER, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(UNFILED_RECORD_CONTAINER_PATH, (String) dataObj.get(FIELD_PATH));
        assertEquals(LOAD_ROOT_UNFILED_RECORD_FOLDER_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(4).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 20 with FolderData

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

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testSchedule4RootUnfiledRecordFoldersWithMaxActiveLoaders3.

@Test
public void testSchedule4RootUnfiledRecordFoldersWithMaxActiveLoaders3() throws Exception {
    int maxActiveLoaders = 3;
    int rootUnfiledRecordFolderNumber = 4;
    int unfiledRecordFoldersDepth = 1;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFoldersDepth);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    FolderData unfiledContainerFolder = mock(FolderData.class);
    when(unfiledContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(unfiledContainerFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(unfiledContainerFolder);
    EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
    verify(mockedSessionService, times(3)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 3 events and rescheduled self.", result.getData());
    assertEquals(4, result.getNextEvents().size());
    for (int i = 0; i < 3; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_ROOT_UNFILED_RECORD_FOLDER, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(UNFILED_RECORD_CONTAINER_PATH, (String) dataObj.get(FIELD_PATH));
        assertEquals(LOAD_ROOT_UNFILED_RECORD_FOLDER_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(3).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)

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