diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/user/AbstractUserTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/user/AbstractUserTest.java index b874e1e7f0..d7dbbdc328 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/user/AbstractUserTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/user/AbstractUserTest.java @@ -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; } }