Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Tests using EditHelperAdvice classes
Tests using EditHelperAdvice classes [message #1817901] Mon, 02 December 2019 15:52 Go to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
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",
				isStereotypeApplied(state, OperationalState.class));

// 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);
		domain.getCommandStack().execute(emfCommand);
		
		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.
Regards.
Yoann.



Re: Tests using EditHelperAdvice classes [message #1817903 is a reply to message #1817901] Mon, 02 December 2019 16:35 Go to previous message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hi,

I found why it didn't work. I replaced a simple ModelSetFixture by ServiceRegistryModelSetFixture

	@Rule
	public ModelSetFixture modelSet = new ServiceRegistryModelSetFixture();

Previous Topic:Temporarily apply stylesheet for document generation
Next Topic:from CSV to UML use case diagram
Goto Forum:
  


Current Time: Thu Apr 25 09:18:46 GMT 2024

Powered by FUDForum. Page generated in 0.04493 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top