use of org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI in project records-management by Alfresco.
the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithNotDeclaredFail.
@Test
public void testDeclareAsRecordWithNotDeclaredFail() throws Exception {
String fileId = "testFileId";
String username = "testUserName";
String password = "testPassword";
long delay = 10L;
declareInPlaceRecords.setDeclareInPlaceRecordDelay(delay);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_ID)).thenReturn(fileId);
when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
FilesAPI mockedFilesAPI = mock(FilesAPI.class);
when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
Record record = mock(Record.class);
when(record.getName()).thenReturn("newRecordName");
when(record.getParentId()).thenReturn("recordParentId");
when(mockedFilesAPI.declareAsRecord(fileId)).thenReturn(record);
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.CREATED.value()));
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
when(mockedUnfiledContainer.getId()).thenReturn("unfiledContainerID");
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
when(mockedUnfiledContainerAPI.getUnfiledContainer(FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledContainer);
when(mockedRestAPIFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
assertEquals(false, result.isSuccess());
assertEquals("Declaring record with id=" + fileId + " didn't take place.", result.getData());
}
use of org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI in project records-management by Alfresco.
the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithRestAPIException.
@Test
public void testDeclareAsRecordWithRestAPIException() throws Exception {
String fileId = "testFileId";
String username = "testUserName";
String password = "testPassword";
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_ID)).thenReturn(fileId);
when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
FilesAPI mockedFilesAPI = mock(FilesAPI.class);
when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
Mockito.doThrow(new Exception("someError")).when(mockedFilesAPI).declareAsRecord(any(String.class));
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
assertEquals(false, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertNotNull(data.get("error"));
assertEquals("someError", data.get("error"));
assertEquals(fileId, data.get(FIELD_ID));
assertEquals(username, data.get(FIELD_USERNAME));
assertEquals(password, data.get(FIELD_PASSWORD));
assertNotNull(data.get("stack"));
assertEquals(0, result.getNextEvents().size());
}
use of org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI in project records-management by Alfresco.
the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithFail.
@Test
public void testDeclareAsRecordWithFail() throws Exception {
String fileId = "testFileId";
String username = "testUserName";
String password = "testPassword";
String summary = "testSummary";
String stack = "testStack";
long delay = 10L;
declareInPlaceRecords.setDeclareInPlaceRecordDelay(delay);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_ID)).thenReturn(fileId);
when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
FilesAPI mockedFilesAPI = mock(FilesAPI.class);
when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.UNAUTHORIZED.value()));
RestErrorModel mockedRestErrorModel = mock(RestErrorModel.class);
when(mockedRestErrorModel.getBriefSummary()).thenReturn(summary);
when(mockedRestErrorModel.getStackTrace()).thenReturn(stack);
when(mockedRmRestWrapper.assertLastError()).thenReturn(mockedRestErrorModel);
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
assertEquals(true, result.isSuccess());
assertEquals("Declaring file as record: \nFailed with code 401.\n " + summary + ". \n" + stack, result.getData());
assertEquals(1, result.getNextEvents().size());
assertEquals(declareInPlaceRecords.getEventNameInPlaceRecordsDeclared(), result.getNextEvents().get(0).getName());
}
use of org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI in project records-management by Alfresco.
the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithSuccess.
@Test
public void testDeclareAsRecordWithSuccess() throws Exception {
String fileId = "testFileId";
String username = "testUserName";
String password = "testPassword";
long delay = 10L;
declareInPlaceRecords.setDeclareInPlaceRecordDelay(delay);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_ID)).thenReturn(fileId);
when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
FilesAPI mockedFilesAPI = mock(FilesAPI.class);
when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
Record record = mock(Record.class);
when(record.getName()).thenReturn("newRecordName");
when(record.getParentId()).thenReturn("unfiledContainerID");
when(mockedFilesAPI.declareAsRecord(fileId)).thenReturn(record);
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.CREATED.value()));
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
when(mockedUnfiledContainer.getId()).thenReturn("unfiledContainerID");
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
when(mockedUnfiledContainerAPI.getUnfiledContainer(FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledContainer);
when(mockedRestAPIFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
FolderData mockedParentFolder = mock(FolderData.class);
when(mockedParentFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder("unfiledContainerID")).thenReturn(mockedParentFolder);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
assertEquals(true, result.isSuccess());
assertEquals("Declaring file as record: \nsuccess", result.getData());
assertEquals(1, result.getNextEvents().size());
assertEquals(declareInPlaceRecords.getEventNameInPlaceRecordsDeclared(), result.getNextEvents().get(0).getName());
}
Aggregations