Search in sources :

Example 1 with DecisionQueue

use of org.apache.wiki.workflow.DecisionQueue in project jspwiki by apache.

the class UserManagerTest method testSetUserProfileWithDenial.

@Test
public void testSetUserProfileWithDenial() throws Exception {
    setUpWithWorkflow();
    // First, count the number of users in the db now.
    int oldUserCount = m_db.getWikiNames().length;
    // Create a new user with random name
    WikiSession session = m_engine.guestSession();
    String loginName = "TestUser" + String.valueOf(System.currentTimeMillis());
    UserProfile profile = m_db.newProfile();
    profile.setEmail("jspwiki.tests@mailinator.com");
    profile.setLoginName(loginName);
    profile.setFullname("FullName" + loginName);
    profile.setPassword("password");
    // Because user profile saves require approvals, we will catch a Redirect
    try {
        m_mgr.setUserProfile(session, profile);
        Assert.fail("We should have caught a DecisionRequiredException caused by approval!");
    } catch (DecisionRequiredException e) {
    }
    // The user should NOT be saved yet
    Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
    // Now, look in Admin's queue, and verify there's a pending Decision there
    DecisionQueue dq = m_engine.getWorkflowManager().getDecisionQueue();
    Collection decisions = dq.getActorDecisions(m_engine.adminSession());
    Assert.assertEquals(1, decisions.size());
    // Verify that the Decision has all the facts and attributes we need
    Decision d = (Decision) decisions.iterator().next();
    List facts = d.getFacts();
    Assert.assertEquals(new Fact(UserManager.PREFS_FULL_NAME, profile.getFullname()), facts.get(0));
    Assert.assertEquals(new Fact(UserManager.PREFS_LOGIN_NAME, profile.getLoginName()), facts.get(1));
    Assert.assertEquals(new Fact(UserManager.FACT_SUBMITTER, session.getUserPrincipal().getName()), facts.get(2));
    Assert.assertEquals(new Fact(UserManager.PREFS_EMAIL, profile.getEmail()), facts.get(3));
    Assert.assertEquals(profile, d.getWorkflow().getAttribute(UserManager.SAVED_PROFILE));
    // Approve the profile
    d.decide(Outcome.DECISION_DENY);
    // Make sure the profile did NOT save
    Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
}
Also used : WikiSession(org.apache.wiki.WikiSession) UserProfile(org.apache.wiki.auth.user.UserProfile) DecisionRequiredException(org.apache.wiki.workflow.DecisionRequiredException) DecisionQueue(org.apache.wiki.workflow.DecisionQueue) Collection(java.util.Collection) List(java.util.List) Fact(org.apache.wiki.workflow.Fact) Decision(org.apache.wiki.workflow.Decision) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.Test)

Example 2 with DecisionQueue

use of org.apache.wiki.workflow.DecisionQueue in project jspwiki by apache.

the class UserManagerTest method testSetUserProfileWithApproval.

@Test
public void testSetUserProfileWithApproval() throws Exception {
    setUpWithWorkflow();
    // First, count the number of users in the db now.
    int oldUserCount = m_db.getWikiNames().length;
    // Create a new user with random name
    WikiSession session = m_engine.guestSession();
    String loginName = "TestUser" + String.valueOf(System.currentTimeMillis());
    UserProfile profile = m_db.newProfile();
    profile.setEmail("jspwiki.tests@mailinator.com");
    profile.setLoginName(loginName);
    profile.setFullname("FullName" + loginName);
    profile.setPassword("password");
    // Because user profile saves require approvals, we will catch a Redirect
    try {
        m_mgr.setUserProfile(session, profile);
        Assert.fail("We should have caught a DecisionRequiredException caused by approval!");
    } catch (DecisionRequiredException e) {
    }
    // The user should NOT be saved yet
    Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
    // Now, look in Admin's queue, and verify there's a pending Decision there
    DecisionQueue dq = m_engine.getWorkflowManager().getDecisionQueue();
    Collection decisions = dq.getActorDecisions(m_engine.adminSession());
    Assert.assertEquals(1, decisions.size());
    // Verify that the Decision has all the facts and attributes we need
    Decision d = (Decision) decisions.iterator().next();
    List facts = d.getFacts();
    Assert.assertEquals(new Fact(UserManager.PREFS_FULL_NAME, profile.getFullname()), facts.get(0));
    Assert.assertEquals(new Fact(UserManager.PREFS_LOGIN_NAME, profile.getLoginName()), facts.get(1));
    Assert.assertEquals(new Fact(UserManager.FACT_SUBMITTER, session.getUserPrincipal().getName()), facts.get(2));
    Assert.assertEquals(new Fact(UserManager.PREFS_EMAIL, profile.getEmail()), facts.get(3));
    Assert.assertEquals(profile, d.getWorkflow().getAttribute(UserManager.SAVED_PROFILE));
    // Approve the profile
    d.decide(Outcome.DECISION_APPROVE);
    // Make sure the profile saved successfully
    Assert.assertEquals(oldUserCount + 1, m_db.getWikiNames().length);
    // Now delete the profile; should be back to old count
    m_db.deleteByLoginName(loginName);
    Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
}
Also used : WikiSession(org.apache.wiki.WikiSession) UserProfile(org.apache.wiki.auth.user.UserProfile) DecisionRequiredException(org.apache.wiki.workflow.DecisionRequiredException) DecisionQueue(org.apache.wiki.workflow.DecisionQueue) Collection(java.util.Collection) List(java.util.List) Fact(org.apache.wiki.workflow.Fact) Decision(org.apache.wiki.workflow.Decision) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)2 List (java.util.List)2 WikiSession (org.apache.wiki.WikiSession)2 WikiSessionTest (org.apache.wiki.WikiSessionTest)2 UserProfile (org.apache.wiki.auth.user.UserProfile)2 Decision (org.apache.wiki.workflow.Decision)2 DecisionQueue (org.apache.wiki.workflow.DecisionQueue)2 DecisionRequiredException (org.apache.wiki.workflow.DecisionRequiredException)2 Fact (org.apache.wiki.workflow.Fact)2 Test (org.junit.Test)2