com.silverpeas.web
Class TestResources

java.lang.Object
  extended by com.silverpeas.web.TestResources
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public abstract class TestResources
extends Object
implements org.springframework.context.ApplicationContextAware

It is a wrapper of the resources required in the RESTWebServiceTest test cases. It defines also some default parameters to use in tests such as the language of the user or the unique identifier of the user. The life-cycle of test resources is managed by the IoC container in which are bootstrapped the test cases. The class is dedicated to be extending by the test classes in order to set additional resources required by the test cases they represent. All data or behaviour to prepare for the tests have their place in a TestResources instance.


Field Summary
static String DEFAULT_DOMAIN
          The default domain the default user belongs to.
static String DEFAULT_LANGUAGE
          Default language to use in the unit tests on the REST-based web services.
static String TEST_RESOURCES_NAME
          The name under which a test resources must be deployed.
static String USER_ID_IN_TEST
          Identifier of the default user to use in the unit tests on the REST-based web services.
 
Constructor Summary
TestResources()
          Constructs the resouces for testing.
 
Method Summary
 UserDetailWithProfiles aUser()
          Gets a user to use in the tests as the one in the current HTTP session.
 UserDetailWithProfiles aUserNamed(String firstName, String lastName)
          Computes a user named with the specified first and last name.
 AccessControllerMock getAccessControllerMock()
          Gets a mock of the AccessController.
 org.springframework.context.ApplicationContext getApplicationContext()
          Gets the application context within which the current test case is actually running.
 OrganisationController getOrganizationControllerMock()
          Gets the OrganizationController mock used in the tests.
 PersonalizationService getPersonalizationServiceMock()
          Gets a mock of the personalization service.
 SessionManagerMock getSessionManagerMock()
          Gets a mock of the session management service.
 SpaceAccessControllerMock getSpaceAccessControllerMock()
          Gets a mock of the SpaceAccessController.
static TestResources getTestResources()
          Gets a TestResources instance managed by the IoC container within which is running the test case.
 PersistentResourceTokenService getTokenServiceMock()
          Gets a mock of the token service.
 UserDetail registerUser(UserDetail user)
          Registers the specified user among the organization controller so that when it is asked it is returned by the controller.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEST_RESOURCES_NAME

public static final String TEST_RESOURCES_NAME
The name under which a test resources must be deployed.

See Also:
Constant Field Values

USER_ID_IN_TEST

public static final String USER_ID_IN_TEST
Identifier of the default user to use in the unit tests on the REST-based web services.

See Also:
Constant Field Values

DEFAULT_LANGUAGE

public static final String DEFAULT_LANGUAGE
Default language to use in the unit tests on the REST-based web services.

See Also:
Constant Field Values

DEFAULT_DOMAIN

public static final String DEFAULT_DOMAIN
The default domain the default user belongs to.

See Also:
Constant Field Values
Constructor Detail

TestResources

public TestResources()
Constructs the resouces for testing. It set ups a mock of the authentication service so that the authentication succeeds with users registered by the registerUser() method. This is useful with tests on the web services.

Method Detail

getTestResources

public static TestResources getTestResources()
Gets a TestResources instance managed by the IoC container within which is running the test case.

Returns:
a bean managed TestResources.

getApplicationContext

public org.springframework.context.ApplicationContext getApplicationContext()
Gets the application context within which the current test case is actually running.

Returns:
the test case execution context (from the underlying IoC container).

getAccessControllerMock

public AccessControllerMock getAccessControllerMock()
Gets a mock of the AccessController. This mock is used to handle authorization capabilities according to the test fixture.

Returns:
mock of the access controller used in the test case.

getSpaceAccessControllerMock

public SpaceAccessControllerMock getSpaceAccessControllerMock()
Gets a mock of the SpaceAccessController. This mock is used to handle space authorization capabilities according to the test fixture.

Returns:
mock of the access controller used in the test case.

getOrganizationControllerMock

public OrganisationController getOrganizationControllerMock()
Gets the OrganizationController mock used in the tests. With this mock, you can register expected behaviours for the OrganizationController instances.

Returns:
the OrganizationController mock used in the tests.

getPersonalizationServiceMock

public PersonalizationService getPersonalizationServiceMock()
Gets a mock of the personalization service. This mock is to be used in tests. This mock is created with Mockito, so you can use it for adding some behaviour to the returned mocked service. By default, the mock is configured to returns a UserPreferences object for any user with as prefered language the french (fr).

Returns:
a mock of the PersonalizationService.

getTokenServiceMock

public PersistentResourceTokenService getTokenServiceMock()
Gets a mock of the token service. This mock is to be used in tests. This mock is created with Mockito, so you can use it for adding some behaviour to the returned mocked service. By default, the mock is configured to returns current sessionKey prefixed by "token-" as token.

Returns:
a mock of the PersonalizationService.

getSessionManagerMock

public SessionManagerMock getSessionManagerMock()
Gets a mock of the session management service. This mock is to be used in tests. This mock is used to manage the sessions of the user(s) used in tests.

Returns:
a mock of the SessionManagement.

aUser

public UserDetailWithProfiles aUser()
Gets a user to use in the tests as the one in the current HTTP session. This method is just for tests requiring only one user and whatever he's. The user in defined in the default domain (see DEFAULT_DOMAIN). The user has no profiles for any Silverpeas component instances.

Returns:
the current user in the underlying HTTP session used in the tests.

aUserNamed

public UserDetailWithProfiles aUserNamed(String firstName,
                                         String lastName)
Computes a user named with the specified first and last name. The user in defined in the default domain (see DEFAULT_DOMAIN). The user has no profiles for any Silverpeas component instances.

Parameters:
firstName - the user first name.
lastName - the user last name.
Returns:
a user.

registerUser

public UserDetail registerUser(UserDetail user)
Registers the specified user among the organization controller so that when it is asked it is returned by the controller. The unique identifier of the user is set by this method. If the user is one with profiles, then the method getUserProfile of the OrganizationController is prepared to return the expected profiles. The user token is also initialized. It equals to concatenation between "token-" and the user id.

Parameters:
user - the user to registers in the test context.
Returns:
the user itself with its identifier set.

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException


Copyright © 2016 Silverpeas. All Rights Reserved.