use of org.alfresco.rest.model.RestErrorModel 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());
}
Aggregations