Search in sources :

Example 36 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class PrepareRMSiteMembersUnitTest method testNoUsersToChoseFrom.

@Test
public void testNoUsersToChoseFrom() throws Exception {
    prepareRMSiteMembers.setRole("Administrator");
    prepareRMSiteMembers.setAssignRMRoleToUsers(true);
    prepareRMSiteMembers.setUserCount(1);
    when(mockedUserDataService.getUsersByCreationState(DataCreationState.Created, 0, 100)).thenReturn(new ArrayList<UserData>());
    EventResult result = prepareRMSiteMembers.processEvent(null);
    assertEquals(true, result.isSuccess());
    assertEquals(PrepareRMSiteMembers.NO_USERS_AVAILABLE_MSG, result.getData());
    List<Event> nextEvents = result.getNextEvents();
    assertEquals(1, nextEvents.size());
    assertEquals(prepareRMSiteMembers.getEventNameContinueLoadingData(), nextEvents.get(0).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 37 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class PrepareRMSiteUnitTest method testRMSiteDoesNotExistAndLoadedInMongoDB.

@Test
public void testRMSiteDoesNotExistAndLoadedInMongoDB() throws Exception {
    String username = "bob";
    String password = "secret";
    prepareRMSite.setUsername(username);
    prepareRMSite.setPassword(password);
    when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
    when(mockedRMSiteAPI.existsRMSite()).thenReturn(false);
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteData.getSiteId()).thenReturn(RM_SITE_ID);
    when(mockedSiteData.getCreationState()).thenReturn(Created);
    when(mockedSiteDataService.getSite(RM_SITE_ID)).thenReturn(mockedSiteData);
    People mockedPeople = mock(People.class);
    RestCoreAPI mockedCoreAPI = mock(RestCoreAPI.class);
    when(mockedCoreAPI.usingAuthUser()).thenReturn(mockedPeople);
    when(mockedRestCoreAPI.withCoreAPI()).thenReturn(mockedCoreAPI);
    when(mockedRestCoreAPI.getStatusCode()).thenReturn(HttpStatus.OK.toString());
    EventResult result = prepareRMSite.processEvent(null);
    ArgumentCaptor<UserData> userData = forClass(UserData.class);
    verify(mockedUserDataService).createNewUser(userData.capture());
    // Check RM admin user
    assertEquals(Created, userData.getValue().getCreationState());
    // Check events
    assertEquals(true, result.isSuccess());
    assertEquals("Preparing Records Management: \n", result.getData());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals(DEFAULT_EVENT_NAME_RM_SITE_PREPARED, event.getName());
    DBObject data = (DBObject) event.getData();
    notNull(data);
    assertEquals(mockedSiteData.getSiteId(), (String) data.get(FIELD_SITE_ID));
    assertEquals(username, (String) data.get(FIELD_SITE_MANAGER_NAME));
    assertEquals(password, (String) data.get(FIELD_SITE_MANAGER_PASSWORD));
    assertEquals(null, (String) data.get(FIELD_ONLY_DB_LOAD));
}
Also used : UserModel(org.alfresco.utility.model.UserModel) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) People(org.alfresco.rest.requests.People) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 38 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class PrepareRMSiteUnitTest method testRMSiteDoesExistAndNotLoadedInMongoDB.

@Test
public void testRMSiteDoesExistAndNotLoadedInMongoDB() throws Exception {
    String username = "bob";
    String password = "secret";
    prepareRMSite.setUsername(username);
    prepareRMSite.setPassword(password);
    when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
    when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
    People mockedPeople = mock(People.class);
    RestCoreAPI mockedCoreAPI = mock(RestCoreAPI.class);
    when(mockedCoreAPI.usingAuthUser()).thenReturn(mockedPeople);
    when(mockedRestCoreAPI.withCoreAPI()).thenReturn(mockedCoreAPI);
    when(mockedRestCoreAPI.getStatusCode()).thenReturn(HttpStatus.OK.toString());
    EventResult result = prepareRMSite.processEvent(null);
    ArgumentCaptor<UserData> userData = forClass(UserData.class);
    verify(mockedUserDataService).createNewUser(userData.capture());
    // Check RM admin user
    assertEquals(Created, userData.getValue().getCreationState());
    // Check events
    assertEquals(true, result.isSuccess());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals("loadRMSiteIntoDB", event.getName());
    DBObject data = (DBObject) event.getData();
    notNull(data);
    assertEquals(RM_SITE_ID, (String) data.get(FIELD_SITE_ID));
    assertEquals(username, (String) data.get(FIELD_SITE_MANAGER_NAME));
    assertEquals(password, (String) data.get(FIELD_SITE_MANAGER_PASSWORD));
    assertEquals(true, (Boolean) data.get(FIELD_ONLY_DB_LOAD));
}
Also used : UserModel(org.alfresco.utility.model.UserModel) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) People(org.alfresco.rest.requests.People) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 39 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testSchedule4UnfiledRecordFoldersWithMaxActiveLoaders3.

