IDEA-142739 GeneralIdBasedToSMTRunnerEventsConvertor doesn't accept duration attribut...
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 17 Jul 2015 07:49:07 +0000 (10:49 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 17 Jul 2015 07:49:07 +0000 (10:49 +0300)
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFailedEvent.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestStartedEvent.java
platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java [new file with mode: 0644]

index 21651ce887796f8d9c33587c9fc7d54324f79b2b..2bc10fced23a0c8d799e04a2359425dc19ba198c 100644 (file)
@@ -310,7 +310,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsP
         String stackTrace = testFailedEvent.getStacktrace();
         if (comparisonFailureActualText != null && comparisonFailureExpectedText != null) {
           testProxy.setTestComparisonFailed(failureMessage, stackTrace,
-                                            comparisonFailureActualText, comparisonFailureExpectedText);
+                                            comparisonFailureActualText, comparisonFailureExpectedText, testFailedEvent.getFilePath());
         } else if (comparisonFailureActualText == null && comparisonFailureExpectedText == null) {
           testProxy.setTestFailed(failureMessage, stackTrace, testFailedEvent.isTestError());
         } else {
@@ -320,6 +320,10 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsP
                      + "Actual:\n"
                      + comparisonFailureActualText);
         }
+        long duration = testFailedEvent.getDurationMillis();
+        if (duration >= 0) {
+          testProxy.setDuration(duration);
+        }
 
         // fire event
         fireOnTestFailed(testProxy);
@@ -388,6 +392,12 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsP
     return myNodeByIdMap.get(treeNodeEvent.getId());
   }
 
+  @Nullable
+  public SMTestProxy findProxyById(int id) {
+    Node node = myNodeByIdMap.get(id);
+    return node != null ? node.getProxy() : null;
+  }
+
   private void fireOnTestingStarted() {
     for (SMTRunnerEventsListener listener : myEventsListeners) {
       listener.onTestingStarted(myTestsRootProxy);
index c9e57612536087c3fcce835683f6bf6937ab8db9..8710d8196a262664dbebf0a9fe4834a4b5f83e5a 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.execution.testframework.sm.runner.events;
 
+import com.intellij.openapi.util.text.StringUtil;
 import jetbrains.buildServer.messages.serviceMessages.TestFailed;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -27,6 +28,7 @@ public class TestFailedEvent extends TreeNodeEvent {
   private final String myComparisonFailureActualText;
   private final String myComparisonFailureExpectedText;
   private final String myFilePath;
+  private final long myDurationMillis;
 
   public TestFailedEvent(@NotNull TestFailed testFailed, boolean testError) {
     this(testFailed, testError, null);
@@ -40,6 +42,18 @@ public class TestFailedEvent extends TreeNodeEvent {
     myComparisonFailureActualText = testFailed.getActual();
     myComparisonFailureExpectedText = testFailed.getExpected();
     myFilePath = filePath;
+    myDurationMillis = parseDuration(testFailed.getAttributes().get("duration"));
+  }
+
+  private static long parseDuration(@Nullable String durationStr) {
+    if (!StringUtil.isEmpty(durationStr)) {
+      try {
+        return Long.parseLong(durationStr);
+      }
+      catch (NumberFormatException ignored) {
+      }
+    }
+    return -1;
   }
 
   public TestFailedEvent(@NotNull String testName,
@@ -48,13 +62,34 @@ public class TestFailedEvent extends TreeNodeEvent {
                          boolean testError,
                          @Nullable String comparisonFailureActualText,
                          @Nullable String comparisonFailureExpectedText) {
-    super(testName, -1);
+    this(testName,
+         -1,
+         localizedFailureMessage,
+         stackTrace,
+         testError,
+         comparisonFailureActualText,
+         comparisonFailureExpectedText,
+         null,
+         -1);
+  }
+
+  public TestFailedEvent(@Nullable String testName,
+                         int id,
+                         @NotNull String localizedFailureMessage,
+                         @Nullable String stackTrace,
+                         boolean testError,
+                         @Nullable String comparisonFailureActualText,
+                         @Nullable String comparisonFailureExpectedText,
+                         @Nullable String expectedTextFilePath,
+                         long durationMillis) {
+    super(testName, id);
     myLocalizedFailureMessage = localizedFailureMessage;
     myStacktrace = stackTrace;
     myTestError = testError;
     myComparisonFailureActualText = comparisonFailureActualText;
     myComparisonFailureExpectedText = comparisonFailureExpectedText;
-    myFilePath = null;
+    myFilePath = expectedTextFilePath;
+    myDurationMillis = durationMillis;
   }
 
   @NotNull
@@ -93,4 +128,11 @@ public class TestFailedEvent extends TreeNodeEvent {
   public String getFilePath() {
     return myFilePath;
   }
+
+  /**
+   * @return the test duration in milliseconds, or -1 if undefined
+   */
+  public long getDurationMillis() {
+    return myDurationMillis;
+  }
 }
index 7632be8b0762030b604444eaa9a3d4d550d173b5..61bb3a607a5ddb6c5de787de4d0e3fab16657298 100644 (file)
@@ -34,6 +34,22 @@ public class TestStartedEvent extends BaseStartedNodeEvent {
           BaseStartedNodeEvent.isRunning(testStarted));
   }
 
+  public TestStartedEvent(@Nullable String name,
+                          int id,
+                          int parentId,
+                          @Nullable final String locationUrl,
+                          @Nullable String nodeType,
+                          @Nullable String nodeArgs,
+                          boolean running) {
+    super(name,
+          id,
+          parentId,
+          locationUrl,
+          nodeType,
+          nodeArgs,
+          running);
+  }
+
   public TestStartedEvent(@NotNull String name, @Nullable String locationUrl) {
     super(name, -1, -1, locationUrl, null, null, true);
   }
diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java
new file mode 100644 (file)
index 0000000..e0eddc0
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * 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 com.intellij.execution.testframework.sm.runner;
+
+import com.intellij.execution.testframework.sm.runner.events.TestFailedEvent;
+import com.intellij.execution.testframework.sm.runner.events.TestStartedEvent;
+import com.intellij.openapi.util.Disposer;
+import org.jetbrains.annotations.NotNull;
+
+public class GeneralIdBasedToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase {
+  private GeneralIdBasedToSMTRunnerEventsConvertor myEventsProcessor;
+  private SMTestProxy.SMRootTestProxy myRootProxy;
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    myRootProxy = new SMTestProxy.SMRootTestProxy();
+    myEventsProcessor = new GeneralIdBasedToSMTRunnerEventsConvertor(myRootProxy, "test");
+    myEventsProcessor.onStartTesting();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    Disposer.dispose(myEventsProcessor);
+    super.tearDown();
+  }
+
+  public void testOnStartedTesting() {
+    assertTrue(myRootProxy.wasLaunched());
+    assertTrue(myRootProxy.isInProgress());
+    assertTrue(myRootProxy.isLeaf());
+  }
+
+  public void testOnTestStarted() throws InterruptedException {
+    onTestStarted("my test", 1, 0);
+    SMTestProxy proxy = myEventsProcessor.findProxyById(1);
+
+    assertNotNull(proxy);
+    assertTrue(proxy.isInProgress());
+    assertEquals(1, myRootProxy.getChildren().size());
+
+    onTestFailed(1, "", 1);
+    proxy = myEventsProcessor.findProxyById(1);
+
+    assertNotNull(proxy);
+    assertTrue(proxy.isDefect());
+    assertEquals(Long.valueOf(1), proxy.getDuration());
+  }
+
+  private void onTestStarted(@NotNull String testName, int id, int parentId) {
+    myEventsProcessor.onTestStarted(new TestStartedEvent(testName, id, parentId, null, null, null, true));
+  }
+
+  private void onTestFailed(int id, @NotNull String errorMessage, int duration) {
+    myEventsProcessor.onTestFailure(new TestFailedEvent(null, id, errorMessage, null, false, null, null, null, duration));
+  }
+
+}