Search in sources :

Example 1 with RestErrorModel

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());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) RecordData(org.alfresco.bm.dataload.rm.services.RecordData) FilesAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI) EventResult(org.alfresco.bm.event.EventResult) RestErrorModel(org.alfresco.rest.model.RestErrorModel) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) RMRestWrapper(org.alfresco.rest.core.RMRestWrapper) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

DBObject (com.mongodb.DBObject)1 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)1 Event (org.alfresco.bm.event.Event)1 EventResult (org.alfresco.bm.event.EventResult)1 RMRestWrapper (org.alfresco.rest.core.RMRestWrapper)1 RestErrorModel (org.alfresco.rest.model.RestErrorModel)1 FilesAPI (org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI)1 UserModel (org.alfresco.utility.model.UserModel)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Test (org.junit.Test)1