Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary view navigation #150

Merged
merged 32 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ddc8806
added navigation buttons:
JKutscha Jul 16, 2021
aee9697
Restructered some tests and added test for summary
Jul 16, 2021
d71a67e
Fix for test of PitclipsePitSummaryViewTest
JKutscha Jul 16, 2021
7e9894f
Added wait condition to PitResultNotifier
JKutscha Jul 18, 2021
54a5cd0
Changed timeouts to fit better
JKutscha Jul 18, 2021
c6f83e6
Unused class which I forgot to delete
JKutscha Jul 18, 2021
bc44bc9
Merge branch 'master' into Summary_View_Navigation
JKutscha Jul 22, 2021
0219999
Merge branch 'master' into Summary_View_Navigation
JKutscha Jul 22, 2021
8569610
Merge branch 'master' into Summary_View_Navigation
JKutscha Jul 24, 2021
e3594ed
Removed bot click events and use reference
JKutscha Jul 24, 2021
d5e24ae
Merge branch 'master' into Summary_View_Navigation
JKutscha Jul 26, 2021
a2ea9c7
Introduced own waiting condition for the browser
JKutscha Jul 27, 2021
f1e8c98
Merge branch 'master' into Summary_View_Navigation
JKutscha Jul 27, 2021
7d68ef8
Updated condition for about:blank in summary view
JKutscha Jul 27, 2021
42d1cdf
Removed navigations to blank page
JKutscha Jul 27, 2021
639aa9b
Added fail, if the summary view can't be gotten
JKutscha Jul 27, 2021
0c93e12
Fixed typo, != instead of ==
JKutscha Jul 27, 2021
e8536ec
Revert back to use SWTBot for button clicks
JKutscha Jul 27, 2021
cf34b41
Merge branch 'master' into Summary_View_Navigation
JKutscha Jul 28, 2021
037d74e
Removed unused methods of PitView
JKutscha Jul 29, 2021
e5721da
Merge branch 'Summary_View_Navigation' of github.com:JKutscha/pitclip…
JKutscha Jul 29, 2021
65f5216
Code review fixes for comments of echebbi
JKutscha Jul 29, 2021
48b4a75
Wait for browser to load page in test instead of constucutor (PitSumm…
JKutscha Jul 29, 2021
07892bb
Added own test for testing while empty view
JKutscha Jul 29, 2021
96252b1
Removed not used fail
JKutscha Jul 29, 2021
ca75d8f
Merge branch 'master' into Summary_View_Navigation
JKutscha Aug 2, 2021
d3ee974
Close view using bot | create buttons and add them
JKutscha Aug 2, 2021
615e174
Merge remote-tracking branch 'origin/master' into Summary_View_Naviga…
Aug 3, 2021
2467ab1
Removed double brwoser creation, merge oversight
Aug 3, 2021
6e6f709
Test fix for codeCoverageReport generated after merge
JKutscha Aug 3, 2021
2421be6
Review fixes
Aug 4, 2021
fd53cc8
Merge branch 'master' into Summary_View_Navigation
JKutscha Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package org.pitest.pitclipse.ui.view;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;

import java.io.File;
Expand All @@ -29,15 +32,54 @@
* A view displaying the HTML report generated by PIT.
*/
public class PitView extends ViewPart implements SummaryView {
public final static String VIEW_ID = "org.pitest.pitclipse.ui.view.PitView";
echebbi marked this conversation as resolved.
Show resolved Hide resolved
private Browser browser = null;
private PitUiUpdatePublisher publisher = null;
private String homeUrlString = null;
private Action homeAction;
public static String HOME_BUTTON_TEXT = "Home";
echebbi marked this conversation as resolved.
Show resolved Hide resolved
private Action backButton;
public static String BACK_BUTTON_TEXT = "<";
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
private Action forwardButton;
public static String FORWARD_BUTTON_TEXT = ">";
JKutscha marked this conversation as resolved.
Show resolved Hide resolved

@Override
public synchronized void createPartControl(Composite parent) {
try {
browser = new Browser(parent, SWT.NONE);
publisher = new PitUiUpdatePublisher(browser);
browser.addProgressListener(publisher);
// create back button
backButton = new Action(BACK_BUTTON_TEXT) {
@Override
public void run() {
browser.back();
}
};
// create home button for navigation
homeAction = new Action(HOME_BUTTON_TEXT) {

JKutscha marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void run() {
if (homeUrlString != null) {
// only set url, if an home is set otherwise NPE
browser.setUrl(homeUrlString);
}
}
};
// create forward button
forwardButton = new Action(FORWARD_BUTTON_TEXT) {
@Override
public void run() {
browser.forward();
}
};
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolBar = actionBars.getToolBarManager();
toolBar.add(backButton);
toolBar.add(homeAction);
toolBar.add(forwardButton);
actionBars.updateActionBars();
} catch (SWTError e) {
MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
messageBox.setMessage("Browser cannot be initialized.");
Expand All @@ -54,8 +96,21 @@ public void setFocus() {
public synchronized void update(File result) {
if (result == null) {
browser.setText("<html/>");
homeUrlString = null;
} else {
browser.setUrl(result.toURI().toString());
homeUrlString = result.toURI().toString();
browser.setUrl(homeUrlString);
}
}

@Override
public void dispose() {
// reset homeUrlString for tests in
// org.pitest.pitclipse.ui.tests.PitclipsePitSummaryViewTest
homeUrlString = null;
if (browser != null && !browser.isDisposed()) {
browser.dispose();
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
}
super.dispose();
}
}
12 changes: 6 additions & 6 deletions tests/org.pitest.pitclipse.ui.tests/fragment.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<fragment>
<extension
point="org.pitest.pitclipse.ui.results">
<update
class="org.pitest.pitclipse.ui.swtbot.PitResultNotifier">
</update>
</extension>
<extension
point="org.pitest.pitclipse.core.executePit">
<pit_options
class="org.pitest.pitclipse.ui.swtbot.PitOptionsTestNotifier">
</pit_options>
</extension>
<extension
point="org.pitest.pitclipse.core.results">
<results
class="org.pitest.pitclipse.ui.swtbot.PitResultNotifier">
</results>
</extension>
</fragment>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private PageObjects() {
packageExplorer = new PackageExplorer(bot);
windowsMenu = new WindowsMenu(bot);
runMenu = new RunMenu(bot);
pitSummaryView = new PitSummaryView();
pitSummaryView = new PitSummaryView(bot);
pitMutationsView = new PitMutationsView(bot);
buildProgress = new BuildProgress(bot);
abstractSyntaxTree = new AbstractSyntaxTree();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,86 @@

package org.pitest.pitclipse.ui.behaviours.pageobjects;

import org.pitest.pitclipse.ui.behaviours.StepException;
import org.pitest.pitclipse.ui.swtbot.PitNotifier;
import org.pitest.pitclipse.ui.swtbot.PitResultsView;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import static org.pitest.pitclipse.ui.view.PitView.BACK_BUTTON_TEXT;
import static org.pitest.pitclipse.ui.view.PitView.FORWARD_BUTTON_TEXT;
import static org.pitest.pitclipse.ui.view.PitView.HOME_BUTTON_TEXT;

public class PitSummaryView {
private static String SUMMARY_VIEW_TITLE = "PIT Summary";
private SWTWorkbenchBot bot;
private SWTBotView summaryView;

private PitResultsView lastResults = null;

public PitSummaryView() {
public PitSummaryView(SWTWorkbenchBot bot) {
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
this.bot = bot;
}

public void waitForUpdate() {
try {
lastResults = PitNotifier.INSTANCE.getResults();
} catch (InterruptedException e) {
throw new StepException(e);
public void showViewIfNotOpen() {
if (summaryView == null) {
summaryView = bot.viewByTitle(SUMMARY_VIEW_TITLE);
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
}
summaryView.show();
}

public void clickButtonWithText(String text) {
showViewIfNotOpen();
bot.toolbarButton(text).click();
}

public String getCurrentBrowserUrl() {
showViewIfNotOpen();
return summaryView.bot().browser().getUrl();
}

public int getClassesTested() {
return lastResults.getClassesTested();
public String clickBack() {
clickButtonWithText(BACK_BUTTON_TEXT);
summaryView.bot().browser().waitForPageLoaded();
return getCurrentBrowserUrl();
}

public double getOverallCoverage() {
return lastResults.getTotalCoverage();
public String clickHome() {
clickButtonWithText(HOME_BUTTON_TEXT);
summaryView.bot().browser().waitForPageLoaded();
return getCurrentBrowserUrl();
}

public double getMutationCoverage() {
return lastResults.getMutationCoverage();
public String clickForward() {
clickButtonWithText(FORWARD_BUTTON_TEXT);
summaryView.bot().browser().waitForPageLoaded();
return getCurrentBrowserUrl();
}

/**
* Sets the link in the browser via javaScript, because bot can't click links in
* browser
* @param hyperLinkText link which to set as url, can be relative
* @return new url of browser
*/
public String setLink(String hyperLinkText) {
showViewIfNotOpen();
// use this instead of the SWTBrowser.execute(), because we need syncExec
final String link = "window.location.href = '" + hyperLinkText + "'";
summaryView.bot().browser().waitForPageLoaded();
UIThreadRunnable.syncExec(new VoidResult() {
@Override
public void run() {
summaryView.bot().browser().widget.execute(link);
}
});
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
summaryView.bot().browser().waitForPageLoaded();
return getCurrentBrowserUrl();
}

/**
* Closes the view, if it is opened.
*/
public void closeView() {
if (summaryView != null) {
showViewIfNotOpen();
summaryView.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void runJUnit() {
}

public void runPit() {
// focus package explorer to ensure the menu is found
bot.viewByTitle("Package Explorer").setFocus();
SWTBotMenuHelper menuHelper = new SWTBotMenuHelper();
SWTBotMenu runAsMenu = bot.menu(RUN)
.menu(RUN_AS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
import org.pitest.pitclipse.runner.PitOptions;
import org.pitest.pitclipse.runner.results.DetectionStatus;
import org.pitest.pitclipse.ui.behaviours.pageobjects.PackageContext;
import org.pitest.pitclipse.ui.behaviours.pageobjects.PitSummaryView;
import org.pitest.pitclipse.ui.swtbot.PitNotifier;
import org.pitest.pitclipse.ui.swtbot.PitResultNotifier.PitSummary;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
Expand All @@ -60,24 +59,24 @@
public class PitclipseSteps {

@When("test {word} in package {word} is run for project {word}")
public void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException {
public void runTest(final String testClassName, final String packageName, final String projectName)
throws CoreException {
// No need to do a full build: we should be now synchronized with building
// Build the whole workspace to prevent random compilation failures
// ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
System.out.println
(String.format("Run PIT on: %s %s.%s",
projectName, packageName, testClassName));
// ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD,
// new NullProgressMonitor());
System.out.println(String.format("Run PIT on: %s %s.%s", projectName, packageName, testClassName));
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
runPit(new SelectTestClass(testClassName, packageName, projectName));
}

@Then("a coverage report is generated with {int} class/classes tested with overall coverage of {int}% and mutation coverage of {int}%")
public void coverageReportGenerated(int classes, double totalCoverage, double mutationCoverage) {
PitSummaryView pitView = PAGES.getPitSummaryView();
pitView.waitForUpdate();
PAGES.views().waitForTestsAreRunOnConsole();
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
try {
assertEquals("Number of tested classes mismatch", classes, pitView.getClassesTested());
assertDoubleEquals("Total coverage mismatch", totalCoverage, pitView.getOverallCoverage());
assertDoubleEquals("Mutation coverage mismatch", mutationCoverage, pitView.getMutationCoverage());
assertEquals("Number of tested classes mismatch", classes, PitSummary.INSTANCE.getClasses());
assertDoubleEquals("Total coverage mismatch", totalCoverage, PitSummary.INSTANCE.getCodeCoverage());
assertDoubleEquals("Mutation coverage mismatch", mutationCoverage,
PitSummary.INSTANCE.getMutationCoverage());
} catch (Error e) {
e.printStackTrace();
throw e;
Expand Down Expand Up @@ -161,8 +160,8 @@ private void runPit(Runnable runnable) {
// make sure to clear the console to avoid interferences
// with the output of previous runs
PAGES.views().clearConsole();
// make sure notifications not read are cleared
PitNotifier.INSTANCE.reset();
// make sure summary is cleared
PitSummary.INSTANCE.reset();
int retryCount = 20;
int counter = 0;
while (counter < retryCount) {
Expand Down

This file was deleted.

Loading