Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Testing Graphiti editor
Testing Graphiti editor [message #950151] Fri, 19 October 2012 17:24 Go to next message
Junior Lekane Nimpa is currently offline Junior Lekane NimpaFriend
Messages: 23
Registered: September 2012
Junior Member
Hello all,

I implemented in a plug-in (plugin_1) a Graphiti-Editor and with a new plugin(plugin_2) i want to test plugin_1. plugin_2 does not depend on plugin_1

- is it good or bad ?

I had a look at the plugin "org.eclipse.graphiti.bot.tests" and i want basically to follow the same approach. So i use a class "AbstractTest" that should be the base class. This class should create a diagram with a type as registred in plugin_1 and a diagram editor to edit the diagram . Following are the relevant methods
Fragment 1:
 
         /**
	 * Get the editor needed to edit diagram
	 * @return the diagram editor
	 */
	protected DiagramEditor getDiagramEditor(){
		if(diagramEditor == null){
			diagramEditor = syncExec(new Result<DiagramEditor>(){
				public DiagramEditor run(){
					Diagram d = getDiagram();
					assertNotNull("diagram could not be created",d);
					
					DiagramEditor de = (DiagramEditor)GraphitiUiInternal.getWorkbenchService().
							openDiagramEditor(d);
					return de;
				}
			});
			/*
			 * Complete here .
			 */
		}
		return diagramEditor;
	}



Fragment 2:
/**
	 * Get the diagram if it exists,
	 * otherwise create diagram and diagram file
	 * @return the diagram
	 */
	protected Diagram getDiagram(){
		if(diagram == null){
			String diagramName = getDiagramFileName();
			URI diagramURI = getDiagramFileURI();
			diagram = getPeService().createDiagram(TestConstant.DIAGRAM_TYPE, diagramName, true);
			
			// yield to an exception ..
			//FileService.createEmfFileForDiagram(diagramURI, diagram);
			
			final TransactionalEditingDomain editingDomain = GraphitiUiInternal.getEmfService()
					.createResourceSetAndEditingDomain();
			final ResourceSet resourceSet = editingDomain.getResourceSet();
			final Resource diagramResource = resourceSet.createResource(diagramURI);
			URI uri = diagramResource.getURI();
			//diagramResource.getContents().add(diagram);
			editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain){
				@Override
				protected void doExecute(){
					diagramResource.setTrackingModification(true);
					diagramResource.getContents().add(diagram);
				}
			});
			try{
				diagramResource.save(null);
			}catch(Exception e){}
			
			diagramEditorPageObject.setEditingDomain(editingDomain);
		}
		return diagram;
	}


This is basically the same code as in the plugin "org.eclipse.graphiti.bot.tests"
In Fragment 2, you can see that i commented the following line
FileService.createEmfFileForDiagram(diagramURI, diagram);

This line yield to an IO.Exception, so i changed the code as you can see above because i was not able to solve this exception. (Any hint ??)
Note that i use in Framgent 2 the String-variable TestConstant.DIAGRAM_TYPE,to pass the name of the diagram type as defined in plugin_1.
With the above methods i can create a non-null diagram and diagram editor, but the following returs always null:
diagramEditor.getDiagramTypeProvider()
My main problem is that i can not
- create a diagram in plugin_2 with a diagram type as defined in plugin_1
- create a diagram editor in plugin_2 that give me a non null diagram type provider

It will be really great, if someone could give me an hint and/or answer.
Thanks so much
Junior
Re: Testing Graphiti editor [message #963148 is a reply to message #950151] Mon, 29 October 2012 15:55 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Junior,

having a dependency from the test plugin to to plugin-under-test is usually
needed because you will need to access classes from that plugin. Why would
you like to omit that?

The editor opening and querying the editor for the providers fails because
the editor relies on an existing file and cannot be correctly initilaized in
case the file not exists (commented-out method createEmfFileFor...).

How are the diagramName and diagramUri variables initialized?

Michael
Previous Topic:GraphitiInternal.getEmfService()
Next Topic:How can i implement Drag and Drop feature with in the diagram
Goto Forum:
  


Current Time: Tue Apr 16 04:39:17 GMT 2024

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

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

Back to the top