Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » JUnit testing of GEF application
JUnit testing of GEF application [message #231576] Mon, 12 March 2007 04:11 Go to next message
Eclipse UserFriend
Originally posted by: sushant.sirsikar.gmail.com

Hello Everyone,
I developed one application using GEF. Now i want to use strategy XP(
extreme Programming) to modify it. How can i use jUnit testing framework
to test it? Is it possible to to test GEF application using jUnit? Can i
create dummy request to test the commands? How can i check GUI events
which are generated by GEF?( for example .... i clicked on pallet and
drag one object on graphical window) I want all test scripts to be run
automatically. Please help me with your suggestions and examples or
documentations if you have any. Thanks in advance.

Sushant
Re: JUnit testing of GEF application [message #231584 is a reply to message #231576] Mon, 12 March 2007 09:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jakub.jurkiewicz.gmail.com

Hi Sushant,

I used to have the same problem until I started using Easy Mock
http://www.easymock.org/ . Thanks to it, you can create a mocks objects
that can simulate a behavior of GEF components.
Here http://www.easymock.org/EasyMock2_2_Documentation.html you can find
some examples, which just have to be transformed into GEF specific ones.

If anyone knows any other ways to test GEF applications, please let us
know :)

Hope this helps,
Jakub Jurkiewicz

Sushant wrote:
> Hello Everyone,
> I developed one application using GEF. Now i want to use strategy XP(
> extreme Programming) to modify it. How can i use jUnit testing framework
> to test it? Is it possible to to test GEF application using jUnit? Can i
> create dummy request to test the commands? How can i check GUI events
> which are generated by GEF?( for example .... i clicked on pallet and
> drag one object on graphical window) I want all test scripts to be run
> automatically. Please help me with your suggestions and examples or
> documentations if you have any. Thanks in advance.
>
> Sushant
>
Re: JUnit testing of GEF application [message #231610 is a reply to message #231584] Mon, 12 March 2007 20:45 Go to previous message
Thomas Maier is currently offline Thomas MaierFriend
Messages: 117
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050103070407050408090209
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi Sushant, hi Jakub, do you have some code to share? Here is some I
hacked a while ago. Beware, it's ugly. Basically, I send fake events,
to simulate user input and test the whole flow down to the code finally
handling the events. Not very nice to program, though. Once I tried
feeding events into a DomainEventDispatcher to work around problems with
the reliability of the event processing. However, this had the problem
that I could not test direct edit actions.

It works on Linux, does not really work on MacOS and is untested on Windows.

HTH, Thomas.


Jakub Jurkiewicz wrote:
> Hi Sushant,
>
> I used to have the same problem until I started using Easy Mock
> http://www.easymock.org/ . Thanks to it, you can create a mocks
> objects that can simulate a behavior of GEF components.
> Here http://www.easymock.org/EasyMock2_2_Documentation.html you can
> find some examples, which just have to be transformed into GEF
> specific ones.
>
> If anyone knows any other ways to test GEF applications, please let us
> know :)
>
> Hope this helps,
> Jakub Jurkiewicz
>
> Sushant wrote:
>> Hello Everyone,
>> I developed one application using GEF. Now i want to use strategy
>> XP( extreme Programming) to modify it. How can i use jUnit testing
>> framework to test it? Is it possible to to test GEF application using
>> jUnit? Can i create dummy request to test the commands? How can i
>> check GUI events which are generated by GEF?( for example .... i
>> clicked on pallet and drag one object on graphical window) I want all
>> test scripts to be run automatically. Please help me with your
>> suggestions and examples or documentations if you have any. Thanks
>> in advance.
>>
>> Sushant
>>


--------------050103070407050408090209
Content-Type: text/x-java;
name="UITestCase.java"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="UITestCase.java"

/*
* Janus Plugin -- Java'n'UML Simultanously.
*
* Janus Plugin aims to extend Eclipse's Java Environment with UML editing capabilities.
* Java code and UML diagrams can both be edited and update each other.
*
* Copyright (C) 2003, 2004, 2005, 2006, 2007 Thomas Maier, University of Kassel.
*
* Janus Plugin is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software Foundation;
* Janus Plugin is licensed using version 2 of the License and not any later version.
*
* Janus Plugin is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
* 330, Boston, MA 02111-1307 USA
*
* Contact Address:
*
* URL: janus-plugin.sourceforge.net
* email: Thomas.Maier@uni-kassel.de
*
* Thomas Maier
* University of Kassel
* Research Group Software Engineering
* Wilhelmshöher Allee 73
* 34121 Kassel
* Germany
*/

package de.unikassel.janus.tests;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.uml2.uml.Model;

import de.unikassel.janus.classdiagrams.editor.palette.ClassDiagram EditorPalette;
import de.unikassel.janus.uml2.JanusUML2;


public abstract class UITestCase extends TestCase
{
public static final String OUTLINE_VIEW_ID = "org.eclipse.ui.views.ContentOutline";
public static final String RESOURCE_PERSPECTIVE_ID= "org.eclipse.ui.resourcePerspective";

private Display display;
private Shell workbenchShell;
private IWorkbenchWindow workbenchWindow;


public void runBare() throws Throwable
{
if (getName().startsWith("uitest"))
{
runBareHack();
}
else
{
super.runBare();
}
}

private void runBareHack() throws Exception, Throwable
{
System.err.println("runBare() hack for " + getName() + " in " + this);
setUp();
try
{
for (int i=0; i<getVoodooCount(); ++i)
{
try
{
setUpUITest();
runTest();
}
finally
{
tearDownUITest();
}
}
}
finally
{
tearDown();
}
}

public static Test createSuiteHack(Class uiTestCaseClass)
{
// Collect all "standard" junit testFoo() methods.
TestSuite standardJUnitTestSuite = new TestSuite(uiTestCaseClass);
TestSuite suite = standardJUnitTestSuite;

// If there is no standard testFoo() method, TestSuite will add a warning.
if (suite.testCount() == 1 && suite.testAt(0) instanceof TestCase)
{
TestCase testCase = (TestCase) suite.testAt(0);
if (testCase.getName().equals("warning"))
{
suite = new TestSuite(uiTestCaseClass.getName());
}
}

// Now add all "UI test" uitestFoo() methods.
Method[] methods = uiTestCaseClass.getDeclaredMethods();
for (Method method : methods)
{
if (method.getName().startsWith("uitest"))
{
suite.addTest(TestSuite.createTest(uiTestCaseClass, method.getName()));
}
}

// If there is no testFoo() or uitestFoo() method, take the warning :).
if (suite.testCount() == 0)
{
suite = standardJUnitTestSuite;
}

return suite;
}


protected void setUpUITest() throws Exception
{
// Do nothing
}

protected void tearDownUITest() throws Exception
{
// Do nothing
}

@Override
protected void setUp() throws Exception
{
super.setUp();

display = Display.getCurrent();

// Close all perspectives but Resource, close all views, set workbench window size.
workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
workbenchShell = workbenchWindow.getShell();
IWorkbenchPage page = workbenchWindow.getActivePage();
boolean foundPerspective = false;
IPerspectiveDescriptor[] perspectives = page.getOpenPerspectives();
for (int i = 0; i < perspectives.length; i++)
{
IPerspectiveDescriptor perspective = perspectives[i];
if (perspective.getId().equals(RESOURCE_PERSPECTIVE_ID))
{
foundPerspective = true;
}
else
{
page.closePerspective(perspective, false, false);
}
}
if (!foundPerspective)
{
PlatformUI.getWorkbench().showPerspective(RESOURCE_PERSPECTI VE_ID, workbenchWindow);
}
IViewReference[] views = page.getViewReferences();
for (int i = 0; i < views.length; i++)
{
page.hideView(views[i]);
}
workbenchWindow.getShell().setSize(1000, 800);
}

@Override
protected void tearDown() throws Exception
{
super.tearDown();
}

protected Display getDisplay()
{
return display;
}

protected Shell getWorkbenchShell()
{
return workbenchShell;
}

protected IWorkbenchWindow getWorkbenchWindow()
{
return workbenchWindow;
}

/**
* I do not really understand what to do to make this "post events and read and dispatch them"
* thing work reliably. It seems to have to do with the number of times I call
* display.readAndDispatch() and the amount of millis I sleep. However, letting the tests run
* several times seems to reliably expose if things work or do not work. In other words, if the
* tests run several times and pass then probably everything is good. I have seen things pass
* two times and fail at the third time, so I bump this up to 5 here to kind of be on the safe
* side.
*
* This weird thing is probably dependent on the machine's performance it is run on.
*/
protected int getVoodooCount()
{
try
{
return Integer.valueOf(System.getProperty("JanusTests.VoodooCount", "5"));
}
catch (NumberFormatException e)
{
return 5;
}
}

/**
* @return number of times <code>display.readAndDispatch()</code> is called
*/
private int getReadAndDispatchVoodooCount()
{
return 5;
}

/**
* @return number of milliseconds to <code>sleep()</code> between
* <code>display.readAndDispatch()</code> calls
*/
private int getReadAndDispatchVoodooSleep()
{
return 1;
}

/**
* Return the number of milliseconds to prevent two consecutive mouse clicks being interpreted
* as a double click.
*
* @return the number of milliseconds to prevent two consecutive mouse clicks being interpreted
* as a double click
*/
protected int getPreventDoubleClickTime()
{
return Display.getCurrent().getDoubleClickTime() + 100;
}

/**
* Return the delay in milliseconds that a direct edit operation starts with.
*
* @return the delay that a direct edit operation starts with
*/
protected int getDirectEditDelay()
{
return 400;
}

protected IEditorPart openEditor(IFile file) throws PartInitException
{
return IDE.openEditor(getWorkbenchWindow().getActivePage(), file);
}

protected void closeEditor(IEditorPart editor)
{
editor.getEditorSite().getPage().closeEditor(editor, false);
}

protected IProject getOrCreateProject(String projectName) throws CoreException
{
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
if (!project.exists()) { project.create(null); }
if (!project.isOpen()) { project.open(null); }

IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = JavaCore.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, null);
JavaCore.create(project);

return project;
}

protected IFile createEmptyDiagramFile(String projectName, String fileName) throws CoreException, IOException
{
Model model = JanusUML2.createModel();
model.setName("emptyDiag");
return createDiagramFile(projectName, fileName, model);
}

protected IFile createDiagramFile(String projectName, String fileName, Model model) throws CoreException, IOException
{
IProject project = getOrCreateProject(projectName);
IFile file = project.getFile(fileName);
ByteArrayOutputStream outputStream = JanusUML2.createStream(model, file);
file.create(new ByteArrayInputStream(outputStream.toByteArray()), false, null);
JanusUML2.disposeDiagram(file);
return file;
}

protected void deleteFile(String projectName, String fileName) throws CoreException
{
IProject project = getOrCreateProject(projectName);
IFile file = project.getFile(fileName);
if (file.exists())
{
file.delete(false, null);
}
}

protected void selectTool(GraphicalViewer graphicalViewer, String toolID)
{
PaletteViewer paletteViewer = graphicalViewer.getEditDomain().getPaletteViewer();
ClassDiagramEditorPalette palette = (ClassDiagramEditorPalette) paletteViewer.getPaletteRoot();
paletteViewer.setActiveTool(ClassDiagramEditorPalette.findTo olEntry(palette, toolID));
}


protected Event post(Event event)
{
/*
* It seems I do not need to fill in the time and current mouse pointer position. Let's see.
*/
getDisplay().post(event);
readAndDispatchEvents();
return event;
}

protected void activateDirectEdit()
{
postTwoLeftMouseClicks();
sleep(getDirectEditDelay());
}

protected void postTwoLeftMouseClicks()
{
postLeftMouseClick();
sleep(getPreventDoubleClickTime());
postLeftMouseClick();
}

protected void postLeftMouseClick()
{
postMouseClick(1);
}

protected void postMouseClick(int button)
{
postMouseDown(button);
postMouseUp(button);
}

protected void postLeftMouseDrag(Control control, int x, int y)
{
postMouseDrag(control, 1, x, y);
}

protected void postMouseDrag(Control control, int button, int x, int y)
{
postMouseDown(button);
postMouseMove(control, x, y, SWT.BUTTON1); // FIXME
postMouseUp(button); // FIXME: See below: statemask
}
/* mouse drag:
mouse down: MouseEvent{FigureCanvas {} time=15876882 data=null button=1 stateMask=0 x=137 y=92}
mouse move: MouseEvent{FigureCanvas {} time=15879432 data=null button=0 stateMask=524288 x=138 y=92}
mouse move: MouseEvent{FigureCanvas {} time=15887473 data=null button=0 stateMask=524288 x=139 y=92}
mouse up: MouseEvent{FigureCanvas {} time=15892969 data=null button=1 stateMask=524288 x=139 y=92}
*/

protected Event postMouseDown(int button)
{
Event event = new Event();
event.type = SWT.MouseDown;
event.button = button;
return post(event);
}

protected Event postMouseUp(int button)
{
Event event = new Event();
event.type = SWT.MouseUp;
event.button = button;
return post(event);
}

protected Event postMouseMove(Control control, org.eclipse.draw2d.geometry.Point point)
{
return postMouseMove(control, point.x, point.y, SWT.NONE);
}

protected Event postMouseMove(Control control, int x, int y)
{
return postMouseMove(control, x, y, SWT.NONE);
}

protected Event postMouseMove(Control control, int x, int y, int stateMask)
{
Point point = getDisplay().map(control, null, x, y);
Event event = new Event();
event.type = SWT.MouseMove;
event.x = point.x;
event.y = point.y;
event.stateMask = stateMask;
return post(event);
}


protected void postDoubleEscape()
{
postKey(SWT.ESC);
postKey(SWT.ESC);
}

protected void postKeys(String string)
{
for (int i=0; i<string.length(); i++)
{
char character = string.charAt(i);
boolean shift = Character.isUpperCase(character);
character = Character.toLowerCase(character);
if (shift)
{
postKeyDown(SWT.SHIFT);
}
postKeyDown(character);
postKeyUp(character);
if (shift)
{
postKeyUp(SWT.SHIFT);
}
}
}

protected void postKey(char character)
{
postKeyDown(character);
postKeyUp(character);
}

protected Event postKeyDown(char character)
{
Event event = new Event();
event.type = SWT.KeyDown;
event.character = character;
return post(event);
}

protected Event postKeyUp(char character)
{
Event event = new Event();
event.type = SWT.KeyUp;
event.character = character;
return post(event);
}

protected void postKey(int keyCode)
{
postKeyDown(keyCode);
postKeyUp(keyCode);
}

protected Event postKeyDown(int keyCode)
{
Event event = new Event();
event.type = SWT.KeyDown;
event.keyCode = keyCode;
return post(event);
}

protected Event postKeyUp(int keyCode)
{
Event event = new Event();
event.type = SWT.KeyUp;
event.keyCode = keyCode;
return post(event);
}


protected void sleep(long millis)
{
try { Thread.sleep(millis); } catch (InterruptedException e) { /* Empty */ }
}

protected void readAndDispatchEvents()
{
readAndDispatchEventsLoop(getReadAndDispatchVoodooCount(), getReadAndDispatchVoodooSleep());
}

private void readAndDispatchEventsLoop(int times, int millis)
{
while (times > 0)
{
readAndDispatchEventsOnce();
sleep(millis);
--times;
}
}

private void readAndDispatchEventsOnce()
{
while (getDisplay().readAndDispatch())
{
// Do nothing.
}
}


protected void waitUserInput()
{
getDisplay().syncExec(new Runnable() {
public void run()
{
waitForMessageBox();
}
});
}

void waitForMessageBox()
{
final Shell shell = new Shell(getDisplay(), SWT.NO_FOCUS );
shell.setText("Bla Shell");
shell.setLocation(1500, 100);
shell.setSize(50, 50);
shell.open();
while (true)
{
MessageBox box = new MessageBox(shell, SWT.NO_FOCUS | SWT.OK | SWT.PRIMARY_MODAL);
box.setText("bla");
box.setMessage("Click to continue.");
box.open();
break;
}
shell.close();
}

/**
* Without this, Draw2D figures have bounds (0, 0, 0, 0).
*/
protected void warmupDraw2D()
{
readAndDispatchEvents();
}

protected org.eclipse.draw2d.geometry.Point getLeftSide(IFigure figure)
{
Rectangle bounds = figure.getBounds();
return new org.eclipse.draw2d.geometry.Point(bounds.x + 3, bounds.y + bounds.height/2);
}

protected org.eclipse.draw2d.geometry.Point getCenter(IFigure figure)
{
Rectangle bounds = figure.getBounds();
return new org.eclipse.draw2d.geometry.Point(bounds.x + bounds.width/2, bounds.y + bounds.height/2);
}
}

