cancel
Showing results for 
Search instead for 
Did you mean: 

FormServiceTest String cannot be cast to BigDecimal

tomi87
Champ in-the-making
Champ in-the-making
I reproduced the FormServiceTest.java from chapter 5. Then I tried to start this test with the whole loanrequest.bpmn20.xml, I imported the .jar file in the folder and added this to the librarys,  but I get this error message:

org.activiti.engine.ActivitiException: problem evaluating script: javax.script.ScriptException: java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:71)
   at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:51)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:115)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:381)
   at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOutgoingBehavior(BpmnActivityBehavior.java:102)
   at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDefaultOutgoingBehavior(BpmnActivityBehavior.java:51)
   at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:44)
   at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.execute(FlowNodeActivityBehavior.java:36)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStartInitial.eventNotificationsCompleted(AtomicOperationProcessStartInitial.java:46)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStart.eventNotificationsCompleted(AtomicOperationProcessStart.java:45)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:335)
   at org.activiti.engine.impl.cmd.SubmitStartFormCmd.execute(SubmitStartFormCmd.java:80)
   at org.activiti.engine.impl.cmd.SubmitStartFormCmd.execute(SubmitStartFormCmd.java:35)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.FormServiceImpl.submitStartFormData(FormServiceImpl.java:60)
   at org.FormServiceTest.startFormSubmit(FormServiceTest.java:42)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal
   at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:122)
   at javax.script.AbstractScriptEngine.eval(Unknown Source)
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:69)
   … 85 more
Caused by: javax.script.ScriptException: java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal
   at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:323)
   at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:116)
   … 87 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal
   at java.math.BigDecimal.compareTo(Unknown Source)
   at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareToWithEqualityCheck(DefaultTypeTransformation.java:599)
   at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareTo(DefaultTypeTransformation.java:554)
   at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareTo(ScriptBytecodeAdapter.java:688)
   at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareGreaterThan(ScriptBytecodeAdapter.java:705)
   at Script1.run(Script1.groovy:4)
   at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320)
   … 88 more

Jan 19, 2013 8:14:29 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions

INFO: Process with id='loanrequest' hasn't the attribute isExecutable set. Please maintain it, so you are compatible to future activiti versions.
Checking credit for Miss Piggy
Jan 19, 2013 8:14:30 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: problem evaluating script: javax.script.ScriptException: java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal

They wrote in the book "At the start of the process, these properties are converted into process variables of the correct type."
What did I wrong or what should I add ?
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Hi,

Can you add the BPMN XML you used? And maybe also the test you run?

Best regards,

tomi87
Champ in-the-making
Champ in-the-making
Can you add the BPMN XML you used? And maybe also the test you run?


It's the bpmn20.xml loanrequest file from the book:
<process id="loanrequest" name="Process to handle a loan request">
  <startEvent id="theStart">
   <extensionElements>
    <activiti:formProperty id="name" name="Name"
     required="true" type="string" />
    <activiti:formProperty id="emailAddress" name="Email address"
     required="true" type="string" />
    <activiti:formProperty id="income" name="Income"
     required="true" type="long" />
    <activiti:formProperty id="loanAmount" name="Loan amount"/>
   </extensionElements>
  </startEvent>
  <sequenceFlow sourceRef="theStart" targetRef="checkCredit" />
  <scriptTask id="checkCredit" scriptFormat="groovy">
   <script>
    outSmiley Tonguerintln "Checking credit for " + name;
    creditCheckOk = false;
    if((income / 2) > loanAmount){creditCheckOk = true;}
    outSmiley Tonguerintln "Checked credit for " + name + " outcome is " + creditCheckOk;
   </script>
  </scriptTask>
  <sequenceFlow sourceRef="checkCredit" targetRef="createApplication" />
  <serviceTask id="createApplication" activiti:class="org.CreateApplicationTask" />
  <sequenceFlow sourceRef="createApplication" targetRef="theEnd" />
  <endEvent id="theEnd" />
</process>
</definitions>

Test:
public class FormServiceTest{

@Rule
public ActivitiRule activitiRule = new ActivitiRule("activiti.cfg-mem.xml");

@Test
@Deployment(resources={"loanrequest.bpmn20.xml"})
public void startFormSubmit() {
  //startFormTest
  ProcessDefinition definition = activitiRule.getRepositoryService()
    .createProcessDefinitionQuery().processDefinitionKey("loanrequest").singleResult();
  assertNotNull(definition);

  FormService formService = activitiRule.getFormService();
  List<FormProperty> formList = formService.getStartFormData(definition.getId()).getFormProperties();
  assertEquals(4, formList.size());

  Map<String, String> formProperties = new HashMap<String, String>();
  formProperties.put("name", "Miss Piggy");
  formProperties.put("emailAddress", "piggy@localhost");
  formProperties.put("income", "400");
  formProperties.put("loanAmount", "100");
  formService.submitStartFormData(definition.getId(), formProperties);

  List<HistoricDetail> historyVariables = activitiRule.getHistoryService()
         .createHistoricDetailQuery()
         .formProperties()
         .list();

  assertNotNull(historyVariables);
  assertEquals(4, historyVariables.size());

//The following test cases are maybe wrong. I fix it later.

  HistoricFormProperty formProperty = (HistoricFormProperty) historyVariables.get(0);
  assertEquals("loanAmount", formProperty.getPropertyId());
  assertEquals("100", formProperty.getPropertyValue());
 
  formProperty = (HistoricFormProperty) historyVariables.get(1);
  assertEquals("income", formProperty.getPropertyId());
  assertEquals("400", formProperty.getPropertyValue());
}
}

My plan is to create a test for the first 'startEvent', 'scriptTask id="checkCredit" ' and 'serviceTask id="createApplication" '. Where I want to set the input Variable for the startEvent and then to test, if the variables are in the created object from activiti:class="org.CreateApplicationTask".

My problem is, how can I submit the input variables that I can check if they are at the end in the object?

I would testthe variable with this kind of following test:
List<HistoricDetail> historyVariables = activitiRule.getHistoryService().createHistoricDetailQuery().variableUpdates().orderByVariableName().asc().list();
HistoricVariableUpdate loanAppUpdate = ((HistoricVariableUpdate) historyVariables.get(5));
  assertEquals("loanApplication", loanAppUpdate.getVariableName());
  LoanApplication la = (LoanApplication) loanAppUpdate.getValue();
  assertEquals(true, la.isCreditCheckOk());

Hope you can help me.

Best regards

tomi87
Champ in-the-making
Champ in-the-making
Do you need some other information ?

jbarrez
Star Contributor
Star Contributor
Do you need some other information ?

No, it's just that I don't get what you are trying to achive:

My problem is, how can I submit the input variables that I can check if they are at the end in the object?

As I understand your original exception, it seems you are passing a String value instead of a numerical value. And that is where the script crashes.

And yes, if I check your test code, I see this:

Map<String, String> formProperties = new HashMap<String, String>();
      formProperties.put("name", "Miss Piggy");
      formProperties.put("emailAddress", "piggy@localhost");
      formProperties.put("income", "400");
      formProperties.put("loanAmount", "100");
      formService.submitStartFormData(definition.getId(), formProperties);

Which are all strings.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.