use of org.alfresco.rest.rm.community.model.recordfolder.RecordFolder in project records-management by Alfresco.
the class LoadRecordUnitTest method testUploadRecordOperation.
@Test
public void testUploadRecordOperation() throws Exception {
loadSingleComponent.setEventNameComplete("recordLoaded");
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(LOAD_RECORD_OPERATION);
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");
when(mockedRestApiFactory.getRecordFolderAPI(any(UserModel.class))).thenReturn(mockedRecordFolderAPI);
RecordFolder mockedFilePlanComponent = mock(RecordFolder.class);
when(mockedFilePlanComponent.getId()).thenReturn("folderId");
when(mockedRecordFolderAPI.getRecordFolder("folderId")).thenReturn(mockedFilePlanComponent);
File mockedFile = mock(File.class);
when(mockedTestFileService.getFile()).thenReturn(mockedFile);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedTestFileService, times(1)).getFile();
verify(mockedRecordFolderAPI, times(1)).createRecord(any(Record.class), eq("folderId"), any(File.class));
verify(mockedFileFolderService, times(1)).incrementFileCount(any(String.class), any(String.class), any(Long.class));
assertEquals(true, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertEquals("Created 1 record.", 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("recordLoaded", event.getName());
DBObject eventData = (DBObject) event.getData();
assertEquals("someContext", eventData.get(FIELD_CONTEXT));
assertEquals("/aPath", eventData.get(FIELD_PATH));
}
use of org.alfresco.rest.rm.community.model.recordfolder.RecordFolder in project records-management by Alfresco.
the class LoadRecordUnitTest method testLoadRecordOperationWithRestAPiException.
@Test
public void testLoadRecordOperationWithRestAPiException() throws Exception {
loadSingleComponent.setEventNameComplete("recordLoaded");
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(LOAD_RECORD_OPERATION);
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");
when(mockedRestApiFactory.getRecordFolderAPI(any(UserModel.class))).thenReturn(mockedRecordFolderAPI);
RecordFolder mockedFilePlanComponent = mock(RecordFolder.class);
when(mockedRecordFolderAPI.getRecordFolder("folderId")).thenReturn(mockedFilePlanComponent);
File mockedFile = mock(File.class);
when(mockedTestFileService.getFile()).thenReturn(mockedFile);
Mockito.doThrow(new Exception("someError")).when(mockedRecordFolderAPI).createRecord(any(Record.class), any(String.class), any(File.class));
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedTestFileService, times(1)).getFile();
verify(mockedRecordFolderAPI, times(1)).createRecord(any(Record.class), eq("folderId"), any(File.class));
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());
}
use of org.alfresco.rest.rm.community.model.recordfolder.RecordFolder in project records-management by Alfresco.
the class LoadRecordUnitTest method testLoadRecordOperationWithNoFileException.
@Test
public void testLoadRecordOperationWithNoFileException() throws Exception {
loadSingleComponent.setEventNameComplete("recordLoaded");
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(LOAD_RECORD_OPERATION);
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");
when(mockedRestApiFactory.getRecordFolderAPI(any(UserModel.class))).thenReturn(mockedRecordFolderAPI);
RecordFolder mockedFilePlanComponent = mock(RecordFolder.class);
when(mockedRecordFolderAPI.getRecordFolder("folderId")).thenReturn(mockedFilePlanComponent);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedTestFileService, times(1)).getFile();
verify(mockedRecordFolderAPI, never()).createRecord(any(Record.class), eq("folderId"), any(File.class));
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("No test files exist for upload: mockedTestFileService", data.get("error"));
assertEquals("aUser", data.get("username"));
assertEquals(mockedFolder.getPath(), data.get("path"));
assertNotNull(data.get("stack"));
assertEquals(0, result.getNextEvents().size());
}
Aggregations