Search in sources :

Example 11 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserSearchServiceTest method shouldSearchForUsers.

@Test
public void shouldSearchForUsers() throws Exception {
    User foo = new User("foo", new ArrayList<>(), "foo@cruise.com", false);
    User bar = new User("bar-foo", new ArrayList<>(), "bar@go.com", true);
    when(ldapUserSearch.search("foo")).thenReturn(Arrays.asList(foo, bar));
    List<UserSearchModel> models = userSearchService.search("foo", new HttpLocalizedOperationResult());
    assertThat(models, is(Arrays.asList(new UserSearchModel(foo, UserSourceType.LDAP), new UserSearchModel(bar, UserSourceType.LDAP))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) User(com.thoughtworks.go.domain.User) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Example 12 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserServiceIntegrationTest method shouldReturnErrorWhenTryingToAddAnonymousUser.

@Test
public void shouldReturnErrorWhenTryingToAddAnonymousUser() throws Exception {
    UserSearchModel anonymous = new UserSearchModel(new User(CaseInsensitiveString.str(Username.ANONYMOUS.getUsername()), "Mr. Anonymous", "anon@cruise.com"), UserSourceType.LDAP);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.create(Arrays.asList(anonymous), result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Failed to add user. Username 'anonymous' is not permitted."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Example 13 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserServiceIntegrationTest method shouldCreateANewUser.

@Test
public void shouldCreateANewUser() throws Exception {
    UserSearchModel foo = new UserSearchModel(new User("fooUser", "Mr Foo", "foo@cruise.com"), UserSourceType.LDAP);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.create(Arrays.asList(foo), result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.message(localizer), is("User 'fooUser' successfully added."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Example 14 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserServiceIntegrationTest method shouldDeleteAllUsers.

@Test
public void shouldDeleteAllUsers() throws Exception {
    UserSearchModel foo = new UserSearchModel(new User("fooUser", "Mr Foo", "foo@cruise.com"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.create(Arrays.asList(foo), result);
    assertThat(userService.allUsersForDisplay(UserService.SortableColumn.EMAIL, UserService.SortDirection.ASC).size(), is(1));
    userService.deleteAll();
    assertThat(userService.allUsersForDisplay(UserService.SortableColumn.EMAIL, UserService.SortDirection.ASC).size(), is(0));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Example 15 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserServiceTest method shouldAllowCreateNewUsersFromPasswordFileWithoutEmailAddress.

@Test
public void shouldAllowCreateNewUsersFromPasswordFileWithoutEmailAddress() throws Exception {
    UserSearchModel passwordUser = new UserSearchModel(new User("passwordUser"), UserSourceType.PASSWORD_FILE);
    doNothing().when(userDao).saveOrUpdate(passwordUser.getUser());
    when(userDao.findUser("passwordUser")).thenReturn(new NullUser());
    when(userDao.enabledUserCount()).thenReturn(10);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.create(Arrays.asList(passwordUser), result);
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Aggregations

UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)16 Test (org.junit.Test)16 User (com.thoughtworks.go.domain.User)6 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1