|Tests using EditHelperAdvice classes [message #1817901]
||Mon, 02 December 2019 15:52
| Yoann Farré
Registered: November 2017
Hello everyone, |
I'm developing junit tests on my plugins. I'm trying to adress some simple tests (to avoid futur regressions) on the renaming action of some elements. In the following example, I defined an EditHelperAdvice class which enables to rename other elements on the fly when the user renames a state. The EditHelperAdvice class is associated (via elementtypesconfigurations files) with element having "OperationalState" stereotype.
In the test, I use the following code:
Package model = fixture.getModel();
TransactionalEditingDomain domain = fixture.getEditingDomain();
assertThat("Root element must exist", model != null);
// Get the operation to rename
NamedElement relevantElement = TestElementUtils.getQualifiedElement(model, STATE_TO_RENAME);
assertThat("State is not found", relevantElement != null);
assertThat("Not a state", relevantElement instanceof State);
State state = (State) relevantElement;
assertThat("OperationalState stereotype is not applied",
// Relevant part
IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(state);
ICommand command = elementEditService.getEditCommand(new SetRequest(state, UMLPackage.Literals.NAMED_ELEMENT__NAME, NEW_NAME));
Assert.assertNotNull("Command should not be null", command);
Assert.assertTrue("Command should be executable", command.canExecute());
Command emfCommand = new GMFtoEMFCommandWrapper(command);
assertThat("State name was not updated", state.getName().equals(NEW_NAME));
With this code the test succeeds (the element is renamed) but the EditHelperAdvice is never called.
I though that this code should trigger the EditHelperAdvices (getAfterSetCommand in my case). My questions are:
1/ Is the code not adapted to do that ? What could be the correct way to do that?
2/ If this code should work, could it be an issue with my elementtypesconfiguration files?
I add that when I do the action (as a user) in an instance where my plugins are installed, I obtain the wanted behavior ((getAfterSetCommand method is well called).
Thanks for reading.
Powered by FUDForum
. Page generated in 0.01215 seconds