Package org.silverpeas.web.test
Class RESTWebServiceTest
- java.lang.Object
-
- org.silverpeas.web.test.RESTWebServiceTest
-
- Direct Known Subclasses:
ResourceCreationTest
,ResourceDeletionTest
,ResourceGettingTest
,ResourceUpdateTest
public abstract class RESTWebServiceTest extends Object
The base class for testing REST web services in Silverpeas. This base class wraps all the mechanisms required to prepare the environment for testing web services with RESTEasy and CDI in the context of Silverpeas.
-
-
Field Summary
Fields Modifier and Type Field Description DbSetupRule
dbSetupRule
-
Constructor Summary
Constructors Constructor Description RESTWebServiceTest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected javax.ws.rs.client.WebTarget
applyQueryParameters(String parameterQueryPart, javax.ws.rs.client.WebTarget resource)
String
authenticate(User user)
Authenticates the specified user through the REST-based Web API and returns the opened session identifier.void
denyAuthorizationToUsers()
Denies the access to the silverpeas resources to all users.void
denySpaceAuthorizationToUsers()
Denies the access to the silverpeas spaces to all users.protected URI
getBaseURI()
protected String
getDataSetScript()
Gets the SQL script file in the classpath that contains statements to prepare the database used by this test with a data set.abstract String[]
getExistingComponentInstances()
Gets the component instances to take into account in tests.String[]
getExistingTools()
Gets tools to take into account in tests.SilverpeasTestEnvironment
getSilverpeasEnvironmentTest()
protected String
getTableCreationScript()
Gets the SQL script file in the classpath that contains statements to create table(s) specific to this test.String
getTokenKeyOf(User theUser)
Gets (and initializes if necessary) the token key of the given user.
The user must exist into database (useSilverpeasTestEnvironment.createDefaultUser()
to add a user, and usegetSilverpeasEnvironmentTest()
to get the silverpeas environment manager instance).protected javax.ws.rs.core.UriBuilder
getWebResourceBaseURIBuilder()
Gets a URI builder initialized with the base URI at which are exposed by default all the REST web resources in Silverpeas.void
reloadAdminCaches()
javax.ws.rs.client.WebTarget
resource()
Gets an initialized web target resource instance for tests.protected javax.ws.rs.client.Invocation.Builder
setUpHTTPRequest(String uri, String mediaType, AuthId authId)
protected javax.ws.rs.client.Invocation.Builder
setUserIdent(AuthId authId, javax.ws.rs.client.Invocation.Builder http)
protected AuthId
withAsAuthId(AuthId credential)
-
-
-
Field Detail
-
dbSetupRule
public DbSetupRule dbSetupRule
-
-
Method Detail
-
reloadAdminCaches
public void reloadAdminCaches()
-
getTableCreationScript
protected String getTableCreationScript()
Gets the SQL script file in the classpath that contains statements to create table(s) specific to this test.- Returns:
- the path in the classpath of a SQL script file (or empty if no such SQL script).
-
getDataSetScript
protected String getDataSetScript()
Gets the SQL script file in the classpath that contains statements to prepare the database used by this test with a data set.- Returns:
- the path in the classpath of a SQL script file (or empty if no such SQL script)
-
getExistingComponentInstances
public abstract String[] getExistingComponentInstances()
Gets the component instances to take into account in tests. Theses component instances will be considered as existing. Others than those will be rejected with an HTTP error 404 (NOT FOUND).- Returns:
- an array with the identifier of the component instances to take into account in tests. The array cannot be null, but it can be empty.
-
getExistingTools
public String[] getExistingTools()
Gets tools to take into account in tests. These tools will be considered as existing. Others than those will be rejected with an HTTP error 404 (NOT FOUND).- Returns:
- an array with the identifier of tools to take into account in tests. The array cannot be null, but it can be empty.
-
resource
public javax.ws.rs.client.WebTarget resource()
Gets an initialized web target resource instance for tests.- Returns:
- the
WebTarget
instance.
-
getBaseURI
protected URI getBaseURI()
-
getWebResourceBaseURIBuilder
protected javax.ws.rs.core.UriBuilder getWebResourceBaseURIBuilder()
Gets a URI builder initialized with the base URI at which are exposed by default all the REST web resources in Silverpeas. This is to be used for checking URIs in returned entities in the tests.- Returns:
- an initialized
UriBuilder
-
getSilverpeasEnvironmentTest
public SilverpeasTestEnvironment getSilverpeasEnvironmentTest()
-
getTokenKeyOf
public String getTokenKeyOf(User theUser)
Gets (and initializes if necessary) the token key of the given user.
The user must exist into database (useSilverpeasTestEnvironment.createDefaultUser()
to add a user, and usegetSilverpeasEnvironmentTest()
to get the silverpeas environment manager instance).For example:
getTokenKeyOf(get().createUser());
- Parameters:
theUser
- the user to authenticate.- Returns:
- the key of the opened session.
-
denyAuthorizationToUsers
public void denyAuthorizationToUsers()
Denies the access to the silverpeas resources to all users. It sets no public both the dummy component and all the existing component instances on which the test is working. All the user roles are removed from all the component instances as well as from all of their parent spaces.
-
denySpaceAuthorizationToUsers
public void denySpaceAuthorizationToUsers()
Denies the access to the silverpeas spaces to all users.
-
authenticate
public String authenticate(User user)
Authenticates the specified user through the REST-based Web API and returns the opened session identifier. The returned session identifier can then be used in the subsequent requests sent during a test. Once the session is opened for the given user, the session cache service is then get to be set for the local thread of the current running test, so that the data prepared for the test and cached in the session cache of the user will be accessible within the thread of the tested web service.Warning: the authentication is performed by the corresponding REST-based web service and as such this one is required to be included in the deployment archive as well as all of its dependencies.
- Parameters:
user
- the user to authenticate.- Returns:
- the opened user session identifier.
-
applyQueryParameters
protected javax.ws.rs.client.WebTarget applyQueryParameters(String parameterQueryPart, javax.ws.rs.client.WebTarget resource)
-
setUserIdent
protected javax.ws.rs.client.Invocation.Builder setUserIdent(AuthId authId, javax.ws.rs.client.Invocation.Builder http)
-
-