Search in sources :

Example 6 with UnfiledContainer

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

the class CreateRMSite method loadSpecialContainersInDB.

private void loadSpecialContainersInDB(String siteId, String siteManager, String password) throws Exception {
    UserModel userModel = new UserModel(siteManager, password);
    FilePlan filePlanEntity = restAPIFactory.getFilePlansAPI(userModel).getFilePlan(FILE_PLAN_ALIAS);
    FolderData filePlan = new FolderData(// already unique
    filePlanEntity.getId(), FILEPLAN_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN, 0L, 0L);
    fileFolderService.createNewFolder(filePlan);
    // add Unfiled record container
    UnfiledContainer unfiledContainer = restAPIFactory.getUnfiledContainersAPI(userModel).getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
    FolderData unfiledRecordContainer = new FolderData(// already unique
    unfiledContainer.getId(), UNFILED_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN + "/" + PATH_SNIPPET_UNFILED_RECORD_CONTAINER, 0L, 0L);
    fileFolderService.createNewFolder(unfiledRecordContainer);
    // add Transfer container
    TransferContainer transferContainerEntity = restAPIFactory.getTransferContainerAPI(userModel).getTransferContainer(TRANSFERS_ALIAS);
    FolderData transferContainer = new FolderData(// already unique
    transferContainerEntity.getId(), TRANSFER_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN + "/" + PATH_SNIPPET_TRANSFER_CONTAINER, 0L, 0L);
    fileFolderService.createNewFolder(transferContainer);
}
Also used : UserModel(org.alfresco.utility.model.UserModel) UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) TransferContainer(org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) FolderData(org.alfresco.bm.cm.FolderData)

Example 7 with UnfiledContainer

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

the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithSuccess.

@Test
public void testDeclareAsRecordWithSuccess() 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("unfiledContainerID");
    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);
    FolderData mockedParentFolder = mock(FolderData.class);
    when(mockedParentFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder("unfiledContainerID")).thenReturn(mockedParentFolder);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
    EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
    assertEquals(true, result.isSuccess());
    assertEquals("Declaring file as record: \nsuccess", result.getData());
    assertEquals(1, result.getNextEvents().size());
    assertEquals(declareInPlaceRecords.getEventNameInPlaceRecordsDeclared(), result.getNextEvents().get(0).getName());
}
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) FolderData(org.alfresco.bm.cm.FolderData) 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 8 with UnfiledContainer

use of org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer 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)

Example 9 with UnfiledContainer

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

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredPaths.