--------------050103070407050408090209
Content-Type: text/x-java;
name="DirectEditTest.java"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="DirectEditTest.java"

/*
* Janus Plugin -- Java'n'UML Simultanously.
*
* Janus Plugin aims to extend Eclipse's Java Environment with UML editing capabilities.
* Java code and UML diagrams can both be edited and update each other.
*
* Copyright (C) 2003, 2004, 2005, 2006, 2007 Thomas Maier, University of Kassel.
*
* Janus Plugin is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software Foundation;
* Janus Plugin is licensed using version 2 of the License and not any later version.
*
* Janus Plugin is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
* 330, Boston, MA 02111-1307 USA
*
* Contact Address:
*
* URL: janus-plugin.sourceforge.net
* email: Thomas.Maier@uni-kassel.de
*
* Thomas Maier
* University of Kassel
* Research Group Software Engineering
* Wilhelmshöher Allee 73
* 34121 Kassel
* Germany
*/

package de.unikassel.janus.tests;

import junit.framework.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.ui.IEditorPart;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Property;

import de.unikassel.janus.classdiagrams.editparts.AttributeEditPart ;
import de.unikassel.janus.classdiagrams.editparts.ClassEditPart;
import de.unikassel.janus.classdiagrams.model.commands.CreateAttrib uteCommand;
import de.unikassel.janus.classdiagrams.model.commands.CreateClassC ommand;


