Search in sources :

Example 6 with FilePlan

use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadRecordsInNonExistentOnePathElCategory.

@Test
public void testUploadRecordsInNonExistentOnePathElCategory() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String configuredPath1 = "/e1";
    String paths = configuredPath1;
    scheduleRecordLoaders.setUploadRecords(true);
    scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleRecordLoaders.setRecordsNumber(recordsNumber);
    scheduleRecordLoaders.setRecordFolderPaths(paths);
    // file plan should be always there
    FolderData mockedFilePlanContainer = mock(FolderData.class);
    when(mockedFilePlanContainer.getId()).thenReturn("filePlanId");
    when(mockedFilePlanContainer.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(mockedFilePlanContainer.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(mockedFilePlanContainer);
    // 2 existent record folders
    String path1 = RECORD_CONTAINER_PATH + "/categ1/folder1";
    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 + "/categ2/folder2";
    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 available 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>());
    when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
    when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
    FilePlan mockedFilePlan = mock(FilePlan.class);
    when(mockedFilePlan.getId()).thenReturn("filePlanId");
    when(mockedFilePlanAPI.getFilePlan("filePlanId")).thenReturn(mockedFilePlan);
    String e1Path = RECORD_CONTAINER_PATH + "/e1";
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e1Path)).thenReturn(null);
    EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).getFolder(any(String.class));
    verify(mockedFileFolderService, never()).incrementFolderCount(any(String.class), any(String.class), eq(1L));
    verify(mockedFileFolderService, never()).createNewFolder(any(String.class), any(String.class), any(String.class));
    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());
    for (int i = 0; i < recordsNumber; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(recordsNumber).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) 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)

Example 7 with FilePlan

use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.

the class CreateRMSiteUnitTest method testLoadingInDbExistentRmSite.

@Test
public void testLoadingInDbExistentRmSite() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    RMSiteAPI mockedRMSiteAPI = mock(RMSiteAPI.class);
    RMSite mockedRMSite = mock(RMSite.class);
    FilePlanAPI mockedFilePlanAPI = mock(FilePlanAPI.class);
    UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
    TransferContainerAPI mockedTransferContainerAPI = mock(TransferContainerAPI.class);
    FilePlan mockedFilePlan = mock(FilePlan.class);
    UnfiledContainer mockedUnfiledRecordsContainer = mock(UnfiledContainer.class);
    TransferContainer mockedTransfers = mock(TransferContainer.class);
    String siteId = randomUUID().toString();
    String siteManager = randomUUID().toString();
    String password = "password";
    when(mockedData.get(FIELD_SITE_ID)).thenReturn(siteId);
    when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn(siteManager);
    when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn(password);
    when(mockedData.get(FIELD_ONLY_DB_LOAD)).thenReturn(true);
    when(mockedEvent.getData()).thenReturn(mockedData);
    when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
    when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
    String guuid = randomUUID().toString();
    when(mockedRMSite.getGuid()).thenReturn(guuid);
    when(mockedRMSiteAPI.getSite()).thenReturn(mockedRMSite);
    when(mockedRestAPIFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
    when(mockedFilePlanAPI.getFilePlan(FILE_PLAN_ALIAS)).thenReturn(mockedFilePlan);
    when(mockedFilePlan.getId()).thenReturn(randomUUID().toString());
    when(mockedRestAPIFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
    when(mockedUnfiledContainerAPI.getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledRecordsContainer);
    when(mockedUnfiledRecordsContainer.getId()).thenReturn(randomUUID().toString());
    when(mockedRestAPIFactory.getTransferContainerAPI(any(UserModel.class))).thenReturn(mockedTransferContainerAPI);
    when(mockedTransferContainerAPI.getTransferContainer(TRANSFERS_ALIAS)).thenReturn(mockedTransfers);
    when(mockedTransfers.getId()).thenReturn(randomUUID().toString());
    EventResult result = createRMSite.processEvent(mockedEvent);
    verify(mockedRMSiteAPI, never()).createRMSite(any(RMSite.class));
    verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
    verify(mockedSiteDataService, times(1)).addSiteMember(any(SiteMemberData.class));
    verify(mockedFileFolderService, times(3)).createNewFolder(any(FolderData.class));
    assertEquals(true, result.isSuccess());
    assertEquals("RM site already exists, just loading it in the DB.", (String) result.getData());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals(DEFAULT_EVENT_NAME_SITE_CREATED, event.getName());
    DBObject data = (DBObject) event.getData();
    assertEquals(null, data);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) DBObject(com.mongodb.DBObject) FilePlanAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI) UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) UserModel(org.alfresco.utility.model.UserModel) RMSiteAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI) TransferContainer(org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer) SiteMemberData(org.alfresco.bm.site.SiteMemberData) RMSite(org.alfresco.rest.rm.community.model.site.RMSite) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) TransferContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.TransferContainerAPI) Event(org.alfresco.bm.event.Event) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI) Test(org.junit.Test)

Aggregations

FolderData (org.alfresco.bm.cm.FolderData)7 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)7 DBObject (com.mongodb.DBObject)6 Event (org.alfresco.bm.event.Event)6 EventResult (org.alfresco.bm.event.EventResult)6 Test (org.junit.Test)6 UserModel (org.alfresco.utility.model.UserModel)4 StopWatch (org.apache.commons.lang3.time.StopWatch)4 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)3 TransferContainer (org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer)3 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)3 SiteData (org.alfresco.bm.site.SiteData)2 SiteMemberData (org.alfresco.bm.site.SiteMemberData)2 RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)2 RMSite (org.alfresco.rest.rm.community.model.site.RMSite)2 FilePlanAPI (org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI)2 RMSiteAPI (org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI)2 TransferContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.TransferContainerAPI)2 UnfiledContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)2 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)1