Fix AbstractUserTest
This commit is contained in:
parent
0fa2b5c25d
commit
a3f7339fca
1 changed files with 19 additions and 7 deletions
|
@ -2,22 +2,34 @@ package org.keycloak.testsuite.user;
|
|||
|
||||
import javax.ws.rs.core.Response;
|
||||
import static javax.ws.rs.core.Response.Status.CREATED;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.keycloak.admin.client.resource.UserResource;
|
||||
import org.keycloak.admin.client.resource.UsersResource;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.AbstractAuthTest;
|
||||
import static org.keycloak.testsuite.admin.ApiUtil.getCreatedId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.keycloak.testsuite.AbstractAuthTest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tkyjovsk
|
||||
*/
|
||||
public class AbstractUserTest extends AbstractAuthTest {
|
||||
public abstract class AbstractUserTest extends AbstractAuthTest {
|
||||
|
||||
protected UsersResource users() {
|
||||
return testRealmResource().users();
|
||||
}
|
||||
|
||||
protected UserResource user(UserRepresentation user) {
|
||||
if (user.getId()==null) {
|
||||
throw new IllegalStateException("User id cannot be null.");
|
||||
}
|
||||
return user(user.getId());
|
||||
}
|
||||
|
||||
protected UserResource user(String id) {
|
||||
return users().get(id);
|
||||
}
|
||||
|
||||
public static UserRepresentation createUserRep(String username) {
|
||||
UserRepresentation user = new UserRepresentation();
|
||||
user.setUsername(username);
|
||||
|
@ -25,16 +37,16 @@ public class AbstractUserTest extends AbstractAuthTest {
|
|||
return user;
|
||||
}
|
||||
|
||||
public String createUser(UserRepresentation user) {
|
||||
public UserRepresentation createUser(UserRepresentation user) {
|
||||
return createUser(users(), user);
|
||||
}
|
||||
|
||||
public String createUser(UsersResource users, UserRepresentation user) {
|
||||
public UserRepresentation createUser(UsersResource users, UserRepresentation user) {
|
||||
Response response = users.create(user);
|
||||
assertEquals(CREATED.getStatusCode(), response.getStatus());
|
||||
String createdId = getCreatedId(response);
|
||||
user.setId(getCreatedId(response));
|
||||
response.close();
|
||||
return createdId;
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue