public class FluentTestsHelper extends Object
Usage example:
new TestsHelper()
.init()
.createDirectGrantClient("direct-grant-client")
.deleteClient("direct-grant-client")
.createTestUser("seb", "seb")
.assignRoleWithUser("seb", "user")
.deleteTestUser("seb")
.deleteRole("user");
Modifier and Type | Class and Description |
---|---|
protected static class |
FluentTestsHelper.ClientData |
Modifier and Type | Field and Description |
---|---|
protected String |
accessToken |
protected String |
adminClient |
protected String |
adminPassword |
protected String |
adminRealm |
protected String |
adminUserName |
protected Map<String,FluentTestsHelper.ClientData> |
createdClients |
static String |
DEFAULT_ADMIN_CLIENT |
static String |
DEFAULT_ADMIN_PASSWORD |
static String |
DEFAULT_ADMIN_REALM |
static String |
DEFAULT_ADMIN_USERNAME |
static String |
DEFAULT_KEYCLOAK_URL |
static String |
DEFAULT_TEST_REALM |
static String |
DEFAULT_USER_ROLE |
protected boolean |
isInitialized |
protected Keycloak |
keycloak |
protected String |
keycloakBaseUrl |
protected String |
testRealm |
Constructor and Description |
---|
FluentTestsHelper()
Creates a new helper instance.
|
FluentTestsHelper(String adminUserName,
String adminPassword)
Creates a new helper instance.
|
FluentTestsHelper(String keycloakBaseUrl,
String adminUserName,
String adminPassword,
String adminRealm,
String adminClient,
String testRealm)
Creates a new helper instance.
|
Modifier and Type | Method and Description |
---|---|
FluentTestsHelper |
assignRoleWithUser(String userName,
String roleName)
Associates a user with a role.
|
FluentTestsHelper |
createClient(org.keycloak.representations.idm.ClientRepresentation clientRepresentation)
Creates a new client based on its representation.
|
FluentTestsHelper |
createDirectGrantClient(String clientId)
Creates a direct grant client.
|
FluentTestsHelper |
createTestUser(String username,
String password)
Creates a test user.
|
FluentTestsHelper |
deleteClient(String clientId)
Deletes a client previously created by this helper.
|
FluentTestsHelper |
deleteRealm(String realmName)
Deletes a realm.
|
FluentTestsHelper |
deleteRole(String roleName)
Deletes a role.
|
FluentTestsHelper |
deleteTestUser(String userName)
Deletes a user.
|
protected String |
generateInitialAccessToken() |
protected String |
getCreatedId(javax.ws.rs.core.Response response) |
protected Keycloak |
getKeycloakInstance(String keycloakBaseUrl,
String realm,
String username,
String password,
String clientId) |
String |
getToken() |
FluentTestsHelper |
importTestRealm(File realmJsonPath) |
FluentTestsHelper |
importTestRealm(InputStream stream)
Import a test realm.
|
FluentTestsHelper |
importTestRealm(String realmJsonPath) |
FluentTestsHelper |
init()
Initialization method.
|
boolean |
isInitialized() |
boolean |
returnsForbidden(String endpoint)
Checks if a given endpoint returns Forbidden HTTP Code.
|
boolean |
testGetWithAuth(String endpoint,
String token)
Checks if given endpoint returns successfully with supplied token.
|
public static final String DEFAULT_KEYCLOAK_URL
public static final String DEFAULT_ADMIN_USERNAME
public static final String DEFAULT_ADMIN_PASSWORD
public static final String DEFAULT_ADMIN_REALM
public static final String DEFAULT_ADMIN_CLIENT
public static final String DEFAULT_TEST_REALM
public static final String DEFAULT_USER_ROLE
protected final String keycloakBaseUrl
protected final String adminUserName
protected final String adminPassword
protected final String adminClient
protected final String adminRealm
protected String testRealm
protected Keycloak keycloak
protected String accessToken
protected volatile boolean isInitialized
protected Map<String,FluentTestsHelper.ClientData> createdClients
public FluentTestsHelper()
public FluentTestsHelper(String adminUserName, String adminPassword)
adminUserName
- Admin username.adminPassword
- Admin password.public FluentTestsHelper(String keycloakBaseUrl, String adminUserName, String adminPassword, String adminRealm, String adminClient, String testRealm)
keycloakBaseUrl
- Full keycloak URL.adminUserName
- Admin username.adminPassword
- Admin password.adminRealm
- Master realm name.adminClient
- Admin Client name.testRealm
- new instance.public FluentTestsHelper init()
this
public boolean isInitialized()
true
if this helper has been initialized.protected Keycloak getKeycloakInstance(String keycloakBaseUrl, String realm, String username, String password, String clientId)
protected String generateInitialAccessToken()
public FluentTestsHelper createClient(org.keycloak.representations.idm.ClientRepresentation clientRepresentation) throws ClientRegistrationException, com.fasterxml.jackson.core.JsonProcessingException
clientRepresentation
- Client data.this
ClientRegistrationException
com.fasterxml.jackson.core.JsonProcessingException
public FluentTestsHelper createDirectGrantClient(String clientId) throws ClientRegistrationException, com.fasterxml.jackson.core.JsonProcessingException
ClientRegistrationException
com.fasterxml.jackson.core.JsonProcessingException
#createClient(ClientRepresentation)}
public FluentTestsHelper deleteClient(String clientId) throws ClientRegistrationException
clientId
- Client id to be deleted.this
ClientRegistrationException
- Thrown when client registration error occurs.public FluentTestsHelper importTestRealm(String realmJsonPath) throws IOException
IOException
importTestRealm(InputStream)
public FluentTestsHelper importTestRealm(File realmJsonPath) throws IOException
IOException
importTestRealm(InputStream)
public FluentTestsHelper importTestRealm(InputStream stream) throws IOException
stream
- A stream representing a JSON file with an exported realm.this
IOException
- Thrown in case of parsing error.public FluentTestsHelper deleteRealm(String realmName)
realmName
- Realm to be deleted.this
public FluentTestsHelper createTestUser(String username, String password)
username
- A username to be created.password
- A password for a user.this
public FluentTestsHelper assignRoleWithUser(String userName, String roleName)
userName
- A username to be associated with a role.roleName
- A role to be associated with a user name.this
public FluentTestsHelper deleteRole(String roleName)
roleName
- A Role name to be deleted.this
public FluentTestsHelper deleteTestUser(String userName)
userName
- A Username to be deleted.this
protected String getCreatedId(javax.ws.rs.core.Response response)
public boolean testGetWithAuth(String endpoint, String token) throws IOException
endpoint
- Endpoint to be evaluated,token
- Token that will be passed into the Authorization
header.true
if the endpoint returns forbidden.IOException
- Thrown by the underlying HTTP Client implementationpublic boolean returnsForbidden(String endpoint) throws IOException
endpoint
- Endpoint to be evaluated,true
if the endpoint returns forbidden.IOException
- Thrown by the underlying HTTP Client implementationpublic String getToken()
Copyright © 2020 JBoss by Red Hat. All rights reserved.