Search in sources :

Example 1 with UnfiledContainer

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

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

the class CreateRMSiteUnitTest method testRMSiteCreation.

@Test
public void testRMSiteCreation() 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(mockedEvent.getData()).thenReturn(mockedData);
    when(mockedSiteDataService.getSite(siteId)).thenReturn(null);
    when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
    when(mockedRMSiteAPI.createRMSite(any(RMSite.class))).thenReturn(mockedRMSite);
    when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
    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());
    RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
    when(mockedRmRestWrapper.getStatusCode()).thenReturn(HttpStatus.CREATED.toString());
    when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
    EventResult result = createRMSite.processEvent(mockedEvent);
    ArgumentCaptor<SiteData> siteData = forClass(SiteData.class);
    verify(mockedSiteDataService).addSite(siteData.capture());
    ArgumentCaptor<SiteMemberData> siteMemberData = forClass(SiteMemberData.class);
    verify(mockedSiteDataService).addSiteMember(siteMemberData.capture());
    // Check RM site
    SiteData siteDataValue = siteData.getValue();
    assertEquals(Scheduled, siteDataValue.getCreationState());
    // Check RM admin member
    SiteMemberData siteMemberDataValue = siteMemberData.getValue();
    assertEquals(Created, siteMemberDataValue.getCreationState());
    assertEquals(Administrator.toString(), siteMemberDataValue.getRole());
    verify(mockedRMSiteAPI, times(1)).createRMSite(any(RMSite.class));
    verify(mockedFileFolderService, times(3)).createNewFolder(any(FolderData.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Created site: " + siteId + " Site creator: " + siteManager, (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) RMRestWrapper(org.alfresco.rest.core.RMRestWrapper) Test(org.junit.Test)

Example 3 with UnfiledContainer

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

the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledContainerWithNoFileException.

@Test
public void testLoadUnfiledRecordOperationInUnfiledContainerWithNoFileException() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_UNFILED_RECORD_OPERATION);
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFolder.getContext()).thenReturn("someContext");
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI(any(UserModel.class))).thenReturn(mockedUnfiledRecordFolderAPI);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder);
    UnfiledContainer mockedFilePlanComponent = mock(UnfiledContainer.class);
    when(mockedUnfiledContainerAPI.getUnfiledContainer("folderId")).thenReturn(mockedFilePlanComponent);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedFileFolderService, never()).deleteFolder(mockedFolder.getContext(), mockedFolder.getPath() + "/locked", false);
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedUnfiledContainerAPI, never()).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
    verify(mockedFileFolderService, never()).incrementFileCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data.get("error"));
    assertEquals("No test files exist for upload: mockedTestFileService", data.get("error"));
    assertEquals("aUser", data.get("username"));
    assertEquals(mockedFolder.getPath(), data.get("path"));
    assertNotNull(data.get("stack"));
    assertEquals(0, result.getNextEvents().size());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) 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) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) Test(org.junit.Test)

Example 4 with UnfiledContainer

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

the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledRecordContainer.

@Test
public void testLoadUnfiledRecordOperationInUnfiledRecordContainer() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
    loadSingleComponent.setDelay(1L);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_UNFILED_RECORD_OPERATION);
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFolder.getContext()).thenReturn("someContext");
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI(any(UserModel.class))).thenReturn(mockedUnfiledRecordFolderAPI);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder);
    UnfiledContainer mockedFilePlanComponent = mock(UnfiledContainer.class);
    when(mockedFilePlanComponent.getId()).thenReturn("folderId");
    when(mockedUnfiledContainerAPI.getUnfiledContainer("folderId")).thenReturn(mockedFilePlanComponent);
    UnfiledContainerChild mockRecord1 = mock(UnfiledContainerChild.class);
    String recordId1 = "recordId1";
    String recordName1 = "recordName1";
    when(mockRecord1.getId()).thenReturn(recordId1);
    when(mockRecord1.getName()).thenReturn(recordName1);
    when(mockedUnfiledContainerAPI.uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class))).thenReturn(mockRecord1).thenReturn(null);
    File mockedFile = mock(File.class);
    when(mockedTestFileService.getFile()).thenReturn(mockedFile);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedUnfiledContainerAPI, times(1)).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
    verify(mockedFileFolderService, times(1)).incrementFileCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(true, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertEquals("Created 1 record.", data.get("msg"));
    assertEquals("/aPath", data.get(FIELD_PATH));
    assertEquals("aUser", data.get("username"));
    assertEquals(1, result.getNextEvents().size());
    Event event = result.getNextEvents().get(0);
    assertEquals(EVENT_UNFILED_RECORD_LOADED, event.getName());
    DBObject eventData = (DBObject) event.getData();
    assertEquals("someContext", eventData.get(FIELD_CONTEXT));
    assertEquals("/aPath", eventData.get(FIELD_PATH));
}
Also used : UserModel(org.alfresco.utility.model.UserModel) 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) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) Test(org.junit.Test)

Example 5 with UnfiledContainer

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

the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledContainerWithRestAPiException.

@Test
public void testLoadUnfiledRecordOperationInUnfiledContainerWithRestAPiException() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_UNFILED_RECORD_OPERATION);
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFolder.getContext()).thenReturn("someContext");
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI(any(UserModel.class))).thenReturn(mockedUnfiledRecordFolderAPI);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder);
    UnfiledContainer mockedFilePlanComponent = mock(UnfiledContainer.class);
    when(mockedUnfiledContainerAPI.getUnfiledContainer("folderId")).thenReturn(mockedFilePlanComponent);
    File mockedFile = mock(File.class);
    when(mockedTestFileService.getFile()).thenReturn(mockedFile);
    Mockito.doThrow(new Exception("someError")).when(mockedUnfiledContainerAPI).uploadRecord(any(UnfiledContainerChild.class), any(String.class), any(File.class));
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedUnfiledContainerAPI, times(1)).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
    verify(mockedFileFolderService, never()).incrementFileCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data.get("error"));
    assertEquals("someError", data.get("error"));
    assertEquals("aUser", data.get("username"));
    assertEquals(mockedFolder.getPath(), data.get("path"));
    assertNotNull(data.get("stack"));
    assertEquals(0, result.getNextEvents().size());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) 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) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) 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