Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2019-06-25 17:30:32 -0400
committerPatrick Tasse2019-07-10 09:58:30 -0400
commit2434d4b409cfbe87f1b1b4c9e89203688c0e7453 (patch)
treef5288aa3b2ebb5cd7d49799ffb1009c96cd0e791
parenta43df20e648db8a35a4a2d6c196d400e19dc7217 (diff)
downloadorg.eclipse.tracecompass-2434d4b409cfbe87f1b1b4c9e89203688c0e7453.tar.gz
org.eclipse.tracecompass-2434d4b409cfbe87f1b1b4c9e89203688c0e7453.tar.xz
org.eclipse.tracecompass-2434d4b409cfbe87f1b1b4c9e89203688c0e7453.zip
swtbot: Fix XYDataProviderBaseTest.isChartDataValid() JSON file path
Make sure the JSON file's absolute path is taken from the proper bundle. This allows running the test from another plug-in's stress test. Change-Id: I329304bca3e194a4bb9e45fad1eeb94287640845 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/144890 Tested-by: CI Bot Reviewed-by: Simon Delisle <simon.delisle@ericsson.com>
-rw-r--r--lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/DisksIOViewTest.java43
-rw-r--r--tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java30
2 files changed, 32 insertions, 41 deletions
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/DisksIOViewTest.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/DisksIOViewTest.java
index 8fc7c28874..95ba6029a4 100644
--- a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/DisksIOViewTest.java
+++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/DisksIOViewTest.java
@@ -12,15 +12,6 @@ package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
@@ -40,7 +31,6 @@ import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfCommonXAxisChartViewer;
import org.eclipse.ui.IViewPart;
import org.junit.Test;
-import org.osgi.framework.Bundle;
import org.swtchart.Chart;
import org.swtchart.ISeries;
import org.swtchart.LineStyle;
@@ -64,21 +54,14 @@ public class DisksIOViewTest extends XYDataProviderBaseTest {
private static final @NonNull ITmfTimestamp ZOOM_START_TIME = TmfTimestamp.fromNanos(1361214078967381303L);
private static final @NonNull ITmfTimestamp ZOOM_END_TIME = TmfTimestamp.fromNanos(1361214078967971599L);
- private static final Bundle BUNDLE = Platform.getBundle("org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests");
/**
* Test to check the Disks IO Activity view. First, when trace opened, there
* should not be any activity. Then, we move to a time range where there are
* write activity. Afterward, we test the zoom
- *
- * @throws URISyntaxException
- * if this URL is not formatted strictly according to to RFC2396 and
- * cannot be converted to a URI.
- * @throws IOException
- * if an error occurs during the conversion
*/
@Test
- public void testDiskView() throws URISyntaxException, IOException {
+ public void testDiskView() {
// Wait for analysis to finish.
WaitUtils.waitForJobs();
IViewPart viewPart = getSWTBotView().getViewReference().getView(true);
@@ -98,7 +81,7 @@ public class DisksIOViewTest extends XYDataProviderBaseTest {
chartViewer.setNbPoints(NUMBER_OF_POINT);
/* Initially, no disk activity */
- SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), getFullPath("resources/disk/disk0-res50.json"), "Chart data is not valid");
+ SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), "resources/disk/disk0-res50.json", "Chart data is not valid");
/* Change time range where there is disks activity */
TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, new TmfTimeRange(ZOOM_START_TIME, ZOOM_END_TIME)));
@@ -109,7 +92,7 @@ public class DisksIOViewTest extends XYDataProviderBaseTest {
verifyChartStyle();
/* Test data model */
- SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), getFullPath("resources/disk/disk1-res50.json"), "Chart data is not valid");
+ SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), "resources/disk/disk1-res50.json", "Chart data is not valid");
/* Change Zoom and number of points */
chartViewer.setNbPoints(MORE_POINTS);
@@ -118,25 +101,7 @@ public class DisksIOViewTest extends XYDataProviderBaseTest {
verifyChartStyle();
/* Test data model */
- SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), getFullPath("resources/disk/disk2-res100.json"), "Chart data is not valid");
- }
-
- /**
- * Get the full path to the test file from the bundle.
- *
- * @param bundlePath
- * path from the bundle
- * @return the absolute path
- * @throws URISyntaxException
- * if this URL is not formatted strictly according to to RFC2396 and
- * cannot be converted to a URI.
- * @throws IOException
- * if an error occurs during the conversion
- */
- private static String getFullPath(String bundlePath) throws URISyntaxException, IOException {
- URL location = FileLocator.find(BUNDLE, new Path(bundlePath), null);
- URI uri = FileLocator.toFileURL(location).toURI();
- return new File(uri).getAbsolutePath();
+ SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), "resources/disk/disk2-res100.json", "Chart data is not valid");
}
private void verifyChartStyle() {
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java
index af0cb604b4..77ab055ae2 100644
--- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java
+++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java
@@ -12,8 +12,11 @@ package org.eclipse.tracecompass.tmf.ui.swtbot.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
+import java.net.URI;
+import java.net.URL;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -22,6 +25,8 @@ import java.util.Objects;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.swt.graphics.RGB;
@@ -47,6 +52,8 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
import org.swtchart.Chart;
import org.swtchart.IBarSeries;
import org.swtchart.ILineSeries;
@@ -138,6 +145,25 @@ public abstract class XYDataProviderBaseTest {
}
/**
+ * Get the full path to a test file from this class's bundle.
+ *
+ * @param bundlePath
+ * path from the bundle
+ * @return the absolute path
+ */
+ private String getFullPath(String bundlePath) {
+ try {
+ Bundle bundle = FrameworkUtil.getBundle(this.getClass());
+ URL location = FileLocator.find(bundle, new Path(bundlePath), null);
+ URI uri = FileLocator.toFileURL(location).toURI();
+ return new File(uri).getAbsolutePath();
+ } catch (Exception e) {
+ fail(e.toString());
+ return null;
+ }
+ }
+
+ /**
* Based on a SWT Chart, we check if data shown is valid with a JSON file.
* Comparison with the main series and other series if exists
*
@@ -146,7 +172,7 @@ public abstract class XYDataProviderBaseTest {
* @param otherSeries
* An array of other series name to check other than the main series
* @param expectedJson
- * The path of the JSON file
+ * The path of the JSON file relative to this class's bundle
* @return True if the serialized chart data matches the JSON file content
*/
protected boolean isChartDataValid(final Chart chart, String expectedJson, String... otherSeries) {
@@ -154,7 +180,7 @@ public abstract class XYDataProviderBaseTest {
* FIXME : Once CQ for Jackson is approved, use deserialization instead of
* comparing strings
*/
- String expected = FileUtils.read(expectedJson);
+ String expected = FileUtils.read(getFullPath(expectedJson));
TmfCommonXAxisModel model = extractModelFromChart(chart, otherSeries);
String current = fGson.toJson(model);
return expected.equals(current);

Back to the top