Search in sources :

Example 31 with EventResult

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

the class CreateRMSiteMemberUnitTest method testWithEmtyUsername.

@Test
public void testWithEmtyUsername() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn("");
    when(mockedEvent.getData()).thenReturn(mockedData);
    EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
    verify(mockedData, times(1)).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data);
}
Also used : EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 32 with EventResult

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

the class CreateRMSiteMembersUnitTest method testNoSiteIdForScheduledMembers.

@Test
public void testNoSiteIdForScheduledMembers() throws Exception {
    int batchSize = 100;
    createRMSiteMembers.setBatchSize(batchSize);
    SiteMemberData mockedSiteMemberData1 = mock(SiteMemberData.class);
    SiteMemberData mockedSiteMemberData2 = mock(SiteMemberData.class);
    when(mockedSiteMemberData1.getSiteId()).thenReturn(PATH_SNIPPET_RM_SITE_ID);
    when(mockedSiteMemberData2.getSiteId()).thenReturn(PATH_SNIPPET_RM_SITE_ID);
    when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.NotScheduled, null, 0, batchSize)).thenReturn(Arrays.asList(mockedSiteMemberData1, mockedSiteMemberData2));
    when(mockedSiteDataService.getSite(PATH_SNIPPET_RM_SITE_ID)).thenReturn(null);
    EventResult result = createRMSiteMembers.processEvent(null);
    verify(mockedSiteDataService, times(2)).getSite(PATH_SNIPPET_RM_SITE_ID);
    verify(mockedSiteDataService, times(2)).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Failed));
    verify(mockedSiteDataService, never()).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Scheduled));
    assertEquals(true, result.isSuccess());
    assertEquals(MessageFormat.format(CreateRMSiteMembers.SCHEDULED_MEMBERS_MSG_TEMPLATE, 0), result.getData());
    List<Event> nextEvents = result.getNextEvents();
    assertEquals(1, nextEvents.size());
    assertEquals(createRMSiteMembers.getEventNameCreateRMSiteMembers(), nextEvents.get(0).getName());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 33 with EventResult

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

the class CreateRMSiteMembersUnitTest method testNoSiteMembersScheduled.

@Test
public void testNoSiteMembersScheduled() throws Exception {
    int batchSize = 100;
    createRMSiteMembers.setBatchSize(batchSize);
    when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.NotScheduled, null, 0, batchSize)).thenReturn(new ArrayList<SiteMemberData>());
    EventResult result = createRMSiteMembers.processEvent(null);
    verify(mockedSiteDataService, never()).getSite(PATH_SNIPPET_RM_SITE_ID);
    verify(mockedSiteDataService, never()).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Failed));
    verify(mockedSiteDataService, never()).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Scheduled));
    assertEquals(true, result.isSuccess());
    assertEquals(MessageFormat.format(CreateRMSiteMembers.SCHEDULED_MEMBERS_MSG_TEMPLATE, 0), result.getData());
    List<Event> nextEvents = result.getNextEvents();
    assertEquals(1, nextEvents.size());
    assertEquals(createRMSiteMembers.getEventNameRMSiteMembersCreated(), nextEvents.get(0).getName());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 34 with EventResult

use of org.alfresco.bm.event.EventResult 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 35 with EventResult

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

the class PrepareRMSiteMembersUnitTest method testNoUsersWanted.

@Test
public void testNoUsersWanted() throws Exception {
    prepareRMSiteMembers.setRole("Administrator");
    prepareRMSiteMembers.setAssignRMRoleToUsers(true);
    prepareRMSiteMembers.setUserCount(0);
    EventResult result = prepareRMSiteMembers.processEvent(null);
    assertEquals(true, result.isSuccess());
    assertEquals(PrepareRMSiteMembers.NO_USERS_WANTED_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) Event(org.alfresco.bm.event.Event) 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