Skip to content

Commit

Permalink
fix import definition from xml when mvel contains special character
Browse files Browse the repository at this point in the history
  • Loading branch information
Kailiang.He committed Mar 9, 2022
1 parent 4b21561 commit aa7526d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.squirrelframework.foundation.fsm.impl;

import org.apache.commons.lang3.StringEscapeUtils;
import org.squirrelframework.foundation.fsm.*;
import org.w3c.dom.Document;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void visitOnEntry(ImmutableTransition<?, ?, ?, ?> visitable) {
+ quoteName(Integer.toString(visitable.getPriority())) + " sqrl:type="
+ quoteName(visitable.getType().toString()) + " target="
+ quoteEnumName(visitable.getTargetState()) + " cond="
+ quoteName(visitable.getCondition().toString())+">");
+ quoteName(StringEscapeUtils.escapeXml(visitable.getCondition().toString()))+">");
for(Action<?, ?, ?, ?> action : visitable.getActions()) {
writeAction(action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ public void execute(Object from, Object to, Object event, Object context,
String definition = sample.exportXMLDefinition(false);
UntypedStateMachineBuilder importedBuilder = new UntypedStateMachineImporter().importDefinition(definition);
}

@Test
public void testImportNonParameterizedActionSuccess() {
UntypedStateMachineBuilder builder =
StateMachineBuilderFactory.create(ImportParameterizedActionCase.class);
builder.externalTransition().from("a").to("b").on(TestEvent.toB).perform(Action.DUMMY_ACTION);
builder.externalTransition().from("b").to("c").on(TestEvent.toC)
.whenMvel("MyCondition:::(context>1&&context<10)").perform(Action.DUMMY_ACTION);
ImportParameterizedActionCase sample = builder.newUntypedStateMachine("a");

UntypedStateMachineBuilder importedBuilder =
new UntypedStateMachineImporter().importDefinition(sample.exportXMLDefinition(false));
String xmlDefinition = sample.exportXMLDefinition(false);
UntypedStateMachineBuilder importedBuilder = new UntypedStateMachineImporter().importDefinition(xmlDefinition);
ImportParameterizedActionCase importedSample = importedBuilder.newAnyStateMachine("a");
importedSample.fire(TestEvent.toB);
assertTrue(importedSample.getCurrentState().equals("b"));
importedSample.fire(TestEvent.toC, 5);
assertTrue(importedSample.getCurrentState().equals("c"));
}

@Test
Expand Down

0 comments on commit aa7526d

Please sign in to comment.