public class DirectEditTest extends UITestCase
{
private IFile file;
private IEditorPart editorPart;
private Model model;
private CommandStack commandStack;
private GraphicalViewer graphicalViewer;

public static Test suite()
{
return createSuiteHack(DirectEditTest.class);
}

@Override
protected void setUp() throws Exception
{
super.setUp();
file = createEmptyDiagramFile("de.unikassel.janus.tests", "DirectEditTest.uml");
}

@Override
protected void tearDown() throws Exception
{
file.delete(false, null);
super.tearDown();
}

@Override
protected void setUpUITest() throws Exception
{
editorPart = openEditor(file);
model = (Model) editorPart.getAdapter(Model.class);
commandStack = (CommandStack) editorPart.getAdapter(CommandStack.class);
graphicalViewer = (GraphicalViewer) editorPart.getAdapter(GraphicalViewer.class);
}

@Override
protected void tearDownUITest() throws Exception
{
closeEditor(editorPart);
}

public void uitestRenameClass() throws Exception
{
CreateClassCommand createClassCommand = CommandTest.createClass(commandStack, model, 50, 50);
org.eclipse.uml2.uml.Class uml2Class = createClassCommand.getNewClass();

warmupDraw2D();

String newClassName = "Foobar";
assertFalse(newClassName.equals(uml2Class.getName())); // be sure to test something

ClassEditPart classEditPart = (ClassEditPart) graphicalViewer.getEditPartRegistry().get(uml2Class);
postMouseMove(graphicalViewer.getControl(), getLeftSide(classEditPart.getFigure()));
activateDirectEdit();
postKeys(newClassName + "\r");
assertEquals(newClassName, uml2Class.getName());
}

public void uitestRenameAttribute() throws Exception
{
CreateClassCommand createClassCommand = CommandTest.createClass(commandStack, model, 50, 50);
org.eclipse.uml2.uml.Class uml2Class = createClassCommand.getNewClass();

CreateAttributeCommand createAttributeCommand = CommandTest.createAttribute(commandStack, uml2Class);
Property attribute = createAttributeCommand.getNewClassMember();

warmupDraw2D();

String newAttributeName = "foo";
assertFalse(newAttributeName.equals(attribute.getName())); // be sure to test something

AttributeEditPart attributeEditPart = (AttributeEditPart) graphicalViewer.getEditPartRegistry().get(attribute);
postMouseMove(graphicalViewer.getControl(), getLeftSide(attributeEditPart.getFigure()));
activateDirectEdit();
postKeys(newAttributeName + "\r");
assertEquals(newAttributeName, attribute.getName());
}
}

--------------050103070407050408090209
Content-Type: text/x-java;
name="ClassTest.java"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="ClassTest.java"

/*
* Janus Plugin -- Java'n'UML Simultanously.
*
* Janus Plugin aims to extend Eclipse's Java Environment with UML editing capabilities.
* Java code and UML diagrams can both be edited and update each other.
*
* Copyright (C) 2003, 2004, 2005, 2006, 2007 Thomas Maier, University of Kassel.
*
* Janus Plugin is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software Foundation;
* Janus Plugin is licensed using version 2 of the License and not any later version.
*
* Janus Plugin is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
* 330, Boston, MA 02111-1307 USA
*
* Contact Address:
*
* URL: janus-plugin.sourceforge.net
* email: Thomas.Maier@uni-kassel.de
*
* Thomas Maier
* University of Kassel
* Research Group Software Engineering
* Wilhelmshöher Allee 73
* 34121 Kassel
* Germany
*/

package de.unikassel.janus.tests;

import junit.framework.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Type;

import de.unikassel.janus.classdiagrams.editor.palette.ClassDiagram EditorPalette;
import de.unikassel.janus.uml2.JanusUML2;


public class ClassTest extends UITestCase
{
private IFile file;
private IEditorPart editorPart;
private Model model;
private GraphicalViewer graphicalViewer;

public static Test suite()
{
return createSuiteHack(ClassTest.class);
}

@Override
protected void setUp() throws Exception
{
super.setUp();
file = createEmptyDiagramFile("de.unikassel.janus.tests", "ClassTest.uml");
}

@Override
protected void setUpUITest() throws Exception
{
editorPart = openEditor(file);
model = (Model) editorPart.getAdapter(Model.class);
graphicalViewer = (GraphicalViewer) editorPart.getAdapter(GraphicalViewer.class);
}

@Override
protected void tearDownUITest() throws Exception
{
closeEditor(editorPart);
}

public void uitestCreateMoveResizeClass() throws Exception
{
assertEquals(0, model.getOwnedTypes().size());

/*
* Is this a GEF bug? It seems the mouse always has to be moved after activating a tool.
*/
postMouseMove(graphicalViewer.getControl(), 50, 60);
postLeftMouseClick();
selectTool(graphicalViewer, ClassDiagramEditorPalette.TOOL_ID_NEW_CLASS);
postMouseMove(graphicalViewer.getControl(), 70, 80);
postLeftMouseClick();
assertEquals(1, model.getOwnedTypes().size());
Type newClass = model.getOwnedType("NewClass");
assertNotNull(newClass);
assertEquals(new Point(70, 80), JanusUML2.getLocation(newClass));

postMouseMove(graphicalViewer.getControl(), 70+10, 80+10);
postLeftMouseDrag(graphicalViewer.getControl(), 70+10+50, 80+10+60);
assertEquals(new Point(70+50+1, 80+60+1), JanusUML2.getLocation(newClass)); // FIXME: why +1?

GraphicalEditPart newClassEditPart = (GraphicalEditPart) graphicalViewer.getEditPartRegistry().get(newClass);
Dimension size = newClassEditPart.getFigure().getSize();
postMouseMove(graphicalViewer.getControl(), 120, 140);
postLeftMouseDrag(graphicalViewer.getControl(), 120-20, 140-10);
Dimension changedSize = newClassEditPart.getFigure().getSize();
assertEquals(size.width + 20, changedSize.width);
assertEquals(size.height+ 10, changedSize.height);
}
}

--------------050103070407050408090209--
Previous Topic:REQ_MOVE and overlapping Layers problem
Next Topic:Advanced Zooming
Goto Forum:
  


Current Time: Mon Dec 11 04:03:48 GMT 2017

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

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