Search in sources :

Example 6 with UserData

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);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) UserModel(org.alfresco.utility.model.UserModel) SiteMemberData(org.alfresco.bm.site.SiteMemberData) UserData(org.alfresco.bm.user.UserData)

Example 7 with UserData

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());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 8 with UserData

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());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 9 with UserData

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());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 10 with UserData

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

Aggregations

UserData (org.alfresco.bm.user.UserData)14 Event (org.alfresco.bm.event.Event)11 EventResult (org.alfresco.bm.event.EventResult)11 Test (org.junit.Test)9 SiteMemberData (org.alfresco.bm.site.SiteMemberData)7 UserModel (org.alfresco.utility.model.UserModel)7 DBObject (com.mongodb.DBObject)6 SiteData (org.alfresco.bm.site.SiteData)6 People (org.alfresco.rest.requests.People)4 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)4 ArrayList (java.util.ArrayList)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 RMRole (org.alfresco.bm.dataload.rm.role.RMRole)1 Logger (org.slf4j.Logger)1