use of org.alfresco.bm.user.UserData in project records-management by Alfresco.
the class LoadSingleComponentUnitTest method mockSiteAndUserData.
/**
* Helper methods
*/
/**
* Helper method for mocking user data
*/
protected void mockSiteAndUserData() {
SiteData mockedSiteData = mock(SiteData.class);
when(mockedSiteDataService.getSite(PATH_SNIPPET_RM_SITE_ID)).thenReturn(mockedSiteData);
SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
when(mockedSiteMemberData.getUsername()).thenReturn("aUser");
when(mockedSiteDataService.randomSiteMember(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, RMRole.Administrator.toString())).thenReturn(mockedSiteMemberData);
UserData mockedUserData = mock(UserData.class);
when(mockedUserData.getUsername()).thenReturn("aUser");
when(mockedUserData.getPassword()).thenReturn("aUser");
when(mockedUserDataService.findUserByUsername("aUser")).thenReturn(mockedUserData);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
when(mockedRestApiFactory.getRecordsAPI(any(UserModel.class))).thenReturn(mockedRecordsAPI);
}
use of org.alfresco.bm.user.UserData in project records-management by Alfresco.
the class PrepareRMSiteMembersUnitTest method testNoNewUsersAvailable.
@Test
public void testNoNewUsersAvailable() throws Exception {
int userCount = 2;
String user1 = "user1";
String user2 = "user2";
prepareRMSiteMembers.setRole("Administrator");
prepareRMSiteMembers.setAssignRMRoleToUsers(true);
prepareRMSiteMembers.setUserCount(userCount);
UserData mockedUserData1 = mock(UserData.class);
when(mockedUserData1.getUsername()).thenReturn(user1);
UserData mockedUserData2 = mock(UserData.class);
when(mockedUserData2.getUsername()).thenReturn(user2);
List<UserData> users = Arrays.asList(mockedUserData1, mockedUserData2);
when(mockedUserDataService.getUsersByCreationState(DataCreationState.Created, 0, 100)).thenReturn(users);
when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, 0, userCount)).thenReturn(new ArrayList<>());
SiteMemberData mockedSiteMemberData1 = mock(SiteMemberData.class);
SiteMemberData mockedSiteMemberData2 = mock(SiteMemberData.class);
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, user1)).thenReturn(mockedSiteMemberData1);
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, user2)).thenReturn(mockedSiteMemberData2);
EventResult result = prepareRMSiteMembers.processEvent(null);
verify(mockedSiteDataService, never()).addSiteMember(any(SiteMemberData.class));
assertEquals(true, result.isSuccess());
assertEquals(PrepareRMSiteMembers.NO_NEW_USERS_FOUND_MSG, result.getData());
List<Event> nextEvents = result.getNextEvents();
assertEquals(1, nextEvents.size());
assertEquals(prepareRMSiteMembers.getEventNameContinueLoadingData(), nextEvents.get(0).getName());
}
use of org.alfresco.bm.user.UserData in project records-management by Alfresco.
the class PrepareRMSiteMembersUnitTest method testAllRequestedNumeberOfUsersFound.
@Test
public void testAllRequestedNumeberOfUsersFound() throws Exception {
int userCount = 2;
String user1 = "user1";
String user2 = "user2";
prepareRMSiteMembers.setRole("Administrator");
prepareRMSiteMembers.setAssignRMRoleToUsers(true);
prepareRMSiteMembers.setUserCount(userCount);
UserData mockedUserData1 = mock(UserData.class);
when(mockedUserData1.getUsername()).thenReturn(user1);
UserData mockedUserData2 = mock(UserData.class);
when(mockedUserData2.getUsername()).thenReturn(user2);
List<UserData> users = Arrays.asList(mockedUserData1, mockedUserData2);
when(mockedUserDataService.getUsersByCreationState(DataCreationState.Created, 0, 100)).thenReturn(users);
when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, 0, userCount)).thenReturn(new ArrayList<>());
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, user1)).thenReturn(null);
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, user2)).thenReturn(null);
EventResult result = prepareRMSiteMembers.processEvent(null);
verify(mockedSiteDataService, times(2)).addSiteMember(any(SiteMemberData.class));
assertEquals(true, result.isSuccess());
assertEquals(MessageFormat.format(PrepareRMSiteMembers.PREPARED_MSG_TEMPLATE, userCount), result.getData());
List<Event> nextEvents = result.getNextEvents();
assertEquals(1, nextEvents.size());
assertEquals(prepareRMSiteMembers.getEventNameSiteMembersPrepared(), nextEvents.get(0).getName());
}
use of org.alfresco.bm.user.UserData in project records-management by Alfresco.
the class PrepareRMSiteMembersUnitTest method testLessThanRequestedNumeberOfUsersFound.
@Test
public void testLessThanRequestedNumeberOfUsersFound() throws Exception {
int userCount = 2;
String user1 = "user1";
String user2 = "user2";
prepareRMSiteMembers.setRole("Administrator");
prepareRMSiteMembers.setAssignRMRoleToUsers(true);
prepareRMSiteMembers.setUserCount(userCount);
UserData mockedUserData1 = mock(UserData.class);
when(mockedUserData1.getUsername()).thenReturn(user1);
UserData mockedUserData2 = mock(UserData.class);
when(mockedUserData2.getUsername()).thenReturn(user2);
List<UserData> users = Arrays.asList(mockedUserData1, mockedUserData2);
when(mockedUserDataService.getUsersByCreationState(DataCreationState.Created, 0, 100)).thenReturn(users);
when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, 0, userCount)).thenReturn(new ArrayList<>());
SiteMemberData mockedSiteMemberData1 = mock(SiteMemberData.class);
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, user1)).thenReturn(mockedSiteMemberData1);
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, user2)).thenReturn(null);
EventResult result = prepareRMSiteMembers.processEvent(null);
verify(mockedSiteDataService, times(1)).addSiteMember(any(SiteMemberData.class));
assertEquals(true, result.isSuccess());
assertEquals(MessageFormat.format(PrepareRMSiteMembers.PREPARED_INCOMPLETE_MSG_TEMPLATE, 1, userCount), result.getData());
List<Event> nextEvents = result.getNextEvents();
assertEquals(1, nextEvents.size());
assertEquals(prepareRMSiteMembers.getEventNameSiteMembersPrepared(), nextEvents.get(0).getName());
}
use of org.alfresco.bm.user.UserData in project records-management by Alfresco.
the class PrepareRMSiteUnitTest method testRMSiteDoesExistAndLoadedInMongoDB.
@Test
public void testRMSiteDoesExistAndLoadedInMongoDB() 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);
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("RM Site already created, continue loading data.", result.getData());
List<Event> events = result.getNextEvents();
assertEquals(1, events.size());
Event event = events.get(0);
assertEquals("scheduleFilePlanLoaders", event.getName());
DBObject data = (DBObject) event.getData();
assertNull(data);
}
Aggregations