missing libs,
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 16:01:11 +0000 (20:01 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 16:01:11 +0000 (20:01 +0400)
some tests

.idea/libraries/Test_Api_libs.xml [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/BuildProcessBase.java
nuget-tests/nuget-tests.iml
nuget-tests/src/jetbrains/buildServer/nuget/tests/util/CompositeBuildProcessTest.java [new file with mode: 0644]

diff --git a/.idea/libraries/Test_Api_libs.xml b/.idea/libraries/Test_Api_libs.xml
new file mode 100644 (file)
index 0000000..0a281a0
--- /dev/null
@@ -0,0 +1,10 @@
+<component name="libraryTable">\r
+  <library name="Test-Api libs">\r
+    <CLASSES>\r
+      <root url="jar://$PROJECT_DIR$/lib/jmock/jmock-core-1.2.0.jar!/" />\r
+      <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/xmlrpc-2.0.1.jar!/" />\r
+    </CLASSES>\r
+    <JAVADOC />\r
+    <SOURCES />\r
+  </library>\r
+</component>
\ No newline at end of file
index c22bcd4f1af250816f4fef1659b0518b1c333e3e..05e597984cfe3ff3621e921b2fe7956e47c80ebb 100644 (file)
@@ -46,9 +46,8 @@ public abstract class BuildProcessBase implements BuildProcess {
 \r
   @NotNull\r
   public final BuildFinishedStatus waitFor() throws RunBuildException {\r
-    if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
-\r
     try {\r
+      if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
       BuildFinishedStatus status = waitForImpl();\r
       if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
 \r
@@ -58,7 +57,6 @@ public abstract class BuildProcessBase implements BuildProcess {
     }\r
   }\r
 \r
-\r
   protected abstract BuildFinishedStatus waitForImpl() throws RunBuildException;\r
 \r
   protected void interruptImpl() {\r
index e694b98fd06bb18b5968f355961b1b0aec83dfc5..4ee5d981a0796f2b568906c20e89d264770f3a66 100644 (file)
@@ -9,6 +9,15 @@
     <orderEntry type="sourceFolder" forTests="false" />\r
     <orderEntry type="library" name="testng" level="project" />\r
     <orderEntry type="library" name="jmock" level="project" />\r
+    <orderEntry type="library" name="Test-Api" level="project" />\r
+    <orderEntry type="module" module-name="nuget-agent" />\r
+    <orderEntry type="module" module-name="nuget-common" />\r
+    <orderEntry type="module" module-name="nuget-server" />\r
+    <orderEntry type="library" name="Common-Api" level="project" />\r
+    <orderEntry type="library" name="Agent-Api" level="project" />\r
+    <orderEntry type="library" name="Test-Api libs" level="project" />\r
+    <orderEntry type="library" name="Idea-OpenApi" level="project" />\r
+    <orderEntry type="library" name="log4j" level="project" />\r
   </component>\r
 </module>\r
 \r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/util/CompositeBuildProcessTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/util/CompositeBuildProcessTest.java
new file mode 100644 (file)
index 0000000..aadf015
--- /dev/null
@@ -0,0 +1,287 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.tests.util;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl;\r
+import jetbrains.buildServer.util.StringUtil;\r
+import org.testng.Assert;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.jetbrains.annotations.Nullable;\r
+import org.testng.annotations.DataProvider;\r
+import org.testng.annotations.Test;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 19:04\r
+ */\r
+public class CompositeBuildProcessTest extends BaseTestCase {\r
+  @Test\r
+  public void test_empty_build_process() {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    assertRunSuccessfully(i, BuildFinishedStatus.FINISHED_SUCCESS);\r
+  }\r
+\r
+  @Test(dataProvider = "buildFinishStatuses")\r
+  public void test_one_build_process(BuildFinishedStatus result) throws RunBuildException {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1", result, log));\r
+    assertRunSuccessfully(i, result == BuildFinishedStatus.INTERRUPTED ? BuildFinishedStatus.FINISHED_SUCCESS : result);\r
+\r
+    assertLog(log, "start-1", "waitFor-1");\r
+  }\r
+\r
+  @Test\r
+  public void test_stopOnFirstError() throws RunBuildException {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_FAILED, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunSuccessfully(i, BuildFinishedStatus.FINISHED_FAILED);\r
+\r
+    assertLog(log, "start-1", "waitFor-1");\r
+  }\r
+\r
+  @Test\r
+  public void test_stopOnFirstError2() throws RunBuildException {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_FAILED, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("3", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunSuccessfully(i, BuildFinishedStatus.FINISHED_FAILED);\r
+    assertLog(log, "start-1", "waitFor-1", "start-2", "waitFor-2");\r
+  }\r
+\r
+  @Test\r
+  public void test_stopOnStartException() throws RunBuildException {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_SUCCESS, log) {{\r
+      setStartException(new RunBuildException("aaa"));\r
+    }});\r
+    i.pushBuildProcess(new RecordingBuildProcess("3", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunException(i, "aaa");\r
+    assertLog(log, "start-1", "waitFor-1", "start-2");\r
+  }\r
+\r
+  @Test\r
+  public void test_stopOnWaitForException() throws RunBuildException {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_SUCCESS, log) {{\r
+      setFinishException(new RunBuildException("aaa"));\r
+    }});\r
+    i.pushBuildProcess(new RecordingBuildProcess("3", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunException(i, "aaa");\r
+    assertLog(log, "start-1", "waitFor-1", "start-2", "waitFor-2");\r
+  }\r
+\r
+  @Test\r
+  public void test_emptyInterrupted() {\r
+    CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    i.interrupt();\r
+\r
+    Assert.assertFalse(i.isFinished());\r
+    Assert.assertTrue(i.isInterrupted());\r
+    assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
+\r
+    Assert.assertTrue(i.isInterrupted());\r
+    Assert.assertTrue(i.isFinished());\r
+  }\r
+\r
+  @Test\r
+  public void test_interruptCalledForFirst() {\r
+    final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1",BuildFinishedStatus.FINISHED_SUCCESS, log) {\r
+      @Override\r
+      public void start() throws RunBuildException {\r
+        super.start();\r
+        i.interrupt();\r
+      }\r
+    });\r
+    i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
+    assertLog(log, "start-1", "interrupt-1", "waitFor-1");\r
+  }\r
+\r
+  @Test\r
+  public void test_interruptCalledForFirst_WaitFor() {\r
+    final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("1",BuildFinishedStatus.FINISHED_SUCCESS, log) {\r
+      @NotNull\r
+      @Override\r
+      public BuildFinishedStatus waitFor() throws RunBuildException {\r
+        i.interrupt();\r
+        return super.waitFor();\r
+      }\r
+    });\r
+    i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
+    assertLog(log, "start-1", "interrupt-1", "waitFor-1");\r
+  }\r
+\r
+  @Test\r
+  public void test_interruptCalledForTwo() {\r
+    final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("0", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("1",BuildFinishedStatus.FINISHED_SUCCESS, log) {\r
+      @Override\r
+      public void start() throws RunBuildException {\r
+        super.start();\r
+        i.interrupt();\r
+      }\r
+    });\r
+    i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
+    assertLog(log, "start-0", "waitFor-0", "start-1", "interrupt-1", "waitFor-1");\r
+  }\r
+\r
+  @Test\r
+  public void test_interruptCalledForTwo_WaitFor() {\r
+    final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
+    final List<String> log = new ArrayList<String>();\r
+    i.pushBuildProcess(new RecordingBuildProcess("0", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+    i.pushBuildProcess(new RecordingBuildProcess("1",BuildFinishedStatus.FINISHED_SUCCESS, log) {\r
+      @NotNull\r
+      @Override\r
+      public BuildFinishedStatus waitFor() throws RunBuildException {\r
+        i.interrupt();\r
+        return super.waitFor();\r
+      }\r
+    });\r
+    i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS, log));\r
+\r
+    assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
+    assertLog(log, "start-0", "waitFor-0", "start-1", "interrupt-1", "waitFor-1");\r
+  }\r
+\r
+\r
+\r
+  @DataProvider(name = "buildFinishStatuses")\r
+  public Object[][] buildStatuses() {\r
+    List<Object[]> list = new ArrayList<Object[]>();\r
+    for (BuildFinishedStatus val : BuildFinishedStatus.values()) {\r
+      list.add(new Object[]{val});\r
+    }\r
+    return list.toArray(new Object[list.size()][]);\r
+  }\r
+\r
+  private void assertRunSuccessfully(@NotNull BuildProcess proc, @NotNull BuildFinishedStatus result) {\r
+    BuildFinishedStatus status = null;\r
+    try {\r
+      proc.start();\r
+      status = proc.waitFor();\r
+    } catch (RunBuildException e) {\r
+      Assert.fail("Failed with exception " + e);\r
+    }\r
+\r
+    Assert.assertEquals(result, status);\r
+  }\r
+\r
+  private void assertRunException(@NotNull BuildProcess proc, @NotNull String message) {\r
+    try {\r
+      proc.start();\r
+      proc.waitFor();\r
+      Assert.fail("Exception expected");\r
+    } catch (RunBuildException e) {\r
+      Assert.assertEquals(message, e.getMessage());\r
+    }\r
+  }\r
+\r
+  private void assertLog(Collection<String> log, String... gold) {\r
+    String actual = StringUtil.join(log, "\n");\r
+    String expected = StringUtil.join(gold, "\n");\r
+    Assert.assertEquals(actual, expected);\r
+  }\r
+\r
+  private class RecordingBuildProcess implements BuildProcess {\r
+    private final String myId;\r
+    private final List<String> myLog;\r
+    private final BuildFinishedStatus myResultStatus;\r
+    private Throwable myStartException;\r
+    private Throwable myFinishException;\r
+\r
+    private RecordingBuildProcess(@NotNull String id,\r
+                                  @Nullable final BuildFinishedStatus resultStatus,\r
+                                  @NotNull final List<String> log) {\r
+      myId = id;\r
+      myLog = log;\r
+      myResultStatus = resultStatus;\r
+    }\r
+\r
+    public void setStartException(Exception startException) {\r
+      myStartException = startException;\r
+    }\r
+\r
+    public void setFinishException(Exception finishException) {\r
+      myFinishException = finishException;\r
+    }\r
+\r
+    public void start() throws RunBuildException {\r
+      myLog.add("start-" + myId);\r
+      throwExceptionIfPossible(myStartException);\r
+    }\r
+\r
+    private void throwExceptionIfPossible(Throwable ex) throws RunBuildException {\r
+      if (ex != null) {\r
+        if (ex instanceof RunBuildException) throw (RunBuildException) ex;\r
+        if (ex instanceof RuntimeException) throw (RuntimeException) ex;\r
+        throw (Error) ex;\r
+      }\r
+    }\r
+\r
+    public boolean isInterrupted() {\r
+      return false;\r
+    }\r
+\r
+    public boolean isFinished() {\r
+      return false;\r
+    }\r
+\r
+    public void interrupt() {\r
+      myLog.add("interrupt-" + myId);\r
+    }\r
+\r
+    @NotNull\r
+    public BuildFinishedStatus waitFor() throws RunBuildException {\r
+      myLog.add("waitFor-" + myId);\r
+      throwExceptionIfPossible(myFinishException);\r
+      return myResultStatus;\r
+    }\r
+  }\r
+}\r