@Test
public void testSchedule4UnfiledRecordFoldersWithMaxActiveLoaders3() throws Exception {
    int maxActiveLoaders = 3;
    int rootUnfiledRecordFolderNumber = 0;
    int unfiledRecordFolderChildrenNumber = 2;
    int unfiledRecordFolderDepth = 4;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFolderDepth);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderNumber(unfiledRecordFolderChildrenNumber);
    FolderData unfiledContainerFolder = mock(FolderData.class);
    when(unfiledContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(unfiledContainerFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(unfiledContainerFolder);
    FolderData mockedUnfiledRecordFolder1 = mock(FolderData.class);
    when(mockedUnfiledRecordFolder1.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordFolder1.getPath()).thenReturn("/a");
    FolderData mockedUnfiledRecordFolder2 = mock(FolderData.class);
    when(mockedUnfiledRecordFolder2.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordFolder2.getPath()).thenReturn("/b");
    List<FolderData> folders = Arrays.asList(mockedUnfiledRecordFolder1, mockedUnfiledRecordFolder2);
    when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, Long.valueOf(UNFILED_RECORD_CONTAINER_LEVEL + 1), Long.valueOf(scheduleUnfiledRecordFolderLoaders.getMaxLevel() - 1), 0L, Long.valueOf(unfiledRecordFolderChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFolderCount()).thenReturn(2L).thenReturn(0L);
    when(mockedUnfiledRecordFolder1.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFolderCount()).thenReturn(2L).thenReturn(0L);
    when(mockedUnfiledRecordFolder2.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
    verify(mockedSessionService, times(3)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 3 events and rescheduled self.", result.getData());
    assertEquals(4, result.getNextEvents().size());
    for (int i = 0; i < 3; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_UNFILED_RECORD_FOLDER, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_UNFILED_RECORD_FOLDER_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
        if (i < 2) {
            assertEquals("/a", (String) dataObj.get(FIELD_PATH));
        } else {
            assertEquals("/b", (String) dataObj.get(FIELD_PATH));
        }
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(3).getName());
}
Also used : 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)

Example 40 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleUnfiledRecordFolderLoadersUnitTest method testScheduleRootUnfiledRecordFoldersWithDepth0.

@Test
public void testScheduleRootUnfiledRecordFoldersWithDepth0() throws Exception {
    int maxActiveLoaders = 8;
    int rootUnfiledRecordFolderNumber = 4;
    int unfiledRecordFoldersDepth = 0;
    scheduleUnfiledRecordFolderLoaders.setCreateUnfiledRecordFolderStructure(true);
    scheduleUnfiledRecordFolderLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordFolderLoaders.setUnfiledRecordFolderDepth(unfiledRecordFoldersDepth);
    scheduleUnfiledRecordFolderLoaders.setRootUnfiledRecordFolderNumber(rootUnfiledRecordFolderNumber);
    FolderData mockedUnfiledRecordContainerFolder = mock(FolderData.class);
    when(mockedUnfiledRecordContainerFolder.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainerFolder.getPath()).thenReturn("/a");
    List<FolderData> folders = Arrays.asList(mockedUnfiledRecordContainerFolder);
    when(mockedFileFolderService.getFoldersByCounts(UNFILED_CONTEXT, 4L, 4L, 0L, Long.valueOf(rootUnfiledRecordFolderNumber - 1), null, null, 0, 100)).thenReturn(folders);
    EventResult result = scheduleUnfiledRecordFolderLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).createNewFolder(any(FolderData.class));
    verify(mockedSessionService, never()).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Loading completed.  Raising 'done' event.", result.getData());
    assertEquals(1, result.getNextEvents().size());
    assertEquals(EVENT_COMPLETE, result.getNextEvents().get(0).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

EventResult (org.alfresco.bm.event.EventResult)133 Test (org.junit.Test)119 Event (org.alfresco.bm.event.Event)109 DBObject (com.mongodb.DBObject)101 StopWatch (org.apache.commons.lang3.time.StopWatch)97 FolderData (org.alfresco.bm.cm.FolderData)77 UserModel (org.alfresco.utility.model.UserModel)35 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 SiteData (org.alfresco.bm.site.SiteData)20 SiteMemberData (org.alfresco.bm.site.SiteMemberData)17 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)15 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)14 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)12 UserData (org.alfresco.bm.user.UserData)11 Node (org.alfresco.rest.requests.Node)10 Site (org.alfresco.rest.requests.Site)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)9 RestWrapper (org.alfresco.rest.core.RestWrapper)8