Search in sources :

Example 41 with EventResult

use of org.alfresco.bm.event.EventResult 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 42 with EventResult

use of org.alfresco.bm.event.EventResult 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)

Example 43 with EventResult

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

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testScheduleUnfiledRecordFoldersChildrenWithDepthLessThan2.

@Test
public void testScheduleUnfiledRecordFoldersChildrenWithDepthLessThan2() throws Exception {
    int maxActiveLoaders = 8;
    int rootUnfiledRecordFolderNumber = 0;
    int unfiledRecordFolderChildrenNumber = 2;
    int unfiledRecordFolderDepth = 1;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFolderDepth);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderNumber(unfiledRecordFolderChildrenNumber);
    FolderData mockedUnfiledRecordContainerFolder = mock(FolderData.class);
    when(mockedUnfiledRecordContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainerFolder.getPath()).thenReturn("/a");
    FolderData mockedUnfiledRecordContainerFolder2 = mock(FolderData.class);
    when(mockedUnfiledRecordContainerFolder2.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainerFolder2.getPath()).thenReturn("/b");
    List<FolderData> folders = Arrays.asList(mockedUnfiledRecordContainerFolder, mockedUnfiledRecordContainerFolder2);
    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);
    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(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 44 with EventResult

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

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testUnfiledRecordFoldersNotWanted.

@Test
public void testUnfiledRecordFoldersNotWanted() throws Exception {
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(false);
    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("Unfiled Record Folders structure creation not wanted, continue with loading data.", result.getData());
    assertEquals(1, result.getNextEvents().size());
}
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 45 with EventResult

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

the class FileUnfiledRecordUnitTest method testFileRecordOperationWithEmptyRecordId.

@Test
public void testFileRecordOperationWithEmptyRecordId() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_FILED);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(FILE_RECORD_OPERATION);
    when(mockedData.get(FIELD_RECORD_ID)).thenReturn("");
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFolder.getContext()).thenReturn("someContext");
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    assertEquals(false, result.isSuccess());
    assertEquals("Request data not complete for filing unfiled record: " + mockedData, result.getData());
    assertEquals(0, result.getNextEvents().size());
}
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) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) 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