This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 6d324825b99004f3df56ca11f085e753cdd7a3ad Author: juanpablo <[email protected]> AuthorDate: Sat Apr 11 18:08:29 2020 +0200 format tests + add some fixes suggested by intellij --- .../apache/wiki/workflow/ApprovalWorkflowTest.java | 9 +- .../apache/wiki/workflow/DecisionQueueTest.java | 14 +- .../java/org/apache/wiki/workflow/FactTest.java | 30 +- .../apache/wiki/workflow/SimpleDecisionTest.java | 181 +++++------ .../apache/wiki/workflow/WorkflowManagerTest.java | 96 +++--- .../org/apache/wiki/workflow/WorkflowTest.java | 338 +++++++++------------ 6 files changed, 287 insertions(+), 381 deletions(-) diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java index d5772d5..7f25b9e 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java @@ -75,7 +75,6 @@ public class ApprovalWorkflowTest { final Workflow w = m_builder.buildApprovalWorkflow(submitter, workflowApproverKey, prepTask, decisionKey, facts, completionTask, rejectedMessageKey); - w.setWorkflowManager( m_engine.getManager( WorkflowManager.class ) ); // Check to see if the workflow built correctly Assertions.assertFalse( w.isStarted() || w.isCompleted() || w.isAborted() ); @@ -83,7 +82,6 @@ public class ApprovalWorkflowTest { Assertions.assertEquals( "workflow.approvalWorkflow", w.getMessageKey() ); Assertions.assertEquals( Workflow.CREATED, w.getCurrentState() ); Assertions.assertEquals( new WikiPrincipal("Submitter"), w.getOwner() ); - Assertions.assertEquals( m_engine.getManager( WorkflowManager.class ), w.getWorkflowManager() ); Assertions.assertEquals( 0, w.getHistory().size() ); // Our dummy "task complete" attributes should still be null @@ -146,10 +144,9 @@ public class ApprovalWorkflowTest { final Task completionTask = new TestPrepTask( "task.saveWikiPage" ); final String rejectedMessageKey = "notification.saveWikiPage.reject"; - final Workflow w = m_builder.buildApprovalWorkflow(submitter, workflowApproverKey, - prepTask, decisionKey, facts, - completionTask, rejectedMessageKey); - w.setWorkflowManager( m_engine.getManager( WorkflowManager.class ) ); + final Workflow w = m_builder.buildApprovalWorkflow( submitter, workflowApproverKey, + prepTask, decisionKey, facts, + completionTask, rejectedMessageKey ); // Start the workflow w.start(); diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/DecisionQueueTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/DecisionQueueTest.java index 0f3eab4..9ac1201 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/DecisionQueueTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/DecisionQueueTest.java @@ -29,12 +29,10 @@ import org.junit.jupiter.api.Test; import java.security.Principal; import java.util.Collection; -import java.util.Properties; -public class DecisionQueueTest -{ +public class DecisionQueueTest { - TestEngine m_engine; + TestEngine m_engine = TestEngine.build(); DecisionQueue m_queue; @@ -51,16 +49,11 @@ public class DecisionQueueTest Session adminSession; @BeforeEach - public void setUp() throws Exception - { - - final Properties props = TestEngine.getTestProperties(); - m_engine = new TestEngine(props); + public void setUp() throws Exception { m_queue = m_engine.getManager( WorkflowManager.class ).getDecisionQueue(); adminSession = m_engine.adminSession(); janneSession = m_engine.janneSession(); w = new Workflow("workflow.key", new WikiPrincipal("Owner1")); - w.setWorkflowManager( m_engine.getManager( WorkflowManager.class ) ); d1 = new SimpleDecision(w, "decision1.key", new GroupPrincipal("Admin")); d2 = new SimpleDecision(w, "decision2.key", new WikiPrincipal("Owner2")); d3 = new SimpleDecision(w, "decision3.key", janneSession.getUserPrincipal()); @@ -168,7 +161,6 @@ public class DecisionQueueTest // Create a workflow with 3 steps, with a Decision for Janne in the middle w = new Workflow("workflow.key", new WikiPrincipal("Owner1")); - w.setWorkflowManager( m_engine.getManager( WorkflowManager.class ) ); final Step startTask = new TaskTest.NormalTask(w); final Step endTask = new TaskTest.NormalTask(w); final Decision decision = new SimpleDecision(w, "decision.Actor1Decision", janne); diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/FactTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/FactTest.java index ea0aaf1..ba73065 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/FactTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/FactTest.java @@ -18,27 +18,25 @@ */ package org.apache.wiki.workflow; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; -public class FactTest -{ +public class FactTest { @Test - public void testCreate() - { - Fact f1 = new Fact("fact1",new Integer(1)); - Fact f2 = new Fact("fact2","A factual String"); - Fact f3 = new Fact("fact3",Outcome.DECISION_ACKNOWLEDGE); - - Assertions.assertEquals("fact1", f1.getMessageKey()); - Assertions.assertEquals("fact2", f2.getMessageKey()); - Assertions.assertEquals("fact3", f3.getMessageKey()); - - Assertions.assertEquals(new Integer(1), f1.getValue()); - Assertions.assertEquals("A factual String", f2.getValue()); - Assertions.assertEquals(Outcome.DECISION_ACKNOWLEDGE, f3.getValue()); + public void testCreate() { + final Fact f1 = new Fact( "fact1", 1 ); + final Fact f2 = new Fact( "fact2", "A factual String" ); + final Fact f3 = new Fact( "fact3", Outcome.DECISION_ACKNOWLEDGE ); + + Assertions.assertEquals( "fact1", f1.getMessageKey() ); + Assertions.assertEquals( "fact2", f2.getMessageKey() ); + Assertions.assertEquals( "fact3", f3.getMessageKey() ); + + Assertions.assertEquals( 1, f1.getValue() ); + Assertions.assertEquals( "A factual String", f2.getValue() ); + Assertions.assertEquals( Outcome.DECISION_ACKNOWLEDGE, f3.getValue() ); } } diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/SimpleDecisionTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/SimpleDecisionTest.java index a2c11b5..409e40d 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/SimpleDecisionTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/SimpleDecisionTest.java @@ -18,186 +18,165 @@ */ package org.apache.wiki.workflow; -import java.util.Collection; -import java.util.List; - import org.apache.wiki.api.exceptions.WikiException; import org.apache.wiki.auth.WikiPrincipal; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class SimpleDecisionTest -{ +import java.util.Collection; +import java.util.List; + + +public class SimpleDecisionTest { Workflow m_workflow; Decision m_decision; @BeforeEach - public void setUp() throws Exception - { - - m_workflow = new Workflow("workflow.key", new WikiPrincipal("Owner1")); - m_decision = new SimpleDecision(m_workflow, "decision.key", new WikiPrincipal("Actor1")); + public void setUp() throws Exception { + m_workflow = new Workflow( "workflow.key", new WikiPrincipal( "Owner1" ) ); + m_decision = new SimpleDecision( m_workflow, "decision.key", new WikiPrincipal( "Actor1" ) ); } @Test - public void testAddFacts() - { - Fact f1 = new Fact("fact1",new Integer(1)); - Fact f2 = new Fact("fact2","A factual String"); - Fact f3 = new Fact("fact3",Outcome.DECISION_ACKNOWLEDGE); - m_decision.addFact(f1); - m_decision.addFact(f2); - m_decision.addFact(f3); + public void testAddFacts() { + final Fact f1 = new Fact( "fact1", Integer.valueOf( 1 ) ); + final Fact f2 = new Fact( "fact2", "A factual String" ); + final Fact f3 = new Fact( "fact3", Outcome.DECISION_ACKNOWLEDGE ); + m_decision.addFact( f1 ); + m_decision.addFact( f2 ); + m_decision.addFact( f3 ); // The facts should be available, and returned in order - List< Fact > facts = m_decision.getFacts(); - Assertions.assertEquals(f1, facts.get(0)); - Assertions.assertEquals(f2, facts.get(1)); - Assertions.assertEquals(f3, facts.get(2)); + final List< Fact > facts = m_decision.getFacts(); + Assertions.assertEquals( f1, facts.get( 0 ) ); + Assertions.assertEquals( f2, facts.get( 1 ) ); + Assertions.assertEquals( f3, facts.get( 2 ) ); } @Test - public void testGetActor() - { - Assertions.assertEquals(new WikiPrincipal("Actor1"), m_decision.getActor()); + public void testGetActor() { + Assertions.assertEquals( new WikiPrincipal( "Actor1" ), m_decision.getActor() ); } @Test - public void testGetDefaultOutcome() - { - Assertions.assertEquals(Outcome.DECISION_APPROVE, m_decision.getDefaultOutcome()); + public void testGetDefaultOutcome() { + Assertions.assertEquals( Outcome.DECISION_APPROVE, m_decision.getDefaultOutcome() ); } @Test - public void testIsReassignable() - { - Assertions.assertTrue(m_decision.isReassignable()); + public void testIsReassignable() { + Assertions.assertTrue( m_decision.isReassignable() ); } @Test - public void testReassign() - { - m_decision.reassign(new WikiPrincipal("Actor2")); - Assertions.assertEquals(new WikiPrincipal("Actor2"), m_decision.getActor()); + public void testReassign() { + m_decision.reassign( new WikiPrincipal( "Actor2" ) ); + Assertions.assertEquals( new WikiPrincipal( "Actor2" ), m_decision.getActor() ); } @Test - public void testSuccessors() - { + public void testSuccessors() { // If the decision is approved, branch to another decision (d2) - Step d2 = new SimpleDecision(m_workflow, "decision2.key", new WikiPrincipal("Actor1")); - m_decision.addSuccessor(Outcome.DECISION_APPROVE, d2); + final Step d2 = new SimpleDecision( m_workflow, "decision2.key", new WikiPrincipal( "Actor1" ) ); + m_decision.addSuccessor( Outcome.DECISION_APPROVE, d2 ); // If the decision is denied, branch to another decision (d3) - Step d3 = new SimpleDecision(m_workflow, "decision3.key", new WikiPrincipal("Actor1")); - m_decision.addSuccessor(Outcome.DECISION_DENY, d3); + final Step d3 = new SimpleDecision( m_workflow, "decision3.key", new WikiPrincipal( "Actor1" ) ); + m_decision.addSuccessor( Outcome.DECISION_DENY, d3 ); - Assertions.assertEquals(d2, m_decision.getSuccessor(Outcome.DECISION_APPROVE)); - Assertions.assertEquals(d3, m_decision.getSuccessor(Outcome.DECISION_DENY)); + Assertions.assertEquals( d2, m_decision.getSuccessor( Outcome.DECISION_APPROVE ) ); + Assertions.assertEquals( d3, m_decision.getSuccessor( Outcome.DECISION_DENY ) ); // The other Outcomes should return null when looked up - Assertions.assertNull(m_decision.getSuccessor(Outcome.DECISION_HOLD)); - Assertions.assertNull(m_decision.getSuccessor(Outcome.DECISION_REASSIGN)); - Assertions.assertNull(m_decision.getSuccessor(Outcome.STEP_ABORT)); + Assertions.assertNull( m_decision.getSuccessor( Outcome.DECISION_HOLD ) ); + Assertions.assertNull( m_decision.getSuccessor( Outcome.DECISION_REASSIGN ) ); + Assertions.assertNull( m_decision.getSuccessor( Outcome.STEP_ABORT ) ); } @Test - public void testErrors() - { - m_decision.addError("Error deciding something."); - m_decision.addError("Error deciding something else."); + public void testErrors() { + m_decision.addError( "Error deciding something." ); + m_decision.addError( "Error deciding something else." ); - List< String > errors = m_decision.getErrors(); - Assertions.assertEquals(2, errors.size()); - Assertions.assertEquals("Error deciding something.", errors.get(0)); - Assertions.assertEquals("Error deciding something else.", errors.get(1)); + final List< String > errors = m_decision.getErrors(); + Assertions.assertEquals( 2, errors.size() ); + Assertions.assertEquals( "Error deciding something.", errors.get( 0 ) ); + Assertions.assertEquals( "Error deciding something else.", errors.get( 1 ) ); } @Test - public void testAvailableOutcomes() - { - Collection< Outcome > outcomes = m_decision.getAvailableOutcomes(); - Assertions.assertTrue(outcomes.contains(Outcome.DECISION_APPROVE)); - Assertions.assertTrue(outcomes.contains(Outcome.DECISION_DENY)); - Assertions.assertFalse(outcomes.contains(Outcome.DECISION_HOLD)); - Assertions.assertFalse(outcomes.contains(Outcome.DECISION_REASSIGN)); - Assertions.assertFalse(outcomes.contains(Outcome.STEP_ABORT)); - Assertions.assertFalse(outcomes.contains(Outcome.STEP_COMPLETE)); + public void testAvailableOutcomes() { + final Collection< Outcome > outcomes = m_decision.getAvailableOutcomes(); + Assertions.assertTrue( outcomes.contains( Outcome.DECISION_APPROVE ) ); + Assertions.assertTrue( outcomes.contains( Outcome.DECISION_DENY ) ); + Assertions.assertFalse( outcomes.contains( Outcome.DECISION_HOLD ) ); + Assertions.assertFalse( outcomes.contains( Outcome.DECISION_REASSIGN ) ); + Assertions.assertFalse( outcomes.contains( Outcome.STEP_ABORT ) ); + Assertions.assertFalse( outcomes.contains( Outcome.STEP_COMPLETE ) ); } @Test - public void testGetEndTime() throws WikiException - { - Assertions.assertEquals(Workflow.TIME_NOT_SET, m_decision.getEndTime()); + public void testGetEndTime() throws WikiException { + Assertions.assertEquals( Workflow.TIME_NOT_SET, m_decision.getEndTime() ); m_decision.start(); - m_decision.decide(Outcome.DECISION_APPROVE); - Assertions.assertTrue((Workflow.TIME_NOT_SET != m_decision.getEndTime())); + m_decision.decide( Outcome.DECISION_APPROVE ); + Assertions.assertTrue( ( Workflow.TIME_NOT_SET != m_decision.getEndTime() ) ); } @Test - public void testGetMessageKey() - { - Assertions.assertEquals("decision.key",m_decision.getMessageKey()); + public void testGetMessageKey() { + Assertions.assertEquals( "decision.key", m_decision.getMessageKey() ); } @Test - public void testGetOutcome() throws WikiException - { - Assertions.assertEquals(Outcome.STEP_CONTINUE,m_decision.getOutcome()); + public void testGetOutcome() throws WikiException { + Assertions.assertEquals( Outcome.STEP_CONTINUE, m_decision.getOutcome() ); m_decision.start(); - m_decision.decide(Outcome.DECISION_APPROVE); - Assertions.assertEquals(Outcome.DECISION_APPROVE, m_decision.getOutcome()); + m_decision.decide( Outcome.DECISION_APPROVE ); + Assertions.assertEquals( Outcome.DECISION_APPROVE, m_decision.getOutcome() ); } @Test - public void testGetStartTime() throws WikiException - { - Assertions.assertEquals(Workflow.TIME_NOT_SET, m_decision.getStartTime()); + public void testGetStartTime() throws WikiException { + Assertions.assertEquals( Workflow.TIME_NOT_SET, m_decision.getStartTime() ); m_decision.start(); - m_decision.decide(Outcome.DECISION_APPROVE); - Assertions.assertTrue((Workflow.TIME_NOT_SET != m_decision.getStartTime())); + m_decision.decide( Outcome.DECISION_APPROVE ); + Assertions.assertTrue( ( Workflow.TIME_NOT_SET != m_decision.getStartTime() ) ); } @Test - public void testGetWorkflow() - { - Assertions.assertEquals(m_workflow, m_decision.getWorkflow()); + public void testGetWorkflow() { + Assertions.assertEquals( m_workflow, m_decision.getWorkflow() ); } @Test - public void testIsCompleted() throws WikiException - { - Assertions.assertFalse(m_decision.isCompleted()); + public void testIsCompleted() throws WikiException { + Assertions.assertFalse( m_decision.isCompleted() ); m_decision.start(); - m_decision.decide(Outcome.DECISION_APPROVE); - Assertions.assertTrue(m_decision.isCompleted()); + m_decision.decide( Outcome.DECISION_APPROVE ); + Assertions.assertTrue( m_decision.isCompleted() ); } @Test - public void testIsStarted() throws WikiException - { - Assertions.assertFalse(m_decision.isStarted()); + public void testIsStarted() throws WikiException { + Assertions.assertFalse( m_decision.isStarted() ); m_decision.start(); - Assertions.assertTrue(m_decision.isStarted()); + Assertions.assertTrue( m_decision.isStarted() ); } @Test - public void testStartTwice() throws WikiException - { + public void testStartTwice() throws WikiException { m_decision.start(); - try - { + try { m_decision.start(); - } - catch (IllegalStateException e) - { + } catch( final IllegalStateException e ) { // Swallow return; } // We should never get here - Assertions.fail("Decision allowed itself to be started twice!"); + Assertions.fail( "Decision allowed itself to be started twice!" ); } } diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowManagerTest.java index f6b8a19..2597ca9 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowManagerTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowManagerTest.java @@ -27,96 +27,84 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.Properties; -public class WorkflowManagerTest -{ +public class WorkflowManagerTest { + protected Workflow w; protected WorkflowManager wm; - protected WikiEngine m_engine; + protected WikiEngine m_engine = TestEngine.build(); @BeforeEach - public void setUp() throws Exception - { - final Properties props = TestEngine.getTestProperties(); - m_engine = new TestEngine(props); + public void setUp() throws Exception { wm = m_engine.getManager( WorkflowManager.class ); // Create a workflow with 3 steps, with a Decision in the middle - w = new Workflow("workflow.key", new WikiPrincipal("Owner1")); - w.setWorkflowManager( m_engine.getManager( WorkflowManager.class ) ); - final Step startTask = new TaskTest.NormalTask(w); - final Step endTask = new TaskTest.NormalTask(w); - final Decision decision = new SimpleDecision(w, "decision.editWikiApproval", new WikiPrincipal("Actor1")); - startTask.addSuccessor(Outcome.STEP_COMPLETE, decision); - decision.addSuccessor(Outcome.DECISION_APPROVE, endTask); - w.setFirstStep(startTask); + w = new Workflow( "workflow.key", new WikiPrincipal( "Owner1" ) ); + final Step startTask = new TaskTest.NormalTask( w ); + final Step endTask = new TaskTest.NormalTask( w ); + final Decision decision = new SimpleDecision( w, "decision.editWikiApproval", new WikiPrincipal( "Actor1" ) ); + startTask.addSuccessor( Outcome.STEP_COMPLETE, decision ); + decision.addSuccessor( Outcome.DECISION_APPROVE, endTask ); + w.setFirstStep( startTask ); // Add a message argument to the workflow with the page name - w.addMessageArgument("MyPage"); + w.addMessageArgument( "MyPage" ); } @Test - public void testStart() throws WikiException - { + public void testStart() throws WikiException { // Once we start the workflow, it should show that it's started // and the WM should have assigned it an ID - Assertions.assertEquals(Workflow.ID_NOT_SET, w.getId()); - Assertions.assertFalse(w.isStarted()); - wm.start(w); - Assertions.assertFalse(Workflow.ID_NOT_SET == w.getId()); - Assertions.assertTrue(w.isStarted()); + Assertions.assertEquals( Workflow.ID_NOT_SET, w.getId() ); + Assertions.assertFalse( w.isStarted() ); + wm.start( w ); + Assertions.assertNotEquals( Workflow.ID_NOT_SET, w.getId() ); + Assertions.assertTrue( w.isStarted() ); } @Test - public void testWorkflows() throws WikiException - { + public void testWorkflows() throws WikiException { // There should be no workflows in the cache, and none in completed list - Assertions.assertEquals(0, wm.getWorkflows().size()); - Assertions.assertEquals(0, wm.getCompletedWorkflows().size()); + Assertions.assertEquals( 0, wm.getWorkflows().size() ); + Assertions.assertEquals( 0, wm.getCompletedWorkflows().size() ); // After starting, there should be 1 in the cache, with ID=1 - wm.start(w); - Assertions.assertEquals(1, wm.getWorkflows().size()); - Assertions.assertEquals(0, wm.getCompletedWorkflows().size()); - final Workflow workflow = (Workflow)wm.getWorkflows().iterator().next(); - Assertions.assertEquals(w, workflow); - Assertions.assertEquals(1, workflow.getId()); + wm.start( w ); + Assertions.assertEquals( 1, wm.getWorkflows().size() ); + Assertions.assertEquals( 0, wm.getCompletedWorkflows().size() ); + final Workflow workflow = wm.getWorkflows().iterator().next(); + Assertions.assertEquals( w, workflow ); + Assertions.assertEquals( 1, workflow.getId() ); // After forcing a decision on step 2, the workflow should complete and vanish from the cache - final Decision d = (Decision)w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertEquals(0, wm.getWorkflows().size()); - Assertions.assertEquals(1, wm.getCompletedWorkflows().size()); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertEquals( 0, wm.getWorkflows().size() ); + Assertions.assertEquals( 1, wm.getCompletedWorkflows().size() ); } @Test - public void testRequiresApproval() - { + public void testRequiresApproval() { // Test properties says we need approvals for workflow.saveWikiPage & workflow.foo - Assertions.assertFalse(wm.requiresApproval("workflow.saveWikiPage")); - Assertions.assertTrue(wm.requiresApproval("workflow.foo")); - Assertions.assertTrue(wm.requiresApproval("workflow.bar")); + Assertions.assertFalse( wm.requiresApproval( "workflow.saveWikiPage" ) ); + Assertions.assertTrue( wm.requiresApproval( "workflow.foo" ) ); + Assertions.assertTrue( wm.requiresApproval( "workflow.bar" ) ); } @Test - public void testGetApprover() throws WikiException - { + public void testGetApprover() throws WikiException { // Test properties says workflow.saveWikiPage approver is GP Admin; workflow.foo is 'janne' - Assertions.assertEquals(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME), wm.getApprover("workflow.foo")); - Assertions.assertEquals(new GroupPrincipal("Admin"), wm.getApprover("workflow.bar")); + Assertions.assertEquals( new WikiPrincipal( "janne", WikiPrincipal.LOGIN_NAME ), wm.getApprover( "workflow.foo" ) ); + Assertions.assertEquals( new GroupPrincipal( "Admin" ), wm.getApprover( "workflow.bar" ) ); // 'saveWikiPage' workflow doesn't require approval, so we will need to catch an Exception - try - { - Assertions.assertEquals(new GroupPrincipal("Admin"), wm.getApprover("workflow.saveWikiPage")); - } - catch ( final WikiException e) - { + try { + Assertions.assertEquals( new GroupPrincipal( "Admin" ), wm.getApprover( "workflow.saveWikiPage" ) ); + } catch( final WikiException e ) { // Swallow return; } // We should never get here - Assertions.fail("Workflow.bar doesn't need approval!"); + Assertions.fail( "Workflow.bar doesn't need approval!" ); } } diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowTest.java index 7b9850d..d600e0b 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowTest.java @@ -29,8 +29,9 @@ import java.math.BigDecimal; import java.security.Principal; import java.util.Date; -public class WorkflowTest -{ + +public class WorkflowTest { + Workflow w; Task initTask; @@ -42,370 +43,321 @@ public class WorkflowTest String ATTR = "TestAttribute"; @BeforeEach - public void setUp() throws Exception - { + public void setUp() throws Exception { // Create workflow; owner is test user - w = new Workflow("workflow.myworkflow", new WikiPrincipal("Owner1")); + w = new Workflow( "workflow.myworkflow", new WikiPrincipal( "Owner1" ) ); // Create custom initialization task - initTask = new TaskTest.NormalTask(w); + initTask = new TaskTest.NormalTask( w ); // Create finish task - finishTask = new TaskTest.NormalTask(w); + finishTask = new TaskTest.NormalTask( w ); // Create an intermetidate decision step - Principal actor = new GroupPrincipal("Admin"); - decision = new SimpleDecision(w, "decision.AdminDecision", actor); + final Principal actor = new GroupPrincipal( "Admin" ); + decision = new SimpleDecision( w, "decision.AdminDecision", actor ); // Hook the steps together - initTask.addSuccessor(Outcome.STEP_COMPLETE, decision); - decision.addSuccessor(Outcome.DECISION_APPROVE, finishTask); + initTask.addSuccessor( Outcome.STEP_COMPLETE, decision ); + decision.addSuccessor( Outcome.DECISION_APPROVE, finishTask ); // Stash page name as message attribute - w.addMessageArgument("MyPage"); + w.addMessageArgument( "MyPage" ); // Set workflow's first step - w.setFirstStep(initTask); + w.setFirstStep( initTask ); } @Test - public void testWorkflow() - { + public void testWorkflow() { // Make sure everything is set to their proper default values - Assertions.assertNull(w.getCurrentStep()); - Assertions.assertNull(w.getCurrentActor()); - Assertions.assertEquals(0, w.getHistory().size()); - Assertions.assertEquals(Workflow.ID_NOT_SET, w.getId()); - Assertions.assertNull(w.getWorkflowManager()); - Assertions.assertEquals(new WikiPrincipal("Owner1"), w.getOwner()); - Assertions.assertEquals(Workflow.CREATED, w.getCurrentState()); - Assertions.assertEquals(Workflow.TIME_NOT_SET, w.getStartTime()); - Assertions.assertEquals(Workflow.TIME_NOT_SET, w.getEndTime()); - } - - @Test - public void testSetWorkflowManager() - { - Assertions.assertNull(w.getWorkflowManager()); - WorkflowManager m = new DefaultWorkflowManager(); - w.setWorkflowManager(m); - Assertions.assertEquals(m, w.getWorkflowManager()); + Assertions.assertNull( w.getCurrentStep() ); + Assertions.assertNull( w.getCurrentActor() ); + Assertions.assertEquals( 0, w.getHistory().size() ); + Assertions.assertEquals( Workflow.ID_NOT_SET, w.getId() ); + Assertions.assertEquals( new WikiPrincipal( "Owner1" ), w.getOwner() ); + Assertions.assertEquals( Workflow.CREATED, w.getCurrentState() ); + Assertions.assertEquals( Workflow.TIME_NOT_SET, w.getStartTime() ); + Assertions.assertEquals( Workflow.TIME_NOT_SET, w.getEndTime() ); } @Test - public void testGetSetAttribute() - { - Assertions.assertNull(w.getAttribute(ATTR)); - w.setAttribute(ATTR, "Test String"); - Assertions.assertNotNull(w.getAttribute(ATTR)); - Assertions.assertEquals("Test String", w.getAttribute(ATTR)); + public void testGetSetAttribute() { + Assertions.assertNull( w.getAttribute( ATTR ) ); + w.setAttribute( ATTR, "Test String" ); + Assertions.assertNotNull( w.getAttribute( ATTR ) ); + Assertions.assertEquals( "Test String", w.getAttribute( ATTR ) ); } @Test - public void testGetMessageArgs() throws WikiException - { + public void testGetMessageArgs() throws WikiException { Object[] args; // Before start, arg1=Owner1, arg2=- (no current actor), arg3=MyPage args = w.getMessageArguments(); - Assertions.assertEquals("Owner1", args[0]); - Assertions.assertEquals("-", args[1]); - Assertions.assertEquals("MyPage", args[2]); + Assertions.assertEquals( "Owner1", args[ 0 ] ); + Assertions.assertEquals( "-", args[ 1 ] ); + Assertions.assertEquals( "MyPage", args[ 2 ] ); // After start (at Decision), arg1=Owner1, arg2=Admin, arg3=MyPage w.start(); args = w.getMessageArguments(); - Assertions.assertEquals("Owner1", args[0]); - Assertions.assertEquals("Admin", args[1]); - Assertions.assertEquals("MyPage", args[2]); + Assertions.assertEquals( "Owner1", args[ 0 ] ); + Assertions.assertEquals( "Admin", args[ 1 ] ); + Assertions.assertEquals( "MyPage", args[ 2 ] ); // After end, arg1=Owner1, arg2=-, arg3=MyPage - decision.decide(Outcome.DECISION_APPROVE); + decision.decide( Outcome.DECISION_APPROVE ); args = w.getMessageArguments(); - Assertions.assertEquals("Owner1", args[0]); - Assertions.assertEquals("-", args[1]); - Assertions.assertEquals("MyPage", args[2]); + Assertions.assertEquals( "Owner1", args[ 0 ] ); + Assertions.assertEquals( "-", args[ 1 ] ); + Assertions.assertEquals( "MyPage", args[ 2 ] ); } @Test - public void testGetMessageArgObjects() - { + public void testGetMessageArgObjects() { // Try passing some valid object types: Date, Number - w.addMessageArgument(new Date()); - w.addMessageArgument(new Integer(1)); - w.addMessageArgument(new Double(2)); - w.addMessageArgument(new BigDecimal(3.14)); + w.addMessageArgument( new Date() ); + w.addMessageArgument( Integer.valueOf( 1 ) ); + w.addMessageArgument( 2d ); + w.addMessageArgument( new BigDecimal( "3.14" ) ); // Try passing an invalid one: e.g., a Workflow (it should Assertions.fail) - try - { - w.addMessageArgument(w); - } - catch (IllegalArgumentException e) - { + try { + w.addMessageArgument( w ); + } catch( final IllegalArgumentException e ) { // Swallow return; } // We should never get here - Assertions.fail("Illegal argument passed..."); + Assertions.fail( "Illegal argument passed..." ); } @Test - public void testGetMessageKey() - { - Assertions.assertEquals("workflow.myworkflow", w.getMessageKey()); + public void testGetMessageKey() { + Assertions.assertEquals( "workflow.myworkflow", w.getMessageKey() ); } @Test - public void testGetOwner() - { - Assertions.assertEquals(new WikiPrincipal("Owner1"), w.getOwner()); + public void testGetOwner() { + Assertions.assertEquals( new WikiPrincipal( "Owner1" ), w.getOwner() ); } @Test - public void testStart() throws WikiException - { - Assertions.assertFalse(w.isStarted()); + public void testStart() throws WikiException { + Assertions.assertFalse( w.isStarted() ); w.start(); - Assertions.assertTrue(w.isStarted()); + Assertions.assertTrue( w.isStarted() ); } @Test - public void testWaitstate() throws WikiException - { + public void testWaitstate() throws WikiException { w.start(); // Default workflow should have hit the Decision step and put itself // into WAITING - Assertions.assertEquals(Workflow.WAITING, w.getCurrentState()); + Assertions.assertEquals( Workflow.WAITING, w.getCurrentState() ); } @Test - public void testRestart() throws WikiException - { + public void testRestart() throws WikiException { w.start(); // Default workflow should have hit the Decision step and put itself // into WAITING - Assertions.assertEquals(Workflow.WAITING, w.getCurrentState()); + Assertions.assertEquals( Workflow.WAITING, w.getCurrentState() ); w.restart(); - Assertions.assertEquals(Workflow.WAITING, w.getCurrentState()); + Assertions.assertEquals( Workflow.WAITING, w.getCurrentState() ); } @Test - public void testAbortBeforeStart() throws WikiException - { + public void testAbortBeforeStart() throws WikiException { // Workflow hasn't been started yet - Assertions.assertFalse(w.isAborted()); + Assertions.assertFalse( w.isAborted() ); w.abort(); - Assertions.assertTrue(w.isAborted()); + Assertions.assertTrue( w.isAborted() ); // Try to start anyway - try - { + try { w.start(); - } - catch (IllegalStateException e) - { + } catch( final IllegalStateException e ) { // Swallow return; } // We should never get here - Assertions.fail("Workflow allowed itself to be started even though it was aborted!"); + Assertions.fail( "Workflow allowed itself to be started even though it was aborted!" ); } @Test - public void testAbortDuringWait() throws WikiException - { + public void testAbortDuringWait() throws WikiException { // Start workflow, then abort while in WAITING state - Assertions.assertFalse(w.isAborted()); + Assertions.assertFalse( w.isAborted() ); w.start(); w.abort(); - Assertions.assertTrue(w.isAborted()); + Assertions.assertTrue( w.isAborted() ); // Try to restart anyway - try - { + try { w.restart(); - } - catch (IllegalStateException e) - { + } catch( final IllegalStateException e ) { // Swallow return; } // We should never get here - Assertions.fail("Workflow allowed itself to be re-started even though it was aborted!"); + Assertions.fail( "Workflow allowed itself to be re-started even though it was aborted!" ); } @Test - public void testAbortAfterCompletion() throws WikiException - { + public void testAbortAfterCompletion() throws WikiException { // Start workflow, then abort after completion - Assertions.assertFalse(w.isAborted()); + Assertions.assertFalse( w.isAborted() ); w.start(); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); // Try to abort anyway - try - { + try { w.abort(); - Assertions.assertTrue(w.isAborted()); - } - catch (IllegalStateException e) - { + Assertions.assertTrue( w.isAborted() ); + } catch( final IllegalStateException e ) { // Swallow return; } // We should never get here - Assertions.fail("Workflow allowed itself to be aborted even though it was completed!"); + Assertions.fail( "Workflow allowed itself to be aborted even though it was completed!" ); } @Test - public void testCurrentState() throws WikiException - { - Assertions.assertEquals(Workflow.CREATED, w.getCurrentState()); + public void testCurrentState() throws WikiException { + Assertions.assertEquals( Workflow.CREATED, w.getCurrentState() ); w.start(); - Assertions.assertEquals(Workflow.WAITING, w.getCurrentState()); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertEquals(Workflow.COMPLETED, w.getCurrentState()); + Assertions.assertEquals( Workflow.WAITING, w.getCurrentState() ); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertEquals( Workflow.COMPLETED, w.getCurrentState() ); } @Test - public void testCurrentStep() throws WikiException - { - Assertions.assertNull(w.getCurrentStep()); + public void testCurrentStep() throws WikiException { + Assertions.assertNull( w.getCurrentStep() ); w.start(); // Workflow stops at the decision step - Assertions.assertEquals(decision, w.getCurrentStep()); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); + Assertions.assertEquals( decision, w.getCurrentStep() ); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); // After we decide, it blows through step 3 and leaves us with a null // step (done) - Assertions.assertNull(w.getCurrentStep()); + Assertions.assertNull( w.getCurrentStep() ); } @Test - public void testPreviousStep() throws WikiException - { + public void testPreviousStep() throws WikiException { // If not started, no previous steps available for anything - Assertions.assertNull(w.getPreviousStep()); - Assertions.assertEquals(null, w.previousStep(initTask)); - Assertions.assertEquals(null, w.previousStep(decision)); - Assertions.assertEquals(null, w.previousStep(finishTask)); + Assertions.assertNull( w.getPreviousStep() ); + Assertions.assertNull( w.previousStep( initTask ) ); + Assertions.assertNull( w.previousStep( decision ) ); + Assertions.assertNull( w.previousStep( finishTask ) ); // Once we start, initTask and decisions' predecessors are known, but // finish task is indeterminate w.start(); - Assertions.assertEquals(null, w.previousStep(initTask)); - Assertions.assertEquals(initTask, w.previousStep(decision)); - Assertions.assertEquals(null, w.previousStep(finishTask)); + Assertions.assertNull( w.previousStep( initTask ) ); + Assertions.assertEquals( initTask, w.previousStep( decision ) ); + Assertions.assertNull( w.previousStep( finishTask ) ); // Once we decide, the finish task returns the correct predecessor - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertEquals(null, w.previousStep(initTask)); - Assertions.assertEquals(initTask, w.previousStep(decision)); - Assertions.assertEquals(decision, w.previousStep(finishTask)); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertNull( w.previousStep( initTask ) ); + Assertions.assertEquals( initTask, w.previousStep( decision ) ); + Assertions.assertEquals( decision, w.previousStep( finishTask ) ); } @Test - public void testCurrentActor() throws WikiException - { + public void testCurrentActor() throws WikiException { // Before starting, actor should be null - Assertions.assertNull(w.getCurrentActor()); + Assertions.assertNull( w.getCurrentActor() ); // After starting, actor should be GroupPrincipal Admin w.start(); - Assertions.assertEquals(new GroupPrincipal("Admin"), w.getCurrentActor()); + Assertions.assertEquals( new GroupPrincipal( "Admin" ), w.getCurrentActor() ); // After decision, actor should be null again - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertNull(w.getCurrentActor()); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertNull( w.getCurrentActor() ); } @Test - public void testHistory() throws WikiException - { - Assertions.assertEquals(0, w.getHistory().size()); + public void testHistory() throws WikiException { + Assertions.assertEquals( 0, w.getHistory().size() ); w.start(); - Assertions.assertEquals(2, w.getHistory().size()); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertEquals(3, w.getHistory().size()); + Assertions.assertEquals( 2, w.getHistory().size() ); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertEquals( 3, w.getHistory().size() ); } @Test - public void testGetStartTime() throws WikiException - { + public void testGetStartTime() throws WikiException { // Start time should be not be set until we start the workflow - Assertions.assertEquals(Workflow.TIME_NOT_SET, w.getStartTime()); + Assertions.assertEquals( Workflow.TIME_NOT_SET, w.getStartTime() ); w.start(); - Assertions.assertFalse(Workflow.TIME_NOT_SET == w.getStartTime()); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertFalse(Workflow.TIME_NOT_SET == w.getStartTime()); + Assertions.assertNotSame( Workflow.TIME_NOT_SET, w.getStartTime() ); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertNotSame( Workflow.TIME_NOT_SET, w.getStartTime() ); } @Test - public void testGetEndTime() throws WikiException - { + public void testGetEndTime() throws WikiException { // End time should be not set until we finish all 3 steps - Assertions.assertEquals(Workflow.TIME_NOT_SET, w.getEndTime()); + Assertions.assertEquals( Workflow.TIME_NOT_SET, w.getEndTime() ); w.start(); - Assertions.assertEquals(Workflow.TIME_NOT_SET, w.getEndTime()); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertFalse(Workflow.TIME_NOT_SET == w.getEndTime()); + Assertions.assertEquals( Workflow.TIME_NOT_SET, w.getEndTime() ); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertNotSame( Workflow.TIME_NOT_SET, w.getEndTime() ); } @Test - public void testIsCompleted() throws WikiException - { + public void testIsCompleted() throws WikiException { // Workflow isn't completed until we finish all 3 steps - Assertions.assertFalse(w.isCompleted()); + Assertions.assertFalse( w.isCompleted() ); w.start(); - Assertions.assertFalse(w.isCompleted()); - Decision d = (Decision) w.getCurrentStep(); - d.decide(Outcome.DECISION_APPROVE); - Assertions.assertTrue(w.isCompleted()); + Assertions.assertFalse( w.isCompleted() ); + final Decision d = ( Decision )w.getCurrentStep(); + d.decide( Outcome.DECISION_APPROVE ); + Assertions.assertTrue( w.isCompleted() ); } @Test - public void testIsStarted() throws WikiException - { - Assertions.assertFalse(w.isStarted()); + public void testIsStarted() throws WikiException { + Assertions.assertFalse( w.isStarted() ); w.start(); - Assertions.assertTrue(w.isStarted()); + Assertions.assertTrue( w.isStarted() ); } @Test - public void testStartTwice() throws WikiException - { + public void testStartTwice() throws WikiException { w.start(); - try - { + try { w.start(); - } - catch (IllegalStateException e) - { + } catch( final IllegalStateException e ) { // Swallow return; } // We should never get here - Assertions.fail("Workflow allowed itself to be started twice!"); + Assertions.fail( "Workflow allowed itself to be started twice!" ); } @Test - public void testSetId() - { - Assertions.assertEquals(Workflow.ID_NOT_SET, w.getId()); - w.setId(1001); - Assertions.assertEquals(1001, w.getId()); + public void testSetId() { + Assertions.assertEquals( Workflow.ID_NOT_SET, w.getId() ); + w.setId( 1001 ); + Assertions.assertEquals( 1001, w.getId() ); } }
