Search in sources :

Example 36 with StopWatch

use of org.apache.commons.lang3.time.StopWatch 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 37 with StopWatch

use of org.apache.commons.lang3.time.StopWatch 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 38 with StopWatch

use of org.apache.commons.lang3.time.StopWatch 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 39 with StopWatch

use of org.apache.commons.lang3.time.StopWatch 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)

Example 40 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.

the class ScheduleFilingUnfiledRecordsUnitTest method testFileRecordsWithNoPreconfiguredFilingToPaths.

@Test
public void testFileRecordsWithNoPreconfiguredFilingToPaths() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String recordId1 = "recordId1";
    String recordId2 = "recordId2";
    String recordId3 = "recordId3";
    String recordId4 = "recordId4";
    String paths = "";
    scheduleFilingUnfiledRecords.setFileUnfiledRecords(true);
    scheduleFilingUnfiledRecords.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilingUnfiledRecords.setRecordFilingLimit("0");
    scheduleFilingUnfiledRecords.setFileToRecordFolderPaths(paths);
    when(mockedRecordService.getRecordCountInSpecifiedPaths(ExecutionState.UNFILED_RECORD_DECLARED.name(), null)).thenReturn(4L);
    String path1 = RECORD_CONTAINER_PATH + "/RootCateg1/recordFolder1";
    FolderData mockedRecordFolder1 = mock(FolderData.class);
    when(mockedRecordFolder1.getId()).thenReturn("recordFolder1Id");
    when(mockedRecordFolder1.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder1.getPath()).thenReturn(path1);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path1)).thenReturn(mockedRecordFolder1);
    String path2 = RECORD_CONTAINER_PATH + "/RootCateg1/recordFolder2";
    FolderData mockedRecordFolder2 = mock(FolderData.class);
    when(mockedRecordFolder2.getId()).thenReturn("recordFolder2Id");
    when(mockedRecordFolder2.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder2.getPath()).thenReturn(path2);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path2)).thenReturn(mockedRecordFolder2);
    // returns record folders
    when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 0, 100)).thenReturn(Arrays.asList(mockedRecordFolder1, mockedRecordFolder2));
    when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 100, 100)).thenReturn(new ArrayList<FolderData>());
    RecordData mockedRecordData1 = mock(RecordData.class);
    when(mockedRecordData1.getId()).thenReturn(recordId1);
    RecordData mockedRecordData2 = mock(RecordData.class);
    when(mockedRecordData2.getId()).thenReturn(recordId2);
    RecordData mockedRecordData3 = mock(RecordData.class);
    when(mockedRecordData3.getId()).thenReturn(recordId3);
    RecordData mockedRecordData4 = mock(RecordData.class);
    when(mockedRecordData4.getId()).thenReturn(recordId4);
    when(mockedRecordService.getRandomRecord(ExecutionState.UNFILED_RECORD_DECLARED.name(), null)).thenReturn(mockedRecordData1).thenReturn(mockedRecordData2).thenReturn(mockedRecordData3).thenReturn(mockedRecordData4);
    EventResult result = scheduleFilingUnfiledRecords.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, times(2)).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
    assertEquals(true, result.isSuccess());
    verify(mockedSessionService, times(recordsNumber)).startSession(any(DBObject.class));
    assertEquals("Raised further " + (recordsNumber) + " events and rescheduled self.", result.getData());
    assertEquals(recordsNumber + 1, result.getNextEvents().size());
    List<String> listOfIds = Arrays.asList(recordId1, recordId2, recordId3, recordId4);
    for (int i = 0; i < recordsNumber; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(TEST_EVENT_FILE_UNFILED_RECORDS, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(FILE_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
        assertEquals(listOfIds.get(i), dataObj.get(FIELD_RECORD_ID));
    }
    assertEquals(TEST_EVENT_RESCHEDULE_SELF, result.getNextEvents().get(recordsNumber).getName());
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

StopWatch (org.apache.commons.lang3.time.StopWatch)500 Test (org.junit.Test)149 EventResult (org.alfresco.bm.event.EventResult)97 DBObject (com.mongodb.DBObject)90 Event (org.alfresco.bm.event.Event)87 FolderData (org.alfresco.bm.cm.FolderData)75 File (java.io.File)72 ArrayList (java.util.ArrayList)48 HashSet (java.util.HashSet)31 Gene (ubic.gemma.model.genome.Gene)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)26 BaseTest (org.umlg.sqlg.test.BaseTest)26 Element (org.w3c.dom.Element)25 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)19 HashMap (java.util.HashMap)18 List (java.util.List)18 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18