Search in sources :

Example 46 with EventResult

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

the class FileUnfiledRecordUnitTest method testFileRecordOperation.

@Test
public void testFileRecordOperation() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_FILED);
    loadSingleComponent.setDelay(1L);
    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("recordId1");
    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");
    String recordId1 = "recordId1";
    String recordParentPath1 = "/recordParentPath1";
    RecordData mockedRecordData1 = mock(RecordData.class);
    when(mockedRecordData1.getId()).thenReturn(recordId1);
    when(mockedRecordData1.getParentPath()).thenReturn(recordParentPath1);
    when(mockedRecordService.getRecord(recordId1)).thenReturn(mockedRecordData1);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedFileFolderService, times(1)).incrementFileCount(mockedFolder.getContext(), mockedFolder.getPath(), 1);
    verify(mockedFileFolderService, times(1)).incrementFileCount(UNFILED_CONTEXT, mockedRecordData1.getParentPath(), -1);
    verify(mockedRecordService, times(1)).updateRecord(any(RecordData.class));
    assertEquals(true, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertEquals("Filed record with id " + recordId1 + ".", data.get("msg"));
    assertEquals("/aPath", data.get(FIELD_PATH));
    assertEquals("aUser", data.get("username"));
    assertEquals(1, result.getNextEvents().size());
    Event event = result.getNextEvents().get(0);
    assertEquals(EVENT_UNFILED_RECORD_FILED, event.getName());
    DBObject eventData = (DBObject) event.getData();
    assertEquals("someContext", eventData.get(FIELD_CONTEXT));
    assertEquals("/aPath", eventData.get(FIELD_PATH));
}
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) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) Test(org.junit.Test)

Example 47 with EventResult

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

the class FileUnfiledRecordUnitTest method testFileRecordOperationWithRestAPiException.

@Test
public void testFileRecordOperationWithRestAPiException() 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("recordId1");
    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");
    RecordData mockedRecordData = mock(RecordData.class);
    when(mockedRecordService.getRecord("recordId1")).thenReturn(mockedRecordData);
    Mockito.doThrow(new Exception("someError")).when(mockedRecordsAPI).fileRecord(any(RecordBodyFile.class), any(String.class));
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedFileFolderService, never()).deleteFolder(mockedFolder.getContext(), mockedFolder.getPath() + "/locked", false);
    verify(mockedFileFolderService, never()).incrementFileCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data.get("error"));
    assertEquals("someError", data.get("error"));
    assertEquals("aUser", data.get("username"));
    assertEquals(mockedFolder.getPath(), data.get("path"));
    assertNotNull(data.get("stack"));
    assertEquals(0, result.getNextEvents().size());
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) RecordBodyFile(org.alfresco.rest.rm.community.model.record.RecordBodyFile) 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)

Example 48 with EventResult

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

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadNoRecords.

@Test
public void testUploadNoRecords() throws Exception {
    int maxActiveLoaders = 8;
    int unfiledRecordsNumber = 0;
    scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
    scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
    EventResult result = scheduleUnfiledRecordLoaders.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));
    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) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 49 with EventResult

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

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithNoPreconfiguredPaths.

@Test
public void testUploadRecordsWithNoPreconfiguredPaths() throws Exception {
    int maxActiveLoaders = 8;
    int unfiledRecordsNumber = 4;
    String paths = "";
    scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
    scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
    scheduleUnfiledRecordLoaders.setUnfiledRecordFolderPaths(paths);
    FolderData mockedUnfiledRecordContainer = mock(FolderData.class);
    when(mockedUnfiledRecordContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledRecordContainer.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainer.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedUnfiledRecordContainer);
    FolderData mockedUnfiledRecordFolder = mock(FolderData.class);
    when(mockedUnfiledRecordFolder.getId()).thenReturn("folderId");
    when(mockedUnfiledRecordFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH + "/folder1");
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH + "/folder1")).thenReturn(mockedUnfiledRecordFolder);
    when(mockedRestApiFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI()).thenReturn(mockedUnfiledRecorFolderAPI);
    // returns unfiled record container here, this is always available plus another unfiled record folder
    when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, null, null, null, null, null, null, 0, 100)).thenReturn(Arrays.asList(mockedUnfiledRecordContainer, mockedUnfiledRecordFolder));
    when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, null, null, null, null, null, null, 100, 100)).thenReturn(new ArrayList<FolderData>());
    EventResult result = scheduleUnfiledRecordLoaders.processEvent(null, new StopWatch());
    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));
    verify(mockedSessionService, times(4)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further " + (unfiledRecordsNumber) + " events and rescheduled self.", result.getData());
    assertEquals(unfiledRecordsNumber + 1, result.getNextEvents().size());
    for (int i = 0; i < unfiledRecordsNumber; i++) {
        Event event = result.getNextEvents().get(0);
        assertEquals(EVENT_LOAD_UNFILED_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_UNFILED_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_UNFILED_RECORD_LOADERS, result.getNextEvents().get(unfiledRecordsNumber).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 50 with EventResult

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

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsNotWanted.

@Test
public void testUploadRecordsNotWanted() throws Exception {
    scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(false);
    EventResult result = scheduleUnfiledRecordLoaders.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));
    assertEquals(true, result.isSuccess());
    assertEquals("Uploading of Unfiled Records not wanted.", result.getData());
    assertEquals(1, result.getNextEvents().size());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) 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