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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations