tmf.swtbot: Stabilize and enhance TestImportExportPackageWizard
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 17 Nov 2016 03:26:25 +0000 (22:26 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 5 Dec 2016 17:38:09 +0000 (12:38 -0500)
The test would fail if ran 1000 times in a row. File#createTempFile
appears to be the culprit.

Remove a useless "waitForJobs()" should accelerate by 500ms.

Add tests of the output size, removes two manual tests from Trace
Compass test spec.

Change-Id: Ia8bc3a517752a121874cd559d192fa0378221716
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/85191
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/wizards/TestImportExportPackageWizard.java

index c11c36663cfaf23a070e88354b8a40c9f8f88b09..a11bdf04ee1024de7adb77614cd1efcb9c19ec9a 100644 (file)
@@ -13,6 +13,7 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
  org.eclipse.ui,
  org.eclipse.ui.ide,
  org.eclipse.ui.views,
+ org.eclipse.tracecompass.common.core,
  org.eclipse.tracecompass.tmf.ui,
  org.eclipse.tracecompass.tmf.core,
  org.eclipse.tracecompass.tmf.core.tests,
index 21d9bbd986a64dd3d4c145acaa85acea494d4db6..5e0d9f32f714b511e9b6857435a5e356174218ee 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -20,6 +20,9 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.text.ParseException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Logger;
@@ -33,6 +36,7 @@ import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
 import org.eclipse.swtbot.swt.finder.waits.Conditions;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.common.core.format.DataSizeWithUnitFormat;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
@@ -52,6 +56,7 @@ public class TestImportExportPackageWizard {
 
     // private static final int PACKAGE_SIZE = 213732;
     private static final String EXPORT_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.zip";
+    private static final String TRACE_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.xml";
     private static final String IMPORT_TRACE_PACKAGE = "Import Trace Package...";
     private static final String IMPORT_TRACE_PACKAGE_TITLE = "Import trace package";
     private static final String EXPORT_TRACE_PACKAGE = "Export Trace Package...";
@@ -68,6 +73,8 @@ public class TestImportExportPackageWizard {
     private static final String PROJECT_NAME = "Test";
     private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
 
+    private static final Pattern PATTERN = Pattern.compile("Approximate uncompressed size: (.*)B");
+
     private static final String TRACE_CONTENT = "<trace>" +
             "<event timestamp=\"100\" name=\"event\"><field name=\"field\" value=\"1\" type=\"int\" /></event>" +
             "<event timestamp=\"200\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
@@ -112,11 +119,17 @@ public class TestImportExportPackageWizard {
      *
      * @throws IOException
      *             won't happen
+     * @throws ParseException
+     *             won't happen
      */
     @Test
-    public void test() throws IOException {
-        File f = File.createTempFile("temp", ".xml").getCanonicalFile();
-        try (FileWriter fw = new FileWriter(f)) {
+    public void test() throws IOException, ParseException {
+        File traceFile = new File(TRACE_LOCATION);
+        if (traceFile.exists()) {
+            traceFile.delete();
+        }
+        traceFile.deleteOnExit();
+        try (FileWriter fw = new FileWriter(traceFile)) {
             fw.write(TRACE_CONTENT);
         }
         File exportPackage = new File(EXPORT_LOCATION);
@@ -124,13 +137,12 @@ public class TestImportExportPackageWizard {
             exportPackage.delete();
         }
         assertFalse("File: " + EXPORT_LOCATION + " already present, aborting test", exportPackage.exists());
-        assertTrue("Trace :" + f.getAbsolutePath() + " does not exist, aborting test", f.exists());
+        assertTrue("Trace :" + traceFile.getAbsolutePath() + " does not exist, aborting test", traceFile.exists());
         SWTBotUtils.createProject(PROJECT_NAME);
-        SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
-        WaitUtils.waitForJobs();
+        SWTBotUtils.openTrace(PROJECT_NAME, TRACE_LOCATION, XMLSTUB_ID);
         ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
         assertNotNull(trace);
-        assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(trace.getPath())).getAbsolutePath());
+        assertEquals("Incorrect opened trace!", traceFile.getAbsolutePath(), (new File(trace.getPath())).getAbsolutePath());
         SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
         assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
         projectExplorerBot.show();
@@ -144,10 +156,28 @@ public class TestImportExportPackageWizard {
         for (SWTBotTreeItem item : items) {
             assertEquals(item.isChecked(), false);
         }
+        String labelText = fBot.label(1).getText();
+        Matcher matcher = PATTERN.matcher(labelText);
+
+        assertTrue(labelText + " matches", matcher.matches());
+        String sizeText = matcher.group(1);
+        assertEquals(labelText + " value", "0", sizeText.trim());
+
         shellBot.button(SELECT_ALL).click();
+
         for (SWTBotTreeItem item : items) {
             assertEquals(item.isChecked(), true);
         }
+
+        labelText = fBot.label(1).getText();
+        matcher = PATTERN.matcher(labelText);
+
+        assertTrue(labelText + " matches", matcher.matches());
+        // should be 138 k
+        sizeText = matcher.group(1);
+        int size = ((Number) DataSizeWithUnitFormat.getInstance().parseObject(sizeText)).intValue();
+        assertTrue(labelText + " value", 0 < size);
+
         shellBot.radio(SAVE_IN_TAR_FORMAT).click();
         shellBot.radio(SAVE_IN_ZIP_FORMAT).click();
 
@@ -162,8 +192,14 @@ public class TestImportExportPackageWizard {
         fBot = new SWTWorkbenchBot();
         exportPackage = new File(EXPORT_LOCATION);
         assertTrue("Exported package", exportPackage.exists());
-        // Fixme: determine why exportPackageSize is different on different machines
-        // assertEquals("Exported package size check", PACKAGE_SIZE, exportPackage.length());
+        /*
+         * Fixme: determine why exportPackageSize is different on different
+         * machines
+         */
+        /*
+         * assertEquals("Exported package size check", PACKAGE_SIZE,
+         * exportPackage.length());
+         */
 
         // import
         treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
@@ -179,13 +215,16 @@ public class TestImportExportPackageWizard {
         fBot.button("Yes To All").click();
         fBot.waitUntil(Conditions.shellCloses(shell));
         fBot = new SWTWorkbenchBot();
-        SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
+        SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(traceFile.getName()));
         trace = TmfTraceManager.getInstance().getActiveTrace();
         assertNotNull(trace);
-        assertEquals("Test if import matches", f.getName(), trace.getName());
-        assertFalse("Test if import files don't match", f.getAbsolutePath().equals(trace.getPath()));
+        assertEquals("Test if import matches", traceFile.getName(), trace.getName());
+        assertFalse("Test if import files don't match", traceFile.getAbsolutePath().equals(trace.getPath()));
         SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
         WaitUtils.waitForJobs();
+        traceFile.delete();
+        exportPackage.delete();
+
     }
 
 }
This page took 0.02811 seconds and 5 git commands to generate.