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 SummaryFields Modifier and Type Field Description DbSetupRuledbSetupRule
 - 
Constructor SummaryConstructors Constructor Description RESTWebServiceTest()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected javax.ws.rs.client.WebTargetapplyQueryParameters(String parameterQueryPart, javax.ws.rs.client.WebTarget resource)Stringauthenticate(User user)Authenticates the specified user through the REST-based Web API and returns the opened session identifier.voiddenyAuthorizationToUsers()Denies the access to the silverpeas resources to all users.voiddenySpaceAuthorizationToUsers()Denies the access to the silverpeas spaces to all users.protected URIgetBaseURI()protected StringgetDataSetScript()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.SilverpeasTestEnvironmentgetSilverpeasEnvironmentTest()protected StringgetTableCreationScript()Gets the SQL script file in the classpath that contains statements to create table(s) specific to this test.StringgetTokenKeyOf(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.UriBuildergetWebResourceBaseURIBuilder()Gets a URI builder initialized with the base URI at which are exposed by default all the REST web resources in Silverpeas.voidreloadAdminCaches()javax.ws.rs.client.WebTargetresource()Gets an initialized web target resource instance for tests.protected javax.ws.rs.client.Invocation.BuildersetUpHTTPRequest(String uri, String mediaType, AuthId authId)protected javax.ws.rs.client.Invocation.BuildersetUserIdent(AuthId authId, javax.ws.rs.client.Invocation.Builder http)protected AuthIdwithAsAuthId(AuthId credential)
 
- 
- 
- 
Field Detail- 
dbSetupRulepublic DbSetupRule dbSetupRule 
 
- 
 - 
Method Detail- 
reloadAdminCachespublic void reloadAdminCaches() 
 - 
getTableCreationScriptprotected 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).
 
 - 
getDataSetScriptprotected 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)
 
 - 
getExistingComponentInstancespublic 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.
 
 - 
getExistingToolspublic 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.
 
 - 
resourcepublic javax.ws.rs.client.WebTarget resource() Gets an initialized web target resource instance for tests.- Returns:
- the WebTargetinstance.
 
 - 
getBaseURIprotected URI getBaseURI() 
 - 
getWebResourceBaseURIBuilderprotected 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
 
 - 
getSilverpeasEnvironmentTestpublic SilverpeasTestEnvironment getSilverpeasEnvironmentTest() 
 - 
getTokenKeyOfpublic 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.
 
 - 
denyAuthorizationToUserspublic 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.
 - 
denySpaceAuthorizationToUserspublic void denySpaceAuthorizationToUsers() Denies the access to the silverpeas spaces to all users.
 - 
authenticatepublic 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.
 
 - 
applyQueryParametersprotected javax.ws.rs.client.WebTarget applyQueryParameters(String parameterQueryPart, javax.ws.rs.client.WebTarget resource) 
 - 
setUserIdentprotected javax.ws.rs.client.Invocation.Builder setUserIdent(AuthId authId, javax.ws.rs.client.Invocation.Builder http) 
 
- 
 
-