1 5 package com.opensymphony.workflow; 6 7 import com.opensymphony.workflow.basic.BasicWorkflow; 8 import com.opensymphony.workflow.loader.WorkflowDescriptor; 9 10 import junit.framework.TestCase; 11 12 import java.util.HashMap ; 13 14 15 21 public class ValidationTestCase extends TestCase { 22 24 public ValidationTestCase(String s) { 25 super(s); 26 } 27 28 30 36 public void testCheckResultInitialActionUnconditionalResult() throws Exception { 37 try { 38 WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getClassLoader().getResource("samples/unconditional-result.xml").toString()); 39 descriptor.validate(); 40 fail("descriptor loaded successfully, even though unconditional-result element is incorrect"); 41 } catch (InvalidWorkflowDescriptorException e) { 42 } catch (Exception ex) { 44 ex.printStackTrace(); 45 fail("descriptor failed to load as expected, but a " + ex.getClass() + " exception was caught instead of InvalidWorkflowDescriptorException"); 46 } 47 } 48 49 54 public void testCommonActions() throws Exception { 55 try { 56 WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getResource("/samples/common-actions.xml").toString()); 57 descriptor.validate(); 58 } catch (InvalidWorkflowDescriptorException e) { 59 e.printStackTrace(); 60 fail("Descriptor did not recognized common-actions!"); 61 } 62 63 try { 64 WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getResource("/samples/invalid/common-actions-bad.xml").toString()); 65 descriptor.validate(); 66 fail("Invalid common-actions not detected correctly"); 67 } catch (InvalidWorkflowDescriptorException e) { 68 } 69 } 70 71 77 public void testDuplicateActionID() throws Exception { 78 try { 79 WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getResource("/samples/invalid/duplicate-action.xml").toString()); 80 descriptor.validate(); 81 fail("descriptor loaded successfully, even though duplicate action exists"); 82 } catch (InvalidWorkflowDescriptorException e) { 83 } catch (Exception ex) { 85 ex.printStackTrace(); 86 fail("descriptor failed to load as expected, but a " + ex.getClass() + " exception was caught instead of InvalidWorkflowDescriptorException"); 87 } 88 } 89 90 93 public void testValidator() throws Exception { 94 Workflow workflow = new BasicWorkflow("testuser"); 95 96 try { 97 long id = workflow.initialize(getClass().getClassLoader().getResource("samples/validator.xml").toString(), 1, new HashMap ()); 98 } catch (InvalidInputException e) { 99 return; 101 } catch (Exception ex) { 102 ex.printStackTrace(); 103 fail("descriptor failed to load as expected, but a " + ex.getClass() + " exception was caught instead of InvalidWorkflowDescriptorException"); 104 } 105 106 fail("Did not get expected InvalidInputException"); 107 } 108 } 109 | Popular Tags |