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);
}
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);
}
Aggregations