Search in sources :

Example 1 with SiteMemberData

use of org.alfresco.bm.site.SiteMemberData in project records-management by Alfresco.

the class CreateRMSiteMemberUnitTest method testCreateSiteMember.

@Test
public void testCreateSiteMember() throws Exception {
    String userName = "user1";
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(userName);
    when(mockedEvent.getData()).thenReturn(mockedData);
    SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
    when(mockedSiteMemberData.getCreationState()).thenReturn(DataCreationState.Scheduled);
    when(mockedSiteMemberData.getRole()).thenReturn(RMRole.Administrator.toString());
    when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName)).thenReturn(mockedSiteMemberData);
    RMUserAPI mockedRMUserAPI = mock(RMUserAPI.class);
    when(mockedRestAPIFactory.getRMUserAPI()).thenReturn(mockedRMUserAPI);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
    EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_MISSING_MSG_TEMPLATE, userName));
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_ALREADY_PROCESSED_MSG_TEMPLATE, mockedSiteMemberData));
    verify(mockedRMUserAPI, times(1)).assignRoleToUser(userName, RMRole.Administrator.toString());
    verify(mockedSiteDataService, times(1)).setSiteMemberCreationState(PATH_SNIPPET_RM_SITE_ID, userName, DataCreationState.Created);
    verify(mockedSiteDataService, times(2)).getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName);
    assertEquals(true, result.isSuccess());
    String data = (String) result.getData();
    assertTrue(data.startsWith(CREATED_RM_SITE_MEMBER_MSG));
    assertEquals(1, result.getNextEvents().size());
    assertEquals(createRMSiteMember.getEventNameRMSiteMemberCreated(), result.getNextEvents().get(0).getName());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) RMUserAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 2 with SiteMemberData

use of org.alfresco.bm.site.SiteMemberData in project records-management by Alfresco.

the class CreateRMSiteMemberUnitTest method testAlreadyProcessedSiteMember.

@Test
public void testAlreadyProcessedSiteMember() throws Exception {
    String userName = "user1";
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(userName);
    when(mockedEvent.getData()).thenReturn(mockedData);
    SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
    when(mockedSiteMemberData.getCreationState()).thenReturn(DataCreationState.Created);
    when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName)).thenReturn(mockedSiteMemberData);
    EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_MISSING_MSG_TEMPLATE, userName));
    verify(mockedData, times(1)).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_ALREADY_PROCESSED_MSG_TEMPLATE, mockedSiteMemberData));
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data);
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) 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 3 with SiteMemberData

use of org.alfresco.bm.site.SiteMemberData in project records-management by Alfresco.

the class CreateRMSiteMemberUnitTest method testCreateSiteMemberWithExceptionOnRestAPI.

@Test(expected = RuntimeException.class)
public void testCreateSiteMemberWithExceptionOnRestAPI() throws Exception {
    String userName = "user1";
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(userName);
    when(mockedEvent.getData()).thenReturn(mockedData);
    SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
    when(mockedSiteMemberData.getCreationState()).thenReturn(DataCreationState.Scheduled);
    when(mockedSiteMemberData.getRole()).thenReturn(RMRole.Administrator.toString());
    when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName)).thenReturn(mockedSiteMemberData);
    RMUserAPI mockedRMUserAPI = mock(RMUserAPI.class);
    when(mockedRestAPIFactory.getRMUserAPI()).thenReturn(mockedRMUserAPI);
    Mockito.doThrow(new Exception("someError")).when(mockedRMUserAPI).assignRoleToUser(userName, RMRole.Administrator.toString());
    createRMSiteMember.processEvent(mockedEvent, new StopWatch());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) RMUserAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 4 with SiteMemberData

use of org.alfresco.bm.site.SiteMemberData 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 5 with SiteMemberData

use of org.alfresco.bm.site.SiteMemberData 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)

Aggregations

SiteMemberData (org.alfresco.bm.site.SiteMemberData)17 Event (org.alfresco.bm.event.Event)13 EventResult (org.alfresco.bm.event.EventResult)12 Test (org.junit.Test)11 DBObject (com.mongodb.DBObject)8 SiteData (org.alfresco.bm.site.SiteData)8 UserData (org.alfresco.bm.user.UserData)6 RMUserAPI (org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI)3 UserModel (org.alfresco.utility.model.UserModel)3 StopWatch (org.apache.commons.lang3.time.StopWatch)3 RMSite (org.alfresco.rest.rm.community.model.site.RMSite)2 RMSiteAPI (org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI)2 Logger (org.slf4j.Logger)2 BasicDBObject (com.mongodb.BasicDBObject)1 ArrayList (java.util.ArrayList)1 FolderData (org.alfresco.bm.cm.FolderData)1 RMRole (org.alfresco.bm.dataload.rm.role.RMRole)1 EventDataObject (org.alfresco.bm.event.selector.EventDataObject)1 EventProcessorResponse (org.alfresco.bm.event.selector.EventProcessorResponse)1 RMRestWrapper (org.alfresco.rest.core.RMRestWrapper)1