Search in sources :

Example 76 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleFilePlanLoadersUnitTest method testSchedule4RootCategoriesWithMaxActiveLoaders3.

@Test
public void testSchedule4RootCategoriesWithMaxActiveLoaders3() throws Exception {
    int maxActiveLoaders = 3;
    int rootCategoriesNumber = 4;
    int categoryStructureDepth = 1;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    FolderData mockedFilePlanFolder = mock(FolderData.class);
    when(mockedFilePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(mockedFilePlanFolder.getPath()).thenReturn("/a");
    List<FolderData> folders = Arrays.asList(mockedFilePlanFolder);
    when(mockedFileFolderService.getFoldersByCounts(FILEPLAN_CONTEXT, 3L, 3L, 0L, Long.valueOf(rootCategoriesNumber - 1), null, null, 0, 100)).thenReturn(folders);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    EventResult result = scheduleFilePlanLoaders.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_RECORD_CATEGORY, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(FILEPLAN_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(RECORD_CONTAINER_PATH, (String) dataObj.get(FIELD_PATH));
        assertEquals(LOAD_ROOT_CATEGORY_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)

Example 77 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleFilePlanLoadersUnitTest method testScheduleChildrenRecordFoldersWithoutMix.

@Test
public void testScheduleChildrenRecordFoldersWithoutMix() throws Exception {
    int maxActiveLoaders = 8;
    int rootCategoriesNumber = 0;
    int categoriesChildrenNumber = 0;
    int foldersChildrenNumber = 2;
    int categoryStructureDepth = 4;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    scheduleFilePlanLoaders.setChildCategNumber(categoriesChildrenNumber);
    scheduleFilePlanLoaders.setFolderNumber(foldersChildrenNumber);
    scheduleFilePlanLoaders.setFolderCategoryMix(false);
    FolderData mockedRootCategoryFolder = mock(FolderData.class);
    when(mockedRootCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedRootCategoryFolder.getPath()).thenReturn("/a");
    String name1 = ROOT_CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedRootCategoryFolder.getName()).thenReturn(name1);
    FolderData mockedChildCategoryFolder = mock(FolderData.class);
    when(mockedChildCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedChildCategoryFolder.getPath()).thenReturn("/b");
    String name2 = CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedChildCategoryFolder.getName()).thenReturn(name2);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFileCount()).thenReturn(2L).thenReturn(0L);
    when(mockedRootCategoryFolder.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFileCount()).thenReturn(2L).thenReturn(0L);
    when(mockedChildCategoryFolder.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    List<FolderData> folders = Arrays.asList(mockedRootCategoryFolder, mockedChildCategoryFolder);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, Long.valueOf(FILE_PLAN_LEVEL + 1), Long.valueOf(scheduleFilePlanLoaders.getMaxLevel() - 1), 0L, Long.valueOf(foldersChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    EventResult result = scheduleFilePlanLoaders.processEvent(null, new StopWatch());
    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_FILE_PLANLOADING_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 78 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleFilePlanLoadersUnitTest method testSchedule4RecordFoldersOnLastLevelWithMaxActiveLoader3.

@Test
public void testSchedule4RecordFoldersOnLastLevelWithMaxActiveLoader3() throws Exception {
    int maxActiveLoaders = 3;
    int rootCategoriesNumber = 0;
    int categoriesChildrenNumber = 0;
    int foldersChildrenNumber = 2;
    int categoryStructureDepth = 4;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    scheduleFilePlanLoaders.setChildCategNumber(categoriesChildrenNumber);
    scheduleFilePlanLoaders.setFolderNumber(foldersChildrenNumber);
    scheduleFilePlanLoaders.setFolderCategoryMix(true);
    FolderData mockedRootCategoryFolder = mock(FolderData.class);
    when(mockedRootCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedRootCategoryFolder.getPath()).thenReturn("/a");
    String name1 = ROOT_CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedRootCategoryFolder.getName()).thenReturn(name1);
    FolderData mockedChildCategoryFolder = mock(FolderData.class);
    when(mockedChildCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedChildCategoryFolder.getPath()).thenReturn("/b");
    String name2 = CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedChildCategoryFolder.getName()).thenReturn(name2);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    List<FolderData> folders = Arrays.asList(mockedRootCategoryFolder, mockedChildCategoryFolder);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, Long.valueOf(scheduleFilePlanLoaders.getMaxLevel()), Long.valueOf(scheduleFilePlanLoaders.getMaxLevel()), 0L, Long.valueOf(foldersChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFileCount()).thenReturn(2L).thenReturn(0L);
    when(mockedRootCategoryFolder.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFileCount()).thenReturn(2L).thenReturn(0L);
    when(mockedChildCategoryFolder.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    EventResult result = scheduleFilePlanLoaders.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_RECORD_FOLDER, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_CATEGORY_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        if (i < 2) {
            assertEquals("/a", (String) dataObj.get(FIELD_PATH));
        } else {
            assertEquals("/b", (String) dataObj.get(FIELD_PATH));
        }
        assertEquals(LOAD_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)

Example 79 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleFilePlanLoadersUnitTest method testScheduleRecordFoldersOnLastLevel.

@Test
public void testScheduleRecordFoldersOnLastLevel() throws Exception {
    int maxActiveLoaders = 8;
    int rootCategoriesNumber = 0;
    int categoriesChildrenNumber = 0;
    int foldersChildrenNumber = 2;
    int categoryStructureDepth = 4;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    scheduleFilePlanLoaders.setChildCategNumber(categoriesChildrenNumber);
    scheduleFilePlanLoaders.setFolderNumber(foldersChildrenNumber);
    scheduleFilePlanLoaders.setFolderCategoryMix(true);
    FolderData mockedRootCategoryFolder = mock(FolderData.class);
    when(mockedRootCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedRootCategoryFolder.getPath()).thenReturn("/a");
    String name1 = ROOT_CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedRootCategoryFolder.getName()).thenReturn(name1);
    FolderData mockedChildCategoryFolder = mock(FolderData.class);
    when(mockedChildCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedChildCategoryFolder.getPath()).thenReturn("/b");
    String name2 = CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedChildCategoryFolder.getName()).thenReturn(name2);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    List<FolderData> folders = Arrays.asList(mockedRootCategoryFolder, mockedChildCategoryFolder);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, Long.valueOf(scheduleFilePlanLoaders.getMaxLevel()), Long.valueOf(scheduleFilePlanLoaders.getMaxLevel()), 0L, Long.valueOf(foldersChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFileCount()).thenReturn(2L).thenReturn(0L);
    when(mockedRootCategoryFolder.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFileCount()).thenReturn(2L).thenReturn(0L);
    when(mockedChildCategoryFolder.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    EventResult result = scheduleFilePlanLoaders.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_RECORD_FOLDER, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_CATEGORY_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        if (i < 2) {
            assertEquals("/a", (String) dataObj.get(FIELD_PATH));
        } else {
            assertEquals("/b", (String) dataObj.get(FIELD_PATH));
        }
        assertEquals(LOAD_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 80 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadRecordsNotWanted.

@Test
public void testUploadRecordsNotWanted() throws Exception {
    scheduleRecordLoaders.setUploadRecords(false);
    EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).createNewFolder(any(FolderData.class));
    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(mockedSessionService, never()).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Uploading of records into File Plan not wanted, continue with loading data.", result.getData());
    assertEquals(1, result.getNextEvents().size());
    Event event = result.getNextEvents().get(0);
    assertEquals("loadingRecordsComplete", event.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

EventResult (org.alfresco.bm.event.EventResult)133 Test (org.junit.Test)119 Event (org.alfresco.bm.event.Event)109 DBObject (com.mongodb.DBObject)101 StopWatch (org.apache.commons.lang3.time.StopWatch)97 FolderData (org.alfresco.bm.cm.FolderData)77 UserModel (org.alfresco.utility.model.UserModel)35 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 SiteData (org.alfresco.bm.site.SiteData)20 SiteMemberData (org.alfresco.bm.site.SiteMemberData)17 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)15 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)14 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)12 UserData (org.alfresco.bm.user.UserData)11 Node (org.alfresco.rest.requests.Node)10 Site (org.alfresco.rest.requests.Site)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)9 RestWrapper (org.alfresco.rest.core.RestWrapper)8