@Test
public void testUploadRecordsWithNotExistentPreconfiguredPaths() throws Exception {
    int maxActiveLoaders = 3;
    int unfiledRecordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String configuredPath2 = "/e1/e2/e4";
    String paths = configuredPath1 + "," + configuredPath2;
    scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
    scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
    scheduleUnfiledRecordLoaders.setUnfiledRecordFolderPaths(paths);
    // unfiledRecord should be always there
    FolderData mockedUnfiledRecordContainer = mock(FolderData.class);
    when(mockedUnfiledRecordContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledRecordContainer.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainer.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedUnfiledRecordContainer);
    when(mockedRestApiFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI()).thenReturn(mockedUnfiledRecorFolderAPI);
    UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
    when(mockedUnfiledContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledContainerAPI.getUnfiledContainer("unfiledRecordContainerId")).thenReturn(mockedUnfiledContainer);
    // e1 folder
    UnfiledContainerChild mockedE1RootUnfiledRecordFolder = mock(UnfiledContainerChild.class);
    when(mockedE1RootUnfiledRecordFolder.getId()).thenReturn("e1Id");
    when(mockedUnfiledContainerAPI.createUnfiledContainerChild(any(UnfiledContainerChild.class), eq("unfiledRecordContainerId"))).thenReturn(mockedE1RootUnfiledRecordFolder);
    String e1Path = UNFILED_RECORD_CONTAINER_PATH + "/e1";
    FolderData mockedE1 = mock(FolderData.class);
    when(mockedE1.getId()).thenReturn("e1Id");
    when(mockedE1.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE1.getPath()).thenReturn(e1Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
    when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
    // e2 folder
    UnfiledContainerChild mockedE2ChildunfiledRecordFolder = mock(UnfiledContainerChild.class);
    when(mockedE2ChildunfiledRecordFolder.getId()).thenReturn("e2Id");
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e1Id"))).thenReturn(mockedE2ChildunfiledRecordFolder);
    String e2Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2";
    FolderData mockedE2 = mock(FolderData.class);
    when(mockedE2.getId()).thenReturn("e2Id");
    when(mockedE2.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE2.getPath()).thenReturn(e2Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
    when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
    // e3 folder
    UnfiledContainerChild mockedE3FilePlanComponent = mock(UnfiledContainerChild.class);
    when(mockedE3FilePlanComponent.getId()).thenReturn("e3Id");
    String e3Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2/e3";
    FolderData mockedE3 = mock(FolderData.class);
    when(mockedE3.getId()).thenReturn("e3Id");
    when(mockedE3.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE3.getPath()).thenReturn(e3Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
    when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
    // e4 folder
    UnfiledContainerChild mockedE4FilePlanComponent = mock(UnfiledContainerChild.class);
    when(mockedE4FilePlanComponent.getId()).thenReturn("e4Id");
    String e4Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2/e4";
    FolderData mockedE4 = mock(FolderData.class);
    when(mockedE4.getId()).thenReturn("e4Id");
    when(mockedE4.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE4.getPath()).thenReturn(e4Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e4Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE4);
    when(mockedFileFolderService.getFolder("e4Id")).thenReturn(mockedE4);
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e2Id"))).thenReturn(mockedE3FilePlanComponent).thenReturn(mockedE4FilePlanComponent);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
    EventResult result = scheduleUnfiledRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).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));
    verify(mockedFileFolderService, times(4)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(4)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
    verify(mockedFileFolderService, times(4)).getFolder(any(String.class));
    verify(mockedSessionService, times(3)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further " + (maxActiveLoaders) + " events and rescheduled self.", result.getData());
    assertEquals(maxActiveLoaders + 1, result.getNextEvents().size());
    for (int i = 0; i < maxActiveLoaders; i++) {
        Event event = result.getNextEvents().get(0);
        assertEquals(EVENT_LOAD_UNFILED_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_UNFILED_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_UNFILED_RECORD_LOADERS, result.getNextEvents().get(maxActiveLoaders).getName());
}
Also used : UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) EventResult(org.alfresco.bm.event.EventResult) UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) 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 10 with UnfiledContainer

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

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredSinglePath.

@Test
public void testUploadRecordsWithNotExistentPreconfiguredSinglePath() throws Exception {
    int maxActiveLoaders = 8;
    int unfiledRecordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String paths = configuredPath1;
    scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
    scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
    scheduleUnfiledRecordLoaders.setUnfiledRecordFolderPaths(paths);
    // unfiledRecord should be always there
    FolderData mockedUnfiledRecordContainer = mock(FolderData.class);
    when(mockedUnfiledRecordContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledRecordContainer.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainer.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedUnfiledRecordContainer);
    when(mockedRestApiFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI()).thenReturn(mockedUnfiledRecorFolderAPI);
    UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
    when(mockedUnfiledContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledContainerAPI.getUnfiledContainer("unfiledRecordContainerId")).thenReturn(mockedUnfiledContainer);
    // e1 folder
    UnfiledContainerChild mockedE1RootUnfiledRecordFolder = mock(UnfiledContainerChild.class);
    when(mockedE1RootUnfiledRecordFolder.getId()).thenReturn("e1Id");
    when(mockedUnfiledContainerAPI.createUnfiledContainerChild(any(UnfiledContainerChild.class), eq("unfiledRecordContainerId"))).thenReturn(mockedE1RootUnfiledRecordFolder);
    String e1Path = UNFILED_RECORD_CONTAINER_PATH + "/e1";
    FolderData mockedE1 = mock(FolderData.class);
    when(mockedE1.getId()).thenReturn("e1Id");
    when(mockedE1.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE1.getPath()).thenReturn(e1Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
    when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
    // e2 folder
    UnfiledContainerChild mockedE2ChildunfiledRecordFolder = mock(UnfiledContainerChild.class);
    when(mockedE2ChildunfiledRecordFolder.getId()).thenReturn("e2Id");
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e1Id"))).thenReturn(mockedE2ChildunfiledRecordFolder);
    String e2Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2";
    FolderData mockedE2 = mock(FolderData.class);
    when(mockedE2.getId()).thenReturn("e2Id");
    when(mockedE2.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE2.getPath()).thenReturn(e2Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
    when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
    // e3 folder
    UnfiledContainerChild mockedE3FilePlanComponent = mock(UnfiledContainerChild.class);
    when(mockedE3FilePlanComponent.getId()).thenReturn("e3Id");
    String e3Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2/e3";
    FolderData mockedE3 = mock(FolderData.class);
    when(mockedE3.getId()).thenReturn("e3Id");
    when(mockedE3.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE3.getPath()).thenReturn(e3Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
    when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e2Id"))).thenReturn(mockedE3FilePlanComponent);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
    EventResult result = scheduleUnfiledRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).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));
    verify(mockedFileFolderService, times(3)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(3)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
    verify(mockedFileFolderService, times(3)).getFolder(any(String.class));
    verify(mockedSessionService, times(4)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 4 events and rescheduled self.", result.getData());
    assertEquals(5, result.getNextEvents().size());
    for (int i = 0; i < unfiledRecordsNumber; i++) {
        Event event = result.getNextEvents().get(0);
        assertEquals(EVENT_LOAD_UNFILED_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(e3Path, (String) dataObj.get(FIELD_PATH));
        assertEquals(LOAD_UNFILED_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_UNFILED_RECORD_LOADERS, result.getNextEvents().get(4).getName());
}
Also used : UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) EventResult(org.alfresco.bm.event.EventResult) UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) 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

UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)10 DBObject (com.mongodb.DBObject)9 FolderData (org.alfresco.bm.cm.FolderData)9 Event (org.alfresco.bm.event.Event)9 EventResult (org.alfresco.bm.event.EventResult)9 Test (org.junit.Test)9 UserModel (org.alfresco.utility.model.UserModel)8 StopWatch (org.apache.commons.lang3.time.StopWatch)7 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)5 UnfiledContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)4 File (java.io.File)3 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)3 RMRestWrapper (org.alfresco.rest.core.RMRestWrapper)3 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)3 TransferContainer (org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer)3 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)2 SiteData (org.alfresco.bm.site.SiteData)2 SiteMemberData (org.alfresco.bm.site.SiteMemberData)2 Record (org.alfresco.rest.rm.community.model.record.Record)2 RMSite (org.alfresco.rest.rm.community.model.site.RMSite)2