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


The following commit(s) were added to refs/heads/master by this push:
     new 72d2a86  fix failing tests
72d2a86 is described below

commit 72d2a869ba120dc41174701e7683510ab5d2ef20
Author: juanpablo <[email protected]>
AuthorDate: Tue May 5 21:45:30 2020 +0200

    fix failing tests
---
 .../java/org/apache/wiki/workflow/TaskTest.java    | 180 ++++++++++-----------
 .../org/apache/wiki/workflow/WorkflowTest.java     |   9 +-
 2 files changed, 90 insertions(+), 99 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/TaskTest.java 
b/jspwiki-main/src/test/java/org/apache/wiki/workflow/TaskTest.java
index 53612e9..6cead93 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/TaskTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/TaskTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.wiki.workflow;
 
+import org.apache.wiki.TestEngine;
 import org.apache.wiki.api.exceptions.WikiException;
 import org.apache.wiki.auth.WikiPrincipal;
 import org.junit.jupiter.api.Assertions;
@@ -27,185 +28,172 @@ import org.junit.jupiter.api.Test;
 import java.util.Collection;
 import java.util.List;
 
-public class TaskTest
-{
 
+public class TaskTest {
+
+    TestEngine engine = TestEngine.build();
+    // listen to workflow events
+    WorkflowManager workflowsEventListener = new DefaultWorkflowManager();
     Workflow m_workflow;
     Task m_task;
 
     /** Sample Task that completes normally. */
-    public static class NormalTask extends Task
-    {
+    public static class NormalTask extends Task {
+
         private static final long serialVersionUID = 1L;
 
-        public NormalTask( final Workflow workflow)
-        {
-            super(workflow.getId(), workflow.getAttributes(), "task.normal");
+        public NormalTask( final Workflow workflow ) {
+            super( workflow.getId(), workflow.getAttributes(), "task.normal" );
         }
-        public Outcome execute() throws WikiException
-        {
+
+        public Outcome execute() throws WikiException {
             return Outcome.STEP_COMPLETE;
         }
 
     }
 
     /** Sample Task that encounters an error during processing. */
-    public static class ErrorTask extends Task
-    {
+    public static class ErrorTask extends Task {
+
         private static final long serialVersionUID = 1L;
 
-        public ErrorTask( final Workflow workflow)
-        {
-            super(workflow.getId(), workflow.getAttributes(), "task.error");
+        public ErrorTask( final Workflow workflow ) {
+            super( workflow.getId(), workflow.getAttributes(), "task.error" );
         }
-        public Outcome execute() throws WikiException
-        {
-            addError("Found an error.");
-            addError("Found a second one!");
+
+        public Outcome execute() throws WikiException {
+            addError( "Found an error." );
+            addError( "Found a second one!" );
             return Outcome.STEP_ABORT;
         }
 
     }
 
     @BeforeEach
-    public void setUp() throws Exception
-    {
-
-        m_workflow = new Workflow("workflow.key", new WikiPrincipal("Owner1"));
-        m_task = new NormalTask(m_workflow);
+    public void setUp() throws Exception {
+        workflowsEventListener.initialize( engine, 
TestEngine.getTestProperties() );
+        m_workflow = new Workflow( "workflow.key", new WikiPrincipal( "Owner1" 
) );
+        m_task = new NormalTask( m_workflow );
     }
 
     @Test
-    public void testGetActor()
-    {
-       Assertions.assertNotSame(new WikiPrincipal("Actor1"), 
m_task.getActor());
-       Assertions.assertEquals(SystemPrincipal.SYSTEM_USER, m_task.getActor());
+    public void testGetActor() {
+        Assertions.assertNotSame( new WikiPrincipal( "Actor1" ), 
m_task.getActor() );
+        Assertions.assertEquals( SystemPrincipal.SYSTEM_USER, 
m_task.getActor() );
     }
 
     @Test
-    public void testSuccessors()
-    {
+    public void testSuccessors() {
         // If task finishes normally, branch to a decision (d1)
-        final Step d1 = new SimpleDecision(m_workflow.getId(), 
m_workflow.getAttributes(), "decision1.key", new WikiPrincipal("Actor1"));
-        m_task.addSuccessor(Outcome.STEP_COMPLETE, d1);
+        final Step d1 = new SimpleDecision( m_workflow.getId(), 
m_workflow.getAttributes(), "decision1.key",
+                new WikiPrincipal( "Actor1" ) );
+        m_task.addSuccessor( Outcome.STEP_COMPLETE, d1 );
 
         // If the task aborts, branch to an alternate decision (d2)
-        final Step d2 = new SimpleDecision(m_workflow.getId(), 
m_workflow.getAttributes(), "decision2.key", new WikiPrincipal("Actor2"));
-        m_task.addSuccessor(Outcome.STEP_ABORT, d2);
+        final Step d2 = new SimpleDecision( m_workflow.getId(), 
m_workflow.getAttributes(), "decision2.key",
+                new WikiPrincipal( "Actor2" ) );
+        m_task.addSuccessor( Outcome.STEP_ABORT, d2 );
 
-        Assertions.assertEquals(d1, 
m_task.getSuccessor(Outcome.STEP_COMPLETE));
-        Assertions.assertEquals(d2, m_task.getSuccessor(Outcome.STEP_ABORT));
+        Assertions.assertEquals( d1, m_task.getSuccessor( 
Outcome.STEP_COMPLETE ) );
+        Assertions.assertEquals( d2, m_task.getSuccessor( Outcome.STEP_ABORT ) 
);
 
         // The other Outcomes should return null when looked up
-        Assertions.assertNull(m_task.getSuccessor(Outcome.DECISION_APPROVE));
-        Assertions.assertNull(m_task.getSuccessor(Outcome.DECISION_DENY));
-        Assertions.assertNull(m_task.getSuccessor(Outcome.DECISION_HOLD));
-        Assertions.assertNull(m_task.getSuccessor(Outcome.DECISION_REASSIGN));
-        Assertions.assertNull(m_task.getSuccessor(Outcome.STEP_CONTINUE));
+        Assertions.assertNull( m_task.getSuccessor( Outcome.DECISION_APPROVE ) 
);
+        Assertions.assertNull( m_task.getSuccessor( Outcome.DECISION_DENY ) );
+        Assertions.assertNull( m_task.getSuccessor( Outcome.DECISION_HOLD ) );
+        Assertions.assertNull( m_task.getSuccessor( Outcome.DECISION_REASSIGN 
) );
+        Assertions.assertNull( m_task.getSuccessor( Outcome.STEP_CONTINUE ) );
     }
 
     @Test
-    public void testErrors()
-    {
-        m_task.addError("Error deciding something.");
-        m_task.addError("Error deciding something else.");
+    public void testErrors() {
+        m_task.addError( "Error deciding something." );
+        m_task.addError( "Error deciding something else." );
 
         final List< String > errors = m_task.getErrors();
-        Assertions.assertEquals(2, errors.size());
-        Assertions.assertEquals("Error deciding something.", errors.get(0));
-        Assertions.assertEquals("Error deciding something else.", 
errors.get(1));
+        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()
-    {
+    public void testAvailableOutcomes() {
         final Collection< Outcome > outcomes = m_task.getAvailableOutcomes();
-        Assertions.assertFalse(outcomes.contains(Outcome.DECISION_APPROVE));
-        Assertions.assertFalse(outcomes.contains(Outcome.DECISION_DENY));
-        Assertions.assertFalse(outcomes.contains(Outcome.DECISION_HOLD));
-        Assertions.assertFalse(outcomes.contains(Outcome.DECISION_REASSIGN));
-        Assertions.assertTrue(outcomes.contains(Outcome.STEP_ABORT));
-        Assertions.assertTrue(outcomes.contains(Outcome.STEP_COMPLETE));
+        Assertions.assertFalse( outcomes.contains( Outcome.DECISION_APPROVE ) 
);
+        Assertions.assertFalse( outcomes.contains( Outcome.DECISION_DENY ) );
+        Assertions.assertFalse( outcomes.contains( Outcome.DECISION_HOLD ) );
+        Assertions.assertFalse( outcomes.contains( Outcome.DECISION_REASSIGN ) 
);
+        Assertions.assertTrue( outcomes.contains( Outcome.STEP_ABORT ) );
+        Assertions.assertTrue( outcomes.contains( Outcome.STEP_COMPLETE ) );
     }
 
     @Test
-    public void testGetEndTime() throws WikiException
-    {
-        Assertions.assertEquals(Step.TIME_NOT_SET, m_task.getEndTime());
+    public void testGetEndTime() throws WikiException {
+        Assertions.assertEquals( Step.TIME_NOT_SET, m_task.getEndTime() );
         m_task.start();
-        m_task.setOutcome(m_task.execute());
-        Assertions.assertTrue((Step.TIME_NOT_SET  !=  m_task.getEndTime()));
+        m_task.setOutcome( m_task.execute() );
+        Assertions.assertTrue( ( Step.TIME_NOT_SET != m_task.getEndTime() ) );
     }
 
     @Test
-    public void testGetMessageKey()
-    {
-        Assertions.assertEquals("task.normal",m_task.getMessageKey());
+    public void testGetMessageKey() {
+        Assertions.assertEquals( "task.normal", m_task.getMessageKey() );
     }
 
     @Test
-    public void testGetOutcome() throws WikiException
-    {
-        Assertions.assertEquals(Outcome.STEP_CONTINUE,m_task.getOutcome());
+    public void testGetOutcome() throws WikiException {
+        Assertions.assertEquals( Outcome.STEP_CONTINUE, m_task.getOutcome() );
         m_task.start();
-        m_task.setOutcome(m_task.execute());
-        Assertions.assertEquals(Outcome.STEP_COMPLETE, m_task.getOutcome());
+        m_task.setOutcome( m_task.execute() );
+        Assertions.assertEquals( Outcome.STEP_COMPLETE, m_task.getOutcome() );
 
         // Test the "error task"
-        m_task = new ErrorTask(m_workflow);
-        Assertions.assertEquals(Outcome.STEP_CONTINUE,m_task.getOutcome());
+        m_task = new ErrorTask( m_workflow );
+        Assertions.assertEquals( Outcome.STEP_CONTINUE, m_task.getOutcome() );
         m_task.start();
-        m_task.setOutcome(m_task.execute());
-        Assertions.assertEquals(Outcome.STEP_ABORT, m_task.getOutcome());
+        m_task.setOutcome( m_task.execute() );
+        Assertions.assertEquals( Outcome.STEP_ABORT, m_task.getOutcome() );
     }
 
     @Test
-    public void testGetStartTime() throws WikiException
-    {
-        Assertions.assertEquals(Step.TIME_NOT_SET, m_task.getStartTime());
+    public void testGetStartTime() throws WikiException {
+        Assertions.assertEquals( Step.TIME_NOT_SET, m_task.getStartTime() );
         m_task.start();
         m_task.execute();
-        Assertions.assertTrue((Step.TIME_NOT_SET  !=  m_task.getStartTime()));
+        Assertions.assertTrue( ( Step.TIME_NOT_SET != m_task.getStartTime() ) 
);
     }
 
     @Test
-    public void testGetWorkflow()
-    {
-        Assertions.assertEquals(m_workflow.getId(), m_task.getWorkflowId() );
+    public void testGetWorkflow() {
+        Assertions.assertEquals( m_workflow.getId(), m_task.getWorkflowId() );
     }
 
     @Test
-    public void testIsCompleted() throws WikiException
-    {
-        Assertions.assertFalse(m_task.isCompleted());
+    public void testIsCompleted() throws WikiException {
+        Assertions.assertFalse( m_task.isCompleted() );
         m_task.start();
-        m_task.setOutcome(m_task.execute());
-        Assertions.assertTrue(m_task.isCompleted());
+        m_task.setOutcome( m_task.execute() );
+        Assertions.assertTrue( m_task.isCompleted() );
     }
 
     @Test
-    public void testIsStarted() throws WikiException
-    {
-        Assertions.assertFalse(m_task.isStarted());
+    public void testIsStarted() throws WikiException {
+        Assertions.assertFalse( m_task.isStarted() );
         m_task.start();
-        Assertions.assertTrue(m_task.isStarted());
+        Assertions.assertTrue( m_task.isStarted() );
     }
 
     @Test
-    public void testStartTwice() throws WikiException
-    {
+    public void testStartTwice() throws WikiException {
         m_task.start();
-        try
-        {
+        try {
             m_task.start();
-        }
-        catch ( final 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/WorkflowTest.java 
b/jspwiki-main/src/test/java/org/apache/wiki/workflow/WorkflowTest.java
index 6064c28..44739ce 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
@@ -18,6 +18,7 @@
  */
 package org.apache.wiki.workflow;
 
+import org.apache.wiki.TestEngine;
 import org.apache.wiki.api.exceptions.WikiException;
 import org.apache.wiki.auth.GroupPrincipal;
 import org.apache.wiki.auth.WikiPrincipal;
@@ -32,7 +33,10 @@ import java.util.Date;
 
 public class WorkflowTest {
 
-    WorkflowManager workflowsEventListener;
+    TestEngine engine = TestEngine.build();
+
+    // listen to workflow events
+    WorkflowManager workflowsEventListener = new DefaultWorkflowManager();
 
     Workflow w;
 
@@ -46,8 +50,7 @@ public class WorkflowTest {
 
     @BeforeEach
     public void setUp() throws Exception {
-        // listen to workflow events
-        workflowsEventListener = new DefaultWorkflowManager();
+        workflowsEventListener.initialize( engine, 
TestEngine.getTestProperties() );
 
         // Create workflow; owner is test user
         w = new Workflow( "workflow.myworkflow", new WikiPrincipal( "Owner1" ) 
);

Reply via email to