Fix AbstractUserTest

This commit is contained in:
Tomas Kyjovsky 2016-02-26 14:57:28 +01:00
parent 0fa2b5c25d
commit a3f7339fca

View file

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