Search in sources :

Example 31 with FolderData

use of org.alfresco.bm.cm.FolderData 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 32 with FolderData

use of org.alfresco.bm.cm.FolderData 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)

Example 33 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledRecordFolderWithRestAPiException.

@Test
public void testLoadUnfiledRecordOperationInUnfiledRecordFolderWithRestAPiException() 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);
    FolderData mockedFolder1 = mock(FolderData.class);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder1);
    File mockedFile = mock(File.class);
    when(mockedTestFileService.getFile()).thenReturn(mockedFile);
    Mockito.doThrow(new Exception("someError")).when(mockedUnfiledRecordFolderAPI).uploadRecord(any(UnfiledContainerChild.class), any(String.class), any(File.class));
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedUnfiledRecordFolderAPI, 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) 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 34 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class LoadSubCategoryUnitTest method testLoadSubCategoryOperation.

@Test
public void testLoadSubCategoryOperation() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_SUB_CATEGORY_LOADED);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn(FILEPLAN_CONTEXT);
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_SUB_CATEGORY_OPERATION);
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, "/aPath")).thenReturn(mockedFolder);
    loadSingleComponent.setFileFolderService(mockedFileFolderService);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    when(mockedRestApiFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
    when(mockedRestApiFactory.getRecordCategoryAPI(any(UserModel.class))).thenReturn(mockedRecordCategoryAPI);
    RecordCategory mockedFilePlanComponent = mock(RecordCategory.class);
    when(mockedFilePlanComponent.getId()).thenReturn("folderId");
    when(mockedRecordCategoryAPI.getRecordCategory("folderId")).thenReturn(mockedFilePlanComponent);
    RecordCategoryChild mockedChildFilePlanComponent = mock(RecordCategoryChild.class);
    when(mockedChildFilePlanComponent.getId()).thenReturn(UUID.randomUUID().toString());
    when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("folderId"))).thenReturn(mockedChildFilePlanComponent);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedFileFolderService, times(1)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(1)).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(true, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertEquals("Created 1 sub-category", 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_SUB_CATEGORY_LOADED, event.getName());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) EventResult(org.alfresco.bm.event.EventResult) RecordCategoryChild(org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) RecordCategory(org.alfresco.rest.rm.community.model.recordcategory.RecordCategory) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) Test(org.junit.Test)

Example 35 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class LoadRecordUnitTest method testUploadRecordOperation.

@Test
public void testUploadRecordOperation() throws Exception {
    loadSingleComponent.setEventNameComplete("recordLoaded");
    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_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.getRecordFolderAPI(any(UserModel.class))).thenReturn(mockedRecordFolderAPI);
    RecordFolder mockedFilePlanComponent = mock(RecordFolder.class);
    when(mockedFilePlanComponent.getId()).thenReturn("folderId");
    when(mockedRecordFolderAPI.getRecordFolder("folderId")).thenReturn(mockedFilePlanComponent);
    File mockedFile = mock(File.class);
    when(mockedTestFileService.getFile()).thenReturn(mockedFile);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedRecordFolderAPI, times(1)).createRecord(any(Record.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("recordLoaded", 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) EventResult(org.alfresco.bm.event.EventResult) RecordFolder(org.alfresco.rest.rm.community.model.recordfolder.RecordFolder) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) Record(org.alfresco.rest.rm.community.model.record.Record) 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

FolderData (org.alfresco.bm.cm.FolderData)94 DBObject (com.mongodb.DBObject)76 Event (org.alfresco.bm.event.Event)70 Test (org.junit.Test)69 EventResult (org.alfresco.bm.event.EventResult)68 StopWatch (org.apache.commons.lang3.time.StopWatch)68 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)21 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)14 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)10 File (java.io.File)9 RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)8 ArrayList (java.util.ArrayList)7 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)7 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)7 LinkedHashSet (java.util.LinkedHashSet)5 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)5 Record (org.alfresco.rest.rm.community.model.record.Record)4 RecordFolder (org.alfresco.rest.rm.community.model.recordfolder.RecordFolder)3 RecordCategoryAPI (org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI)2