Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-7226

Be able to change session user identity in Junit4 tests at runtime in a test method

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None

      Description

      To change the session user identity in a test method use the following code:

      featuresRunner.getFeature(CoreFeature.class).getRepository().switchUser(username);

      where featuresRunner can be injected in a test field like this:

      @Inject
      protected FeaturesRunner featuresRunner;

      Note that this is a fake login. In tests no real login is done - but the session context map is used to
      inject the current login. (May be we want to change this behavior and use real login)

      There are various flavors of this method:

      switchUser(String username, boolean isAdministrator, boolean isAnonymous);

      switchSystemUser()

      switchAdminUser(String username)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bstefanescu Bogdan Stefanescu
                Reporter:
                bstefanescu Bogdan Stefanescu
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: