Commit 0aa741b8 authored by Dongyue Mou's avatar Dongyue Mou
Browse files

Mira SWT Bot test methods and the Export Report Summarization Action

refs 65
parent 8e1d1415
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.ui.action;
import java.io.File;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.fortiss.af3.mira.command.ExportReportSummarizationCommand;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.ui.AF3MiraUIActivator;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
/**
*
* @author Leonhard Uden
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class ExportReportSummarizationAction extends EObjectActionBase {
/** */
private Shell shell;
/**
* @param shell
* the default shell
* @param target
* the requirement to be exported
*/
public ExportReportSummarizationAction(Requirement target, Shell shell) {
super("ExportReportSummarization", AbstractUIPlugin
.imageDescriptorFromPlugin(AF3MiraUIActivator.PLUGIN_ID,
"icons/Icon_Requirement.png"));
setToolTipText("Export report summarization");
setTarget(target);
this.shell = shell;
}
/** {@inheritDoc} */
@Override
public void run() {
if (getTarget() == null) {
MessageDialog.openError(shell, "No requirement specified",
"No requirement is specified to export");
return;
}
FileDialog fsd = new FileDialog(shell);
fsd.setFilterExtensions(new String[] { "*.htm", "*.doc" });
fsd.setText("Select the name of the report summarization");
fsd.setOverwrite(false);
String file = fsd.open();
if (file.endsWith(".htm") || file.endsWith(".doc"))
file = file.substring(0, file.length() - 4);
File docfile = new File(file + ".doc");
File htmfile = new File(file + ".htm");
if (docfile.exists() || htmfile.exists()) {
if (!MessageDialog
.openConfirm(shell, "Overwrite the files?",
"The file selected exists already. Do you want to overwrite them?"))
return;
}
try {
new ExportReportSummarizationCommand((Requirement) getTarget(),
htmfile, docfile).call();
} catch (Exception e) {
e.printStackTrace();
ErrorDialog.openError(shell,
"Error while generating report summarization", e
.getMessage(), new Status(IStatus.ERROR,
AF3MiraUIActivator.PLUGIN_ID, 0,
"Cannot generate report summarization", e));
}
}
}
......@@ -244,7 +244,8 @@ public class RequirementEditor extends EditorBase<Requirement> {
DataBindingUtils.performComplexTextBinding(dbc, idInput, ObservableUtil
.observeValue(editedObject,
FortissToolingKernelPackage.Literals.IID_LABELED__ID),
new IDToStringConverter(), null, new StringToIDValidator(editedObject), null);
new IDToStringConverter(), null, new StringToIDValidator(
editedObject), null);
typeLabel = toolkit.createLabel(generalComposite, "Type ",
SWT.READ_ONLY);
......
......@@ -17,6 +17,10 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.belle2.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.InputStream;
import junit.framework.Assert;
......@@ -27,6 +31,9 @@ import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.usecase.UseCase;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
......@@ -45,6 +52,8 @@ import org.junit.runner.RunWith;
@RunWith(SWTBotJunit4ClassRunner.class)
public class EditorTest {
private final int zeroRows = 0;
private static SWTWorkbenchBot bot;
@BeforeClass
......@@ -84,6 +93,7 @@ public class EditorTest {
bot.textWithLabel("Project name:").setText("GeneralTestParentProject");
bot.button("Finish").click();
bot.sleep(1000);
}
@Test
......@@ -105,7 +115,7 @@ public class EditorTest {
SWTBotView view = bot.viewByTitle("Model Navigator");
view.bot().tree().select("Project").contextMenu("Requirement Analysis")
.click();
bot.sleep(2000);
// bot.sleep(2000);
}
......@@ -115,7 +125,7 @@ public class EditorTest {
view.bot().tree().expandNode("Project")
.getNode("Requirements Analysis")
.contextMenu("New Requirement").click();
bot.sleep(500);
// bot.sleep(500);
}
......@@ -135,12 +145,13 @@ public class EditorTest {
.setText("SWTBot Requirement Test Source");
editor.bot().textWithLabel("Todo ")
.setText("SWTBot Requirement Test ToDo");
bot.sleep(500);
// bot.sleep(500);
editor.bot().comboBoxWithLabel("Status ").setSelection("Analyzed");
editor.bot().comboBoxWithLabel("Priority ")
.setSelection("High - Must-be");
bot.sleep(500);
// bot.sleep(500);
}
@Test
......@@ -148,14 +159,28 @@ public class EditorTest {
SWTBotEditor editor = bot.editorByTitle("1");
editor.bot().button("Add").click();
bot.sleep(500);
bot.sleep(2000);
Assert.assertNotNull("A conflicted relation should have been added",
editor.bot().table().getTableItem("is conflicted with"));
// Assert.assertEquals("is conflicted with", editor.bot().ccomboBox(1)
// .getText());
editor.bot().table().click(0, 0);
editor.bot().ccomboBox("is conflicts with").setSelection("refines");
editor.bot().ccomboBox("is conflicted with").setSelection("refines");
bot.sleep(1000);
editor.bot().table().click(0, 0);
Assert.assertEquals(
"The conflict relation should have been changed to a \"refines\" relation",
"refines", (String) editor.bot().ccomboBox().getText());
bot.sleep(500);
editor.bot().table().click(0, 0);
editor.bot().button("Remove").click();
bot.sleep(500);
Assert.assertEquals(
"Number of rows should be zero, since no step should exist",
zeroRows, editor.bot().table().rowCount());
}
......@@ -164,7 +189,8 @@ public class EditorTest {
SWTBotEditor editor = bot.editorByTitle("1");
editor.bot().text("").setText("SWTBot Requirement Test Comment");
bot.sleep(500);
// bot.sleep(500);
}
@Test
......@@ -173,12 +199,13 @@ public class EditorTest {
editor.bot().toolbarButtonWithTooltip("Show Requirement Hierarchy")
.click();
bot.sleep(500);
// bot.sleep(500);
// editor.bot().toolbarButtonWithTooltip("Validate").click();
// editor.bot().toolbarButtonWithTooltip("Generate report").click();
// can only operate in eclipse(?), therefore windows of the OS cannot be
// blocked
}
@Test
......@@ -187,7 +214,8 @@ public class EditorTest {
view.bot().tree().expandNode("Project")
.getNode("Requirements Analysis").contextMenu("New Use Case")
.click();
bot.sleep(500);
// bot.sleep(500);
}
@Test
......@@ -206,12 +234,13 @@ public class EditorTest {
.setText("SWTBot Use Case Test Source");
editor.bot().textWithLabel("Todo ")
.setText("SWTBot Use Case Test ToDo");
bot.sleep(500);
// bot.sleep(500);
editor.bot().comboBoxWithLabel("Status ").setSelection("Analyzed");
editor.bot().comboBoxWithLabel("Priority ")
.setSelection("High - Must-be");
bot.sleep(500);
}
@Test
......@@ -228,7 +257,8 @@ public class EditorTest {
.setText("SWTBot Use Case Test min guarantee");
editor.bot().textWithLabel("Success guarantees ")
.setText("SWTBot Use Case Test suc. guarantee");
bot.sleep(500);
// bot.sleep(500);
}
// TODO Test not yet possible, Arch missing
......@@ -237,7 +267,8 @@ public class EditorTest {
public void canAssignScopeToUseCase() throws Exception {
SWTBotEditor editor = bot.editorByTitle("2");
editor.bot().buttonWithTooltip("Assign Scope").click();
bot.sleep(3000);
// bot.sleep(3000);
}
@Test
......@@ -253,39 +284,42 @@ public class EditorTest {
bot.button("OK").click();
shell.bot().button(0).click();
bot.button("OK").click();
bot.sleep(500);
// bot.sleep(500);
// Remove Actor_2
shell.bot().tree().expandNode("2").select("Actor_2");
shell.bot().button(1).click();
bot.button("OK").click();
bot.sleep(500);
// bot.sleep(500);
// Change Name of Actor_1
shell.bot().tree().expandNode("2").select("Actor_1");
shell.bot().button(2).click();
bot.text("Actor_1").setText("Hector");
bot.button("OK").click();
bot.sleep(500);
// bot.sleep(500);
shell.bot().button("OK").click();
bot.sleep(500);
// bot.sleep(500);
}
@Test
@Ignore
public void canAssignRelatedRequirementsToUseCase() throws Exception {
SWTBotEditor editor = bot.editorByTitle("2");
editor.bot().button("Add").click();
bot.sleep(500);
editor.bot().button("Add").click();
// bot.sleep(500);
editor.bot().table(1).click(0, 0);
editor.bot().ccomboBox("is conflicts with").setSelection("refines");
bot.sleep(500);
editor.bot().table().click(0, 0);
editor.bot().ccomboBox("is conflicted with").setSelection("refines");
// bot.sleep(500);
editor.bot().button("Remove").click();
bot.sleep(500);
// bot.sleep(500);
}
@Test
......@@ -293,7 +327,8 @@ public class EditorTest {
SWTBotEditor editor = bot.editorByTitle("2");
editor.bot().text("", 1).setText("SWTBot UseCase Test Comment");
bot.sleep(500);
// bot.sleep(500);
}
@Test
......@@ -302,12 +337,13 @@ public class EditorTest {
editor.bot().toolbarButtonWithTooltip("Show Requirement Hierarchy")
.click();
bot.sleep(500);
// bot.sleep(500);
// editor.bot().toolbarButtonWithTooltip("Validate").click();
// editor.bot().toolbarButtonWithTooltip("Generate report").click();
// can only operate in eclipse(?), therefore windows of the OS cannot be
// blocked
}
@Test
......@@ -316,7 +352,7 @@ public class EditorTest {
view.bot().tree().expandNode("Project")
.expandNode("Requirements Analysis").getNode("2")
.contextMenu("New Scenario").click();
bot.sleep(500);
// bot.sleep(500);
}
......@@ -326,9 +362,10 @@ public class EditorTest {
SWTBotEditor editor = bot.editorByTitle("Scenario (No name)");
editor.bot().textWithLabel("Name ").setText("SWT Bot Test Scenario");
bot.sleep(500);
// bot.sleep(500);
// editor.bot().checkBoxWithLabel("Success Scenario").click();
// editor.bot().toolbarButton("Success Scenario").click();
}
@Test
......@@ -338,46 +375,81 @@ public class EditorTest {
editor.bot().button("Add").click();
bot.sleep(500);
// at the moment not possible, the first actor is chosen automatically
// and cannot be changed
// editor.bot().table().click(0, 2);
// editor.bot().button("Hector").click();
// SWTBotShell shell = bot.activeShell();
// shell.bot().tree().expandNode("2").select("Hector");
// bot.sleep(500);
// shell.bot().button("OK").click();
// bot.sleep(500);
editor.bot().table().click(0, 1);
editor.bot().text("<no action>").setText("SWT Bot Test Action");
bot.sleep(500);
editor.bot().table().click(0, 2);
editor.bot().button("...").click();
SWTBotShell shell = bot.activeShell();
shell.bot().tree().expandNode("2").select("Hector");
bot.sleep(500);
shell.bot().button("OK").click();
bot.sleep(500);
editor.bot().table().click(0, 3);
editor.bot().ccomboBox("NotClassified").setSelection("External");
editor.bot().ccomboBox("").setSelection("External");
bot.sleep(500);
editor.bot().table().click(0, 4);
editor.bot().ccomboBox("")
.setSelection("SWT Bot Test Action(Scenario (No name))");
bot.sleep(500);
editor.bot().ccomboBox("").setSelection(0);
// .setText("SWT Bot Test Action(Scenario (No name))");
bot.sleep(3000);
}
@Test
public void canMoveAndRemoveScenarioSteps() throws Exception {
SWTBotEditor editor = bot.editorByTitle("Scenario (No name)");
editor.bot().table().click(0, 1);
bot.sleep(500);
editor.bot().button("Move Up").click();
bot.sleep(500);
editor.bot().table().click(0, 3);
assertEquals(
"Scenario with action rype \" External \" should be in the first row",
"External", (String) editor.bot().ccomboBox().getText());
editor.bot().button("Add").click();
editor.bot().table().click(1, 0);
bot.sleep(500);
editor.bot().table().click(1, 0);
editor.bot().button("Move Up").click();
editor.bot().table().click(0, 0);
bot.sleep(500);
editor.bot().table().click(1, 3);
assertEquals(
"Scenario with action rype \" External \" should be in the second row",
"External", (String) editor.bot().ccomboBox().getText());
editor.bot().table().click(0, 0);
editor.bot().button("Move Down").click();
editor.bot().table().click(1, 0);
bot.sleep(500);
editor.bot().table().click(0, 3);
assertEquals(
"Scenario with action rype \" External \" should be in the first row",
"External", (String) editor.bot().ccomboBox().getText());
editor.bot().table().click(1, 3);
editor.bot().button("Remove").click();
editor.bot().table().click(0, 3);
editor.bot().button("Remove").click();
bot.sleep(500);
Assert.assertEquals(
"Number of rows should be zero, since no step should exist",
zeroRows, editor.bot().table().rowCount());
}
@Test
@Ignore
public void areTestResultsConsistent() throws Exception {
bot.toolbarButtonWithTooltip("Save All (Ctrl+Shift+S)").click();
......@@ -398,4 +470,57 @@ public class EditorTest {
break;
}
}
@Test
public void areRequirementsObjectsExistent() throws Exception {
bot.menu("File").menu("Save All").click();
UseCase u = null;
Requirement r = null;
Analysis root = EditorTestUtil.getAnalysisFromFile();
assertNotNull(root);
for (int i = 0; i < root.getContainedElementsLength(); i++) {
if (root.getContainedElements(i) instanceof UseCase) {
u = (UseCase) root.getContainedElements(i);
assertNotNull(u.getName());
assertNotNull(u.getDescription());
assertNotNull(u.getRationale());
assertNotNull(u.getAuthor());
assertNotNull(u.getSources());
assertNotNull(u.getStatus());
assertNotNull(u.getPriority());
assertNotNull(u.getTodo());
assertNotNull(u.getScope());
assertNotNull(u.getTrigger());
assertNotNull(u.getPrecondition());
assertNotNull(u.getMinimalGuarantee());
assertNotNull(u.getSuccessGuarantee());
assertNotNull(u.getActorList());
assertNotNull(u.getComment());
assertNull(u.getConnections());
}
if (root.getContainedElements(i) instanceof UseCase) {
r = (Requirement) root.getContainedElements(i);
assertNotNull(r.getName());
assertNotNull(r.getDescription());
assertNotNull(r.getRationale());
assertNotNull(r.getAuthor());
assertNotNull(r.getSources());
assertNotNull(r.getStatus());
assertNotNull(r.getPriority());
assertNotNull(r.getTodo());
assertNotNull(r.getComment());
assertNull(r.getConnections());
}
}
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.belle2.test;
import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.tooling.kernel.utils.EMFResourceUtils;
/**
*
* @author Leonhard Uden
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public abstract class EditorTestUtil {
public static Analysis getAnalysisFromFile() {
Analysis analysis = null;
try {
IFile af3file = ResourcesPlugin.getWorkspace().getRoot()
.getProject("GeneralTestParentProject")
.getFile("SWTBotProject.af3_20");