craigmcc 01/09/03 13:09:27
Modified: workflow/src/java/org/apache/commons/workflow/base
BaseDescriptor.java
workflow/src/test/org/apache/commons/workflow/base
Employee.java
workflow/src/test/org/apache/commons/workflow/core
CoreExecuteTestCase.java
Log:
Support setting properties through JXPath expressions, and add a unit test
for this.
Revision Changes Path
1.4 +6 -5
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseDescriptor.java
Index: BaseDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseDescriptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseDescriptor.java 2001/08/26 03:38:11 1.3
+++ BaseDescriptor.java 2001/09/03 20:09:27 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseDescriptor.java,v
1.3 2001/08/26 03:38:11 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/08/26 03:38:11 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseDescriptor.java,v
1.4 2001/09/03 20:09:27 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/09/03 20:09:27 $
*
* ====================================================================
*
@@ -71,7 +71,7 @@
/**
* <p>Basic implementation of the <strong>Descriptor</strong> interface.</p>
*
- * @version $Revision: 1.3 $ $Date: 2001/08/26 03:38:11 $
+ * @version $Revision: 1.4 $ $Date: 2001/09/03 20:09:27 $
* @author Craig R. McClanahan
*/
@@ -327,7 +327,8 @@
public void put(Context context, Object value) {
if (xpath != null) {
- throw new IllegalStateException("Cannot 'put' throw xpath");
+ JXPathContext jpc = context.getJXPathContext();
+ jpc.setValue("local/" + xpath, value);
} else {
if (scope == null)
context.put(name, value);
1.2 +11 -3
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/Employee.java
Index: Employee.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/Employee.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Employee.java 2001/08/19 23:53:10 1.1
+++ Employee.java 2001/09/03 20:09:27 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/Employee.java,v
1.1 2001/08/19 23:53:10 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/19 23:53:10 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/Employee.java,v
1.2 2001/09/03 20:09:27 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/09/03 20:09:27 $
*
* ====================================================================
*
@@ -93,6 +93,14 @@
}
public void removeAddress(String key) {
addresses.remove(key);
+ }
+
+ private Address baseAddress = null;
+ public Address getBaseAddress() {
+ return (this.baseAddress);
+ }
+ public void setBaseAddress(Address baseAddress) {
+ this.baseAddress = baseAddress;
}
private String firstName = null;
1.7 +88 -4
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java
Index: CoreExecuteTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CoreExecuteTestCase.java 2001/08/27 05:57:26 1.6
+++ CoreExecuteTestCase.java 2001/09/03 20:09:27 1.7
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java,v
1.6 2001/08/27 05:57:26 craigmcc Exp $
- * $Revision: 1.6 $
- * $Date: 2001/08/27 05:57:26 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java,v
1.7 2001/09/03 20:09:27 craigmcc Exp $
+ * $Revision: 1.7 $
+ * $Date: 2001/09/03 20:09:27 $
*
* ====================================================================
*
@@ -78,6 +78,7 @@
import org.apache.commons.workflow.base.BaseContext;
import org.apache.commons.workflow.base.BaseDescriptor;
import org.apache.commons.workflow.base.BaseScope;
+import org.apache.commons.workflow.base.Employee;
/**
@@ -85,7 +86,7 @@
* implementations.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.6 $ $Date: 2001/08/27 05:57:26 $
+ * @version $Revision: 1.7 $ $Date: 2001/09/03 20:09:27 $
*/
public class CoreExecuteTestCase extends TestCase
@@ -774,6 +775,89 @@
(String) context.pop());
assertTrue("Stack is now empty",
context.isEmpty());
+ } catch (StepException e) {
+ e.printStackTrace(System.out);
+ if (e.getCause() != null) {
+ System.out.println("ROOT CAUSE");
+ e.getCause().printStackTrace(System.out);
+ }
+ fail("Threw StepException " + e);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail("Threw exception " + e);
+ }
+
+ }
+
+
+ /**
+ * Test setting and getting properties via XPath expressions.
+ */
+ public void testXpathProperties() {
+
+ // Stash a bean in local scope to play with
+ Employee employee = new Employee();
+ context.put("employee", employee);
+
+ // Configure the steps in this activity
+ activity.addStep(new GetStep("01",
+ new BaseDescriptor("employee/firstName")));
+ activity.addStep(new SuspendStep("02"));
+ // Test will remove the retrieved String value
+ activity.addStep(new StringStep("03", "The New First Name"));
+ activity.addStep(new PutStep("04",
+ new BaseDescriptor("employee/firstName")));
+ activity.addStep(new SuspendStep("05"));
+
+ // Execute the activity and validate results #1
+ try {
+ context.execute();
+ assertEquals("Trail contents 1",
+ "beforeActivity()/" +
+ "beforeStep(01)/afterStep(01)/" +
+ "beforeStep(02)/afterStep(02)/" +
+ "afterActivity()/",
+ trail.toString());
+ assertTrue("Context is suspended",
+ context.getSuspend());
+ assertTrue("Stack is not empty",
+ !context.isEmpty());
+ Object top = context.pop();
+ assertTrue("Stack is empty",
+ context.isEmpty());
+ assertTrue("employee/firstName returned a String",
+ top instanceof String);
+ assertEquals("employee/firstName old value",
+ employee.getFirstName(), (String) top);
+ } catch (StepException e) {
+ e.printStackTrace(System.out);
+ if (e.getCause() != null) {
+ System.out.println("ROOT CAUSE");
+ e.getCause().printStackTrace(System.out);
+ }
+ fail("Threw StepException " + e);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail("Threw exception " + e);
+ }
+
+ // Execute the activity and validate results #2
+ try {
+ context.execute();
+ assertEquals("Trail contents 2",
+ "beforeActivity()/" +
+ "beforeStep(03)/afterStep(03)/" +
+ "beforeStep(04)/afterStep(04)/" +
+ "beforeStep(05)/afterStep(05)/" +
+ "afterActivity()/",
+ trail.toString());
+ assertTrue("Context is suspended",
+ context.getSuspend());
+ assertTrue("Stack is empty",
+ context.isEmpty());
+ assertEquals("employee/firstName new value",
+ "The New First Name",
+ employee.getFirstName());
} catch (StepException e) {
e.printStackTrace(System.out);
if (e.getCause() != null) {