com.silverpeas.web
Class RESTWebServiceTest<T extends TestResources>

java.lang.Object
  extended by com.sun.jersey.test.framework.JerseyTest
      extended by com.silverpeas.web.RESTWebServiceTest<T>
Type Parameters:
T - the test resources wrapper in use in the test cases.
Direct Known Subclasses:
ResourceCreationTest, ResourceDeletionTest, ResourceGettingTest, ResourceUpdateTest

public abstract class RESTWebServiceTest<T extends TestResources>
extends com.sun.jersey.test.framework.JerseyTest

The base class for testing REST web services in Silverpeas. This base class wraps all of the mechanismes required to prepare the environment for testing web services with Jersey and Spring in the context of Silverpeas.


Field Summary
protected static String CONTEXT_NAME
           
 
Constructor Summary
RESTWebServiceTest(String webServicePackage, String springContext)
          Constructs a new test case on the REST web service testing.
 
Method Summary
 void addComponentInstance(String componentId)
          Adds the specified component instance among the existing ones and that will be used in tests.
 void addTool(String toolId)
           
 UserDetailWithProfiles aUser()
          Gets a user to use in the test case.
 String authenticate(UserDetail theUser)
          Authenticates the user to use in the tests.
protected  javax.ws.rs.core.MultivaluedMap<String,String> buildQueryParametersFrom(String query)
           
 void denieAuthorizationToUsers()
          Denies the access to the silverpeas resources to all users.
 void denieSpaceAuthorizationToUsers()
          Denies the access to the silverpeas spaces to all users.
protected  AccessControllerMock getAccessControllerMock()
           
abstract  String[] getExistingComponentInstances()
          Gets the component instances to take into account in tests.
 String[] getExistingTools()
          Gets tools to take into account in tests.
protected  SpaceAccessControllerMock getMockedSpaceAccessController()
           
protected  OrganisationController getOrganizationControllerMock()
           
protected  PersonalizationService getPersonalizationServiceMock()
           
 T getTestResources()
          Gets the resources in use in the current test case.
 void prepareMockedResources()
           
 com.sun.jersey.api.client.WebResource resource()
           
 void setComponentAccessibilityToUser(String componentId, String userId)
           
 
Methods inherited from class com.sun.jersey.test.framework.JerseyTest
client, configure, getBaseURI, getClient, getClientFactory, getPort, getTestContainerFactory, setClientFactory, setTestContainerFactory, setUp, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_NAME

protected static final String CONTEXT_NAME
See Also:
Constant Field Values
Constructor Detail

RESTWebServiceTest

public RESTWebServiceTest(String webServicePackage,
                          String springContext)
Constructs a new test case on the REST web service testing. It bootstraps the runtime context into which the REST web service to test will run.

Parameters:
webServicePackage - the Java package in which is defined the web service to test.
springContext - the Spring context configuration file that accompanies the web service to test.
Method Detail

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. Theses 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 com.sun.jersey.api.client.WebResource resource()
Overrides:
resource in class com.sun.jersey.test.framework.JerseyTest

prepareMockedResources

public void prepareMockedResources()

authenticate

public String authenticate(UserDetail theUser)
Authenticates the user to use in the tests. The user will be added in the context of the mocked organization controller.

Parameters:
theUser - the user to authenticate.
Returns:
the key of the opened session.

aUser

public UserDetailWithProfiles aUser()
Gets a user to use in the test case. The user is managed by the test resources. So, to override it, please override the TestResources class.

Returns:
the detail about the user in use in the current test case.

denieAuthorizationToUsers

public void denieAuthorizationToUsers()
Denies the access to the silverpeas resources to all users.


denieSpaceAuthorizationToUsers

public void denieSpaceAuthorizationToUsers()
Denies the access to the silverpeas spaces to all users.


getTestResources

public T getTestResources()
Gets the resources in use in the current test case.

Returns:
a TestResources instance.

addComponentInstance

public void addComponentInstance(String componentId)
Adds the specified component instance among the existing ones and that will be used in tests.

Parameters:
componentId - the unique identifier of the component instance to use in tests.

addTool

public void addTool(String toolId)

setComponentAccessibilityToUser

public void setComponentAccessibilityToUser(String componentId,
                                            String userId)

getOrganizationControllerMock

protected OrganisationController getOrganizationControllerMock()

getAccessControllerMock

protected AccessControllerMock getAccessControllerMock()

getMockedSpaceAccessController

protected SpaceAccessControllerMock getMockedSpaceAccessController()

getPersonalizationServiceMock

protected PersonalizationService getPersonalizationServiceMock()

buildQueryParametersFrom

protected javax.ws.rs.core.MultivaluedMap<String,String> buildQueryParametersFrom(String query)


Copyright © 2016 Silverpeas. All Rights Reserved.