Search in sources :

Example 16 with Event

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

the class DeclareInPlaceRecordsUnitTest method testWithNullSiteId.

@Test(expected = IllegalStateException.class)
public void testWithNullSiteId() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_ID)).thenReturn(null);
    when(mockedEvent.getData()).thenReturn(mockedData);
    declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
}
Also used : Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 17 with Event

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

Example 18 with Event

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

the class DeclareInPlaceRecordsUnitTest method testWithNullData.

@Test(expected = IllegalStateException.class)
public void testWithNullData() throws Exception {
    Event mockedEvent = mock(Event.class);
    when(mockedEvent.getData()).thenReturn(null);
    declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
}
Also used : Event(org.alfresco.bm.event.Event) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 19 with Event

use of org.alfresco.bm.event.Event 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());
}
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) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 20 with Event

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

the class DeclareInPlaceRecordsUnitTest method testWithEmptyPassword.

@Test(expected = IllegalStateException.class)
public void testWithEmptyPassword() throws Exception {
    String siteId = "testColabSiteId";
    String username = "testUserName";
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_ID)).thenReturn(siteId);
    when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
    when(mockedData.get(FIELD_PASSWORD)).thenReturn(EMPTY_STRING);
    when(mockedEvent.getData()).thenReturn(mockedData);
    declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
}
Also used : Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

Event (org.alfresco.bm.event.Event)133 DBObject (com.mongodb.DBObject)111 Test (org.junit.Test)110 EventResult (org.alfresco.bm.event.EventResult)109 StopWatch (org.apache.commons.lang3.time.StopWatch)87 FolderData (org.alfresco.bm.cm.FolderData)74 UserModel (org.alfresco.utility.model.UserModel)36 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 SiteMemberData (org.alfresco.bm.site.SiteMemberData)19 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)15 SiteData (org.alfresco.bm.site.SiteData)12 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)12 ArrayList (java.util.ArrayList)11 UserData (org.alfresco.bm.user.UserData)11 File (java.io.File)9 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)9 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)6 Record (org.alfresco.rest.rm.community.model.record.Record)6 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)6 RